10 "github.com/anacrolix/dht/v2/krpc"
11 trHttp "github.com/anacrolix/torrent/tracker/http"
12 "github.com/anacrolix/torrent/tracker/shared"
13 "github.com/anacrolix/torrent/tracker/udp"
18 Started = shared.Started
19 Stopped = shared.Stopped
20 Completed = shared.Completed
23 type AnnounceRequest = udp.AnnounceRequest
25 type AnnounceResponse = trHttp.AnnounceResponse
27 type Peer = trHttp.Peer
29 type AnnounceEvent = udp.AnnounceEvent
32 ErrBadScheme = errors.New("unknown scheme")
35 type Announce struct {
37 Request AnnounceRequest
39 HTTPProxy func(*http.Request) (*url.URL, error)
43 // If the port is zero, it's assumed to be the same as the Request.Port.
44 ClientIp4 krpc.NodeAddr
45 // If the port is zero, it's assumed to be the same as the Request.Port.
46 ClientIp6 krpc.NodeAddr
47 Context context.Context
50 // The code *is* the documentation.
51 const DefaultTrackerAnnounceTimeout = 15 * time.Second
53 func (me Announce) Do() (res AnnounceResponse, err error) {
54 cl, err := NewClient(me.TrackerUrl, NewClientOpts{
55 Http: trHttp.NewClientOpts{
57 ServerName: me.ServerName,
59 UdpNetwork: me.UdpNetwork,
65 if me.Context == nil {
66 // This is just to maintain the old behaviour that should be a timeout of 15s. Users can
67 // override it by providing their own Context. See comments elsewhere about longer timeouts
68 // acting as rate limiting overloaded trackers.
69 ctx, cancel := context.WithTimeout(context.Background(), DefaultTrackerAnnounceTimeout)
73 return cl.Announce(me.Context, me.Request, trHttp.AnnounceOpt{
74 UserAgent: me.UserAgent,
75 HostHeader: me.HostHeader,
76 ClientIp4: me.ClientIp4.IP,
77 ClientIp6: me.ClientIp6.IP,