7 trHttp "github.com/anacrolix/torrent/tracker/http"
8 "github.com/anacrolix/torrent/tracker/udp"
11 type udpClient struct {
16 func (c *udpClient) Close() error {
20 func (c *udpClient) Announce(ctx context.Context, req AnnounceRequest, opts trHttp.AnnounceOpt) (res AnnounceResponse, err error) {
21 if req.IPAddress == 0 && opts.ClientIp4 != nil {
22 // I think we're taking bytes in big-endian order (all IPs), and writing it to a natively
23 // ordered uint32. This will be correctly ordered when written back out by the UDP client
24 // later. I'm ignoring the fact that IPv6 announces shouldn't have an IP address, we have a
25 // perfectly good IPv4 address.
26 req.IPAddress = binary.BigEndian.Uint32(opts.ClientIp4.To4())
28 h, nas, err := c.cl.Announce(ctx, req, udp.Options{RequestUri: c.requestUri})
32 res.Interval = h.Interval
33 res.Leechers = h.Leechers
34 res.Seeders = h.Seeders
35 for _, cp := range nas.NodeAddrs() {
36 res.Peers = append(res.Peers, trHttp.Peer{}.FromNodeAddr(cp))