tracker/server.go | 12 ++++++------ tracker/udp.go | 14 +++++++------- diff --git a/tracker/server.go b/tracker/server.go index e8613b08eb14ca3dad007bc755fddd99931ab9f0..3e98ae1d61c6054bf960f7b690a443efe9f6cdbe 100644 --- a/tracker/server.go +++ b/tracker/server.go @@ -65,23 +65,23 @@ if err != nil { return } switch h.Action { - case Connect: + case ActionConnect: if h.ConnectionId != connectRequestConnectionId { return } connId := me.newConn() err = me.respond(addr, ResponseHeader{ - Connect, + ActionConnect, h.TransactionId, }, ConnectionResponse{ connId, }) return - case Announce: + case ActionAnnounce: if _, ok := me.conns[h.ConnectionId]; !ok { me.respond(addr, ResponseHeader{ TransactionId: h.TransactionId, - Action: Error, + Action: ActionError, }, []byte("not connected")) return } @@ -97,7 +97,7 @@ panic(err) } err = me.respond(addr, ResponseHeader{ TransactionId: h.TransactionId, - Action: Announce, + Action: ActionAnnounce, }, AnnounceResponseHeader{ Interval: 900, Leechers: t.Leechers, @@ -108,7 +108,7 @@ default: err = fmt.Errorf("unhandled action: %d", h.Action) me.respond(addr, ResponseHeader{ TransactionId: h.TransactionId, - Action: Error, + Action: ActionError, }, []byte("unhandled action")) return } diff --git a/tracker/udp.go b/tracker/udp.go index d853674753f771095d657c99256c9efcb1be7abf..36f7cc7eeda47f7161378a1d3f12625bca791476 100644 --- a/tracker/udp.go +++ b/tracker/udp.go @@ -20,10 +20,10 @@ type Action int32 const ( - Connect Action = iota - Announce - Scrape - Error + ActionConnect Action = iota + ActionAnnounce + ActionScrape + ActionError connectRequestConnectionId = 0x41727101980 @@ -110,7 +110,7 @@ reqURI := c.url.RequestURI() // Clearly this limits the request URI to 255 bytes. BEP 41 supports // longer but I'm not fussed. options := append([]byte{optionTypeURLData, byte(len(reqURI))}, []byte(reqURI)...) - b, err := c.request(Announce, req, options) + b, err := c.request(ActionAnnounce, req, options) if err != nil { return } @@ -215,7 +215,7 @@ if h.TransactionId != tid { continue } c.contiguousTimeouts = 0 - if h.Action == Error { + if h.Action == ActionError { err = errors.New(buf.String()) } responseBody = buf @@ -254,7 +254,7 @@ return } c.socket = pproffd.WrapNetConn(c.socket) } - b, err := c.request(Connect, nil, nil) + b, err := c.request(ActionConnect, nil, nil) if err != nil { return }