From 644697977b84264cc3e6964b74e8473edcdf9ed2 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Tue, 20 Jan 2015 21:51:18 +0000 Subject: [PATCH] refactor: make protocol message tags a separate type --- router/connection.go | 2 +- router/protocol.go | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/router/connection.go b/router/connection.go index e2c77bd1..8eb1625f 100644 --- a/router/connection.go +++ b/router/connection.go @@ -530,7 +530,7 @@ func (conn *LocalConnection) receiveTCP(decoder *gob.Decoder) { continue } payload := msg[1:] - switch msg[0] { + switch ProtocolMsg(msg[0]) { case ProtocolConnectionEstablished: // We sent fast heartbeats to the remote peer, which has // now received at least one of them and told us via this diff --git a/router/protocol.go b/router/protocol.go index 05c36a45..9fffe7f5 100644 --- a/router/protocol.go +++ b/router/protocol.go @@ -5,8 +5,10 @@ const ( ProtocolVersion = 10 ) +type ProtocolMsg byte + const ( - ProtocolConnectionEstablished = iota + ProtocolConnectionEstablished ProtocolMsg = iota ProtocolFragmentationReceived ProtocolStartFragmentationTest ProtocolNonce @@ -16,11 +18,11 @@ const ( ) var ( - ProtocolConnectionEstablishedByte = []byte{ProtocolConnectionEstablished} - ProtocolFragmentationReceivedByte = []byte{ProtocolFragmentationReceived} - ProtocolStartFragmentationTestByte = []byte{ProtocolStartFragmentationTest} - ProtocolNonceByte = []byte{ProtocolNonce} - ProtocolFetchAllByte = []byte{ProtocolFetchAll} - ProtocolUpdateByte = []byte{ProtocolUpdate} - ProtocolPMTUVerifiedByte = []byte{ProtocolPMTUVerified} + ProtocolConnectionEstablishedByte = []byte{byte(ProtocolConnectionEstablished)} + ProtocolFragmentationReceivedByte = []byte{byte(ProtocolFragmentationReceived)} + ProtocolStartFragmentationTestByte = []byte{byte(ProtocolStartFragmentationTest)} + ProtocolNonceByte = []byte{byte(ProtocolNonce)} + ProtocolFetchAllByte = []byte{byte(ProtocolFetchAll)} + ProtocolUpdateByte = []byte{byte(ProtocolUpdate)} + ProtocolPMTUVerifiedByte = []byte{byte(ProtocolPMTUVerified)} )