<commit_before>package main

import (
	"fmt"
	"io/ioutil"
	"net"
	"net/http"
	"net/url"

	"github.com/koding/kite"
)

const publicEcho = "http://echoip.com"
const proxyHostUrl = "koding.com/-/userproxy/"

func getRegisterURL(k *kite.Kite) (*url.URL, error) {
	ip, err := publicIP()
	if err != nil {
		return nil, err
	}

	// http://localhost:8090/userproxy/172.16.17.32/kite

	return &url.URL{
		Scheme: "https",
		Host:   proxyHostUrl + ip.String(),
		Path:   "/kite",
	}, nil
}

// publicIP returns an IP that is supposed to be Public.
func publicIP() (net.IP, error) {
	resp, err := http.Get(publicEcho)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	out, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}

	n := net.ParseIP(string(out))
	if n == nil {
		return nil, fmt.Errorf("cannot parse ip %s", string(out))
	}

	return n, nil
}<commit_msg>klient: register with public IP so we know the real IP<commit_after>package main

import (
	"fmt"
	"io/ioutil"
	"net"
	"net/http"
	"net/url"
	"strconv"

	"github.com/koding/kite"
)

const publicEcho = "http://echoip.com"

func getRegisterURL(k *kite.Kite) (*url.URL, error) {
	ip, err := publicIP()
	if err != nil {
		return nil, err
	}

	scheme := "http"
	if k.TLSConfig != nil {
		scheme = "https"
	}

	return &url.URL{
		Scheme: scheme,
		Host:   ip.String() + ":" + strconv.Itoa(k.Config.Port),
		Path:   "/kite",
	}, nil
}

// publicIP returns an IP that is supposed to be Public.
func publicIP() (net.IP, error) {
	resp, err := http.Get(publicEcho)
	if err != nil {
		return nil, err
	}
	defer resp.Body.Close()

	out, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return nil, err
	}

	n := net.ParseIP(string(out))
	if n == nil {
		return nil, fmt.Errorf("cannot parse ip %s", string(out))
	}

	return n, nil
}
{'fraction_non_alphanumeric': 0.16795580110497238, 'fraction_numerical': 0.0071823204419889505, 'mean_word_length': 3.2313084112149535, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '3334758', 'n_tokens_mistral': 770, 'n_tokens_neox': 730, 'n_words': 192}