tracker: Set UDP IPAddress field in announces
This commit is contained in:
parent
5a7c4fc135
commit
41b66adad7
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue