From: Matt Joiner Date: Thu, 29 Mar 2018 03:29:15 +0000 (+1100) Subject: Expose public IPv4 and IPv6 config options and use them with trackers X-Git-Tag: v1.0.0~155 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=d950677f67c26793d1c551266dfc56f81081b48a;p=btrtrc.git Expose public IPv4 and IPv6 config options and use them with trackers --- diff --git a/config.go b/config.go index 860f6cd1..d0f09669 100644 --- a/config.go +++ b/config.go @@ -108,6 +108,9 @@ type Config struct { // impact of a few bad apples. 4s loses 1% of successful handshakes that // are obtained with 60s timeout, and 5% of unsuccessful handshakes. HandshakesTimeout time.Duration // default 20 * time.Second + + PublicIp4 net.IP + PublicIp6 net.IP } func (cfg *Config) setDefaults() { diff --git a/tracker/tracker.go b/tracker/tracker.go index 95f6ed1e..928ab777 100644 --- a/tracker/tracker.go +++ b/tracker/tracker.go @@ -56,8 +56,10 @@ type Announce struct { UserAgent string HttpClient *http.Client UdpNetwork string - ClientIp4 krpc.NodeAddr - ClientIp6 krpc.NodeAddr + // If the port is zero, it's assumed to be the same as the Request.Port + ClientIp4 krpc.NodeAddr + // If the port is zero, it's assumed to be the same as the Request.Port + ClientIp6 krpc.NodeAddr } // In an FP language with currying, what order what you put these params? diff --git a/tracker_scraper.go b/tracker_scraper.go index d8065b69..ec94ee9e 100644 --- a/tracker_scraper.go +++ b/tracker_scraper.go @@ -8,6 +8,7 @@ import ( "net/url" "time" + "github.com/anacrolix/dht/krpc" "github.com/anacrolix/missinggo" "github.com/anacrolix/torrent/tracker" @@ -115,6 +116,9 @@ func (me *trackerScraper) announce() (ret trackerAnnounceResult) { TrackerUrl: me.trackerUrl(ip), Request: req, HostHeader: me.u.Host, + UdpNetwork: me.u.Scheme, + ClientIp4: krpc.NodeAddr{IP: me.t.cl.config.PublicIp4}, + ClientIp6: krpc.NodeAddr{IP: me.t.cl.config.PublicIp6}, }.Do() if err != nil { ret.Err = fmt.Errorf("error announcing: %s", err)