]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Expose public IPv4 and IPv6 config options and use them with trackers
authorMatt Joiner <anacrolix@gmail.com>
Thu, 29 Mar 2018 03:29:15 +0000 (14:29 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Thu, 29 Mar 2018 03:29:15 +0000 (14:29 +1100)
config.go
tracker/tracker.go
tracker_scraper.go

index 860f6cd19a6d96d2317b9e3d4637e61d31834964..d0f09669d9d4e1ad5ef45ff163cebb46cd1e92a8 100644 (file)
--- 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() {
index 95f6ed1e29c131c0e598942154b0046affd4f1a5..928ab777ba600f42864e31664b8268b0b4d5ea84 100644 (file)
@@ -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?
index d8065b699cb20e25bea6fce89adb4b2b3e5b323e..ec94ee9eaef657fa7232f1871f72e893fd14ebc1 100644 (file)
@@ -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)