9 "github.com/anacrolix/dht/v2/krpc"
12 // Marshalled as binary by the UDP client, so be careful making changes.
13 type AnnounceRequest struct {
17 Left int64 // If less than 0, math.MaxInt64 will be used for HTTP trackers instead.
19 // Apparently this is optional. None can be used for announces done at
24 NumWant int32 // How many peer addresses are desired. -1 for default.
28 type AnnounceResponse struct {
29 Interval int32 // Minimum seconds the local peer should wait before next announce.
35 type AnnounceEvent int32
37 func (e AnnounceEvent) String() string {
38 // See BEP 3, "event".
39 return []string{"empty", "completed", "started", "stopped"}[e]
43 None AnnounceEvent = iota
44 Completed // The local peer just completed the torrent.
45 Started // The local peer has just resumed this torrent.
46 Stopped // The local peer is leaving the swarm.
50 ErrBadScheme = errors.New("unknown scheme")
53 type Announce struct {
55 Request AnnounceRequest
57 HTTPProxy func(*http.Request) (*url.URL, error)
61 // If the port is zero, it's assumed to be the same as the Request.Port.
62 ClientIp4 krpc.NodeAddr
63 // If the port is zero, it's assumed to be the same as the Request.Port.
64 ClientIp6 krpc.NodeAddr
65 Context context.Context
68 func (me Announce) Do() (res AnnounceResponse, err error) {
69 _url, err := url.Parse(me.TrackerUrl)
75 return announceHTTP(me, _url)
76 case "udp", "udp4", "udp6":
77 return announceUDP(me, _url)