]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Prefix the Action constants
authorMatt Joiner <anacrolix@gmail.com>
Sun, 7 Feb 2016 06:16:01 +0000 (17:16 +1100)
committerMatt Joiner <anacrolix@gmail.com>
Sun, 7 Feb 2016 06:16:01 +0000 (17:16 +1100)
In preparation to rework the client interface

tracker/server.go
tracker/udp.go

index e8613b08eb14ca3dad007bc755fddd99931ab9f0..3e98ae1d61c6054bf960f7b690a443efe9f6cdbe 100644 (file)
@@ -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
        }
index d853674753f771095d657c99256c9efcb1be7abf..36f7cc7eeda47f7161378a1d3f12625bca791476 100644 (file)
@@ -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
        }