]> Sergey Matveev's repositories - btrtrc.git/commitdiff
tracker: Set UDP IPAddress field in announces
authorMatt Joiner <anacrolix@gmail.com>
Wed, 21 Feb 2018 02:33:12 +0000 (13:33 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Wed, 21 Feb 2018 02:33:12 +0000 (13:33 +1100)
tracker/tracker.go
tracker/udp.go

index fd24b0bef77e1ca549acf72896f7446166b134cb..95f6ed1e29c131c0e598942154b0046affd4f1a5 100644 (file)
@@ -18,7 +18,7 @@ type AnnounceRequest struct {
        // Apparently this is optional. None can be used for announces done at
        // regular intervals.
        Event     AnnounceEvent
-       IPAddress int32
+       IPAddress uint32
        Key       int32
        NumWant   int32 // How many peer addresses are desired. -1 for default.
        Port      uint16
index babbbefb05cb12fc2da3dc81372a267c8df403d7..656cc7df5c551797d413ca0a1a491095bd495d09 100644 (file)
@@ -99,12 +99,18 @@ func (c *udpAnnounce) ipv6() bool {
        return rip.To16() != nil && rip.To4() == nil
 }
 
-func (c *udpAnnounce) Do(req *AnnounceRequest) (res AnnounceResponse, err error) {
+func (c *udpAnnounce) Do(req AnnounceRequest) (res AnnounceResponse, err error) {
        err = c.connect()
        if err != nil {
                return
        }
        reqURI := c.url.RequestURI()
+       if c.ipv6() {
+               // BEP 15
+               req.IPAddress = 0
+       } else if req.IPAddress == 0 && c.a.ClientIp4.IP != nil {
+               req.IPAddress = binary.BigEndian.Uint32(c.a.ClientIp4.IP.To4())
+       }
        // Clearly this limits the request URI to 255 bytes. BEP 41 supports
        // longer but I'm not fussed.
        options := append([]byte{optionTypeURLData, byte(len(reqURI))}, []byte(reqURI)...)
@@ -288,5 +294,5 @@ func announceUDP(opt Announce, _url *url.URL) (AnnounceResponse, error) {
                a:   &opt,
        }
        defer ua.Close()
-       return ua.Do(&opt.Request)
+       return ua.Do(opt.Request)
 }