From 8deef98874eab8b7557943b8deedc833dbbe02b2 Mon Sep 17 00:00:00 2001 From: Jimmy Zelinskie Date: Wed, 25 Feb 2015 21:47:01 -0500 Subject: [PATCH] udp: style nitpicks --- udp/protocol.go | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/udp/protocol.go b/udp/protocol.go index 57cf8f3..513bc7f 100644 --- a/udp/protocol.go +++ b/udp/protocol.go @@ -13,19 +13,6 @@ import ( "github.com/chihaya/chihaya/tracker/models" ) -// initialConnectionID is the magic initial connection ID specified by BEP 15. -var initialConnectionID = []byte{0, 0, 0x04, 0x17, 0x27, 0x10, 0x19, 0x80} - -// eventIDs maps IDs to event names. -var eventIDs = []string{"", "completed", "started", "stopped"} - -var ( - errMalformedPacket = models.ProtocolError("malformed packet") - errMalformedIP = models.ProtocolError("malformed IP address") - errMalformedEvent = models.ProtocolError("malformed event ID") - errBadConnectionID = models.ProtocolError("bad connection ID") -) - const ( connectActionID uint32 = iota announceActionID @@ -33,6 +20,24 @@ const ( errorActionID ) +var ( + // initialConnectionID is the magic initial connection ID specified by BEP 15. + initialConnectionID = []byte{0, 0, 0x04, 0x17, 0x27, 0x10, 0x19, 0x80} + + // eventIDs maps IDs to event names. + eventIDs = []string{ + "", + "completed", + "started", + "stopped", + } + + errMalformedPacket = models.ProtocolError("malformed packet") + errMalformedIP = models.ProtocolError("malformed IP address") + errMalformedEvent = models.ProtocolError("malformed event ID") + errBadConnectionID = models.ProtocolError("bad connection ID") +) + // handleTorrentError writes err to w if err is a models.ClientError. func handleTorrentError(err error, w *Writer) { if err == nil { @@ -61,7 +66,6 @@ func (s *Server) handlePacket(packet []byte, addr *net.UDPAddr) (response []byte connectionID: connID, transactionID: transactionID, } - defer func() { response = writer.buf.Bytes() }() if action != 0 && !s.connIDGen.Matches(connID, addr.IP) { @@ -121,9 +125,9 @@ func (s *Server) newAnnounce(packet []byte, ip net.IP) (*models.Announce, error) return nil, errMalformedEvent } - ipbuf := packet[84:88] + ipbytes := packet[84:88] if s.config.AllowIPSpoofing && !bytes.Equal(ipbuf, []byte{0, 0, 0, 0}) { - ip = net.ParseIP(string(ipbuf)) + ip = net.ParseIP(string(ipbytes)) } if ip == nil {