<commit_before>// Copyright (C) 2015 <NAME> and Contributors.

package main

import (
	"bytes"
	"encoding/json"
	"io/ioutil"
	"log"
	"net/http"
	"net/url"
	"time"
)

const (
	httpStatusEnhanceYourCalm = 429
)

func poolHandler(pool string, uri *url.URL, mapping mapping) {
	if debug {
		log.Println("Joining", pool)
	}
	for {
		uriCopy := *uri
		uriCopy.Host = mapping.Address().String()

		var b bytes.Buffer
		json.NewEncoder(&b).Encode(struct {
			URL string `json:"url"`
		}{
			uriCopy.String(),
		})

		resp, err := httpClient.Post(pool, "application/json", &b)
		if err != nil {
			log.Printf("Error joining pool %v: HTTP request: %v", pool, err)
			time.Sleep(time.Minute)
			continue
		}

		bs, err := ioutil.ReadAll(resp.Body)
		resp.Body.Close()
		if err != nil {
			log.Printf("Error joining pool %v: reading response: %v", pool, err)
			time.Sleep(time.Minute)
			continue
		}

		switch resp.StatusCode {
		case http.StatusOK:
			var x struct {
				EvictionIn time.Duration `json:"evictionIn"`
			}
			if err := json.NewDecoder(resp.Body).Decode(&x); err == nil {
				rejoin := x.EvictionIn - (x.EvictionIn / 5)
				log.Printf("Joined pool %s, rejoining in %v", pool, rejoin)
				time.Sleep(rejoin)
				continue
			} else {
				log.Printf("Joined pool %s, failed to deserialize response: %v", pool, err)
			}
<commit_msg> cmd/strelaysrv: Fix JSON unmarshalling when joining a relay pool (fixes #6733) (#6729)<commit_after>// Copyright (C) 2015 <NAME> and Contributors.

package main

import (
	"bytes"
	"encoding/json"
	"io/ioutil"
	"log"
	"net/http"
	"net/url"
	"time"
)

const (
	httpStatusEnhanceYourCalm = 429
)

func poolHandler(pool string, uri *url.URL, mapping mapping) {
	if debug {
		log.Println("Joining", pool)
	}
	for {
		uriCopy := *uri
		uriCopy.Host = mapping.Address().String()

		var b bytes.Buffer
		json.NewEncoder(&b).Encode(struct {
			URL string `json:"url"`
		}{
			uriCopy.String(),
		})

		resp, err := httpClient.Post(pool, "application/json", &b)
		if err != nil {
			log.Printf("Error joining pool %v: HTTP request: %v", pool, err)
			time.Sleep(time.Minute)
			continue
		}

		bs, err := ioutil.ReadAll(resp.Body)
		resp.Body.Close()
		if err != nil {
			log.Printf("Error joining pool %v: reading response: %v", pool, err)
			time.Sleep(time.Minute)
			continue
		}

		switch resp.StatusCode {
		case http.StatusOK:
			var x struct {
				EvictionIn time.Duration `json:"evictionIn"`
			}
			if err := json.Unmarshal(bs, &x); err == nil {
				rejoin := x.EvictionIn - (x.EvictionIn / 5)
				log.Printf("Joined pool %s, rejoining in %v", pool, rejoin)
				time.Sleep(rejoin)
				continue
			} else {
				log.Printf("Joined pool %s, failed to deserialize response: %v", pool, err)
			}

{'fraction_non_alphanumeric': 0.15071507150715072, 'fraction_numerical': 0.0088008800880088, 'mean_word_length': 3.309636650868878, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6574848', 'n_tokens_mistral': 1157, 'n_tokens_neox': 1006, 'n_words': 255}