From 077ffaaf40d520f810b32c811f5e339fcbe640e8 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Sun, 7 Feb 2016 17:16:01 +1100 Subject: [PATCH] Prefix the Action constants In preparation to rework the client interface --- tracker/server.go | 12 ++++++------ tracker/udp.go | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/tracker/server.go b/tracker/server.go index e8613b08..3e98ae1d 100644 --- a/tracker/server.go +++ b/tracker/server.go @@ -65,23 +65,23 @@ func (me *server) serveOne() (err error) { 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 @@ func (me *server) serveOne() (err error) { } err = me.respond(addr, ResponseHeader{ TransactionId: h.TransactionId, - Action: Announce, + Action: ActionAnnounce, }, AnnounceResponseHeader{ Interval: 900, Leechers: t.Leechers, @@ -108,7 +108,7 @@ func (me *server) serveOne() (err error) { 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 d8536747..36f7cc7e 100644 --- a/tracker/udp.go +++ b/tracker/udp.go @@ -20,10 +20,10 @@ import ( type Action int32 const ( - Connect Action = iota - Announce - Scrape - Error + ActionConnect Action = iota + ActionAnnounce + ActionScrape + ActionError connectRequestConnectionId = 0x41727101980 @@ -110,7 +110,7 @@ func (c *udpClient) Announce(req *AnnounceRequest) (res AnnounceResponse, err er // 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 @@ func (c *udpClient) request(action Action, args interface{}, options []byte) (re continue } c.contiguousTimeouts = 0 - if h.Action == Error { + if h.Action == ActionError { err = errors.New(buf.String()) } responseBody = buf @@ -254,7 +254,7 @@ func (c *udpClient) Connect() (err error) { } c.socket = pproffd.WrapNetConn(c.socket) } - b, err := c.request(Connect, nil, nil) + b, err := c.request(ActionConnect, nil, nil) if err != nil { return } -- 2.48.1