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(
35 opts trHttp.AnnounceOpt,
36 ) (res AnnounceResponse, err error) {
37 if req.IPAddress == 0 && opts.ClientIp4 != nil {
38 // I think we're taking bytes in big-endian order (all IPs), and writing it to a natively
39 // ordered uint32. This will be correctly ordered when written back out by the UDP client
40 // later. I'm ignoring the fact that IPv6 announces shouldn't have an IP address, we have a
41 // perfectly good IPv4 address.
42 req.IPAddress = binary.BigEndian.Uint32(opts.ClientIp4.To4())
44 h, nas, err := c.cl.Announce(ctx, req, udp.Options{RequestUri: c.requestUri})
48 res.Interval = h.Interval
49 res.Leechers = h.Leechers
50 res.Seeders = h.Seeders
51 for _, cp := range nas.NodeAddrs() {
52 res.Peers = append(res.Peers, trHttp.Peer{}.FromNodeAddr(cp))