7 "github.com/anacrolix/generics"
9 trHttp "github.com/anacrolix/torrent/tracker/http"
10 "github.com/anacrolix/torrent/tracker/udp"
11 "github.com/anacrolix/torrent/types/infohash"
14 type udpClient struct {
19 func (c *udpClient) Scrape(ctx context.Context, ihs []infohash.T) (out udp.ScrapeResponse, err error) {
20 return c.cl.Client.Scrape(
22 generics.SliceMap(ihs, func(from infohash.T) udp.InfoHash {
28 func (c *udpClient) Close() error {
32 func (c *udpClient) Announce(ctx context.Context, req AnnounceRequest, opts trHttp.AnnounceOpt) (res AnnounceResponse, err error) {
33 if req.IPAddress == 0 && opts.ClientIp4 != nil {
34 // I think we're taking bytes in big-endian order (all IPs), and writing it to a natively
35 // ordered uint32. This will be correctly ordered when written back out by the UDP client
36 // later. I'm ignoring the fact that IPv6 announces shouldn't have an IP address, we have a
37 // perfectly good IPv4 address.
38 req.IPAddress = binary.BigEndian.Uint32(opts.ClientIp4.To4())
40 h, nas, err := c.cl.Announce(ctx, req, udp.Options{RequestUri: c.requestUri})
44 res.Interval = h.Interval
45 res.Leechers = h.Leechers
46 res.Seeders = h.Seeders
47 for _, cp := range nas.NodeAddrs() {
48 res.Peers = append(res.Peers, trHttp.Peer{}.FromNodeAddr(cp))