10 "github.com/anacrolix/dht/v2/krpc"
11 "github.com/anacrolix/torrent/tracker/udp"
14 type AnnounceRequest = udp.AnnounceRequest
16 type AnnounceResponse struct {
17 Interval int32 // Minimum seconds the local peer should wait before next announce.
23 type AnnounceEvent = udp.AnnounceEvent
26 None AnnounceEvent = iota
27 Completed // The local peer just completed the torrent.
28 Started // The local peer has just resumed this torrent.
29 Stopped // The local peer is leaving the swarm.
33 ErrBadScheme = errors.New("unknown scheme")
36 type Announce struct {
38 Request AnnounceRequest
40 HTTPProxy func(*http.Request) (*url.URL, error)
44 // If the port is zero, it's assumed to be the same as the Request.Port.
45 ClientIp4 krpc.NodeAddr
46 // If the port is zero, it's assumed to be the same as the Request.Port.
47 ClientIp6 krpc.NodeAddr
48 Context context.Context
51 // The code *is* the documentation.
52 const DefaultTrackerAnnounceTimeout = 15 * time.Second
54 func (me Announce) Do() (res AnnounceResponse, err error) {
55 _url, err := url.Parse(me.TrackerUrl)
59 if me.Context == nil {
60 // This is just to maintain the old behaviour that should be a timeout of 15s. Users can
61 // override it by providing their own Context. See comments elsewhere about longer timeouts
62 // acting as rate limiting overloaded trackers.
63 ctx, cancel := context.WithTimeout(context.Background(), DefaultTrackerAnnounceTimeout)
69 return announceHTTP(me, _url)
70 case "udp", "udp4", "udp6":
71 return announceUDP(me, _url)