From 41b66adad736afc28f9231575b54ac2276415408 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Wed, 21 Feb 2018 13:33:12 +1100 Subject: [PATCH] tracker: Set UDP IPAddress field in announces --- tracker/tracker.go | 2 +- tracker/udp.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tracker/tracker.go b/tracker/tracker.go index fd24b0be..95f6ed1e 100644 --- a/tracker/tracker.go +++ b/tracker/tracker.go @@ -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 diff --git a/tracker/udp.go b/tracker/udp.go index babbbefb..656cc7df 100644 --- a/tracker/udp.go +++ b/tracker/udp.go @@ -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) } -- 2.50.0