9 // Marshalled as binary by the UDP client, so be careful making changes.
10 type AnnounceRequest struct {
16 // Apparently this is optional. None can be used for announces done at
21 NumWant int32 // How many peer addresses are desired. -1 for default.
25 type AnnounceResponse struct {
26 Interval int32 // Minimum seconds the local peer should wait before next announce.
32 type AnnounceEvent int32
34 func (e AnnounceEvent) String() string {
35 // See BEP 3, "event".
36 return []string{"empty", "completed", "started", "stopped"}[e]
40 None AnnounceEvent = iota
41 Completed // The local peer just completed the torrent.
42 Started // The local peer has just resumed this torrent.
43 Stopped // The local peer is leaving the swarm.
47 ErrBadScheme = errors.New("unknown scheme")
50 // TODO: Just split udp/http announcing completely, to support various different options they have.
52 func Announce(cl *http.Client, userAgent string, urlStr string, req *AnnounceRequest) (res AnnounceResponse, err error) {
53 return AnnounceHost(cl, userAgent, urlStr, req, "")
56 func AnnounceHost(cl *http.Client, userAgent string, urlStr string, req *AnnounceRequest, host string) (res AnnounceResponse, err error) {
57 _url, err := url.Parse(urlStr)
63 return announceHTTP(cl, userAgent, req, _url, host)
65 return announceUDP(req, _url)