cosmetic: turn some if-then-else into 'switch'
This commit is contained in:
1 parent
198de416ab
commit
d69854d9c5
2 files changed
+24
-18
No files matched your search
+14
-9
@@ -479,23 +479,28 @@ func (conn *LocalConnection) receiveTCP(decoder *gob.Decoder) {
|
||||
// the traffic rather than shutting down.
|
||||
continue
|
||||
}
|
||||
if msg[0] == ProtocolConnectionEstablished {
|
||||
switch 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
|
||||
// message. We can now consider the connection as
|
||||
// established from our end.
|
||||
conn.SetEstablished()
|
||||
} else if msg[0] == ProtocolStartFragmentationTest {
|
||||
case ProtocolStartFragmentationTest:
|
||||
conn.Forward(false, &ForwardedFrame{
|
||||
srcPeer: conn.local,
|
||||
dstPeer: conn.remote,
|
||||
frame: FragTest},
|
||||
nil)
|
||||
} else if msg[0] == ProtocolFragmentationReceived {
|
||||
case ProtocolFragmentationReceived:
|
||||
conn.setStackFrag(true)
|
||||
} else if usingPassword && msg[0] == ProtocolNonce {
|
||||
conn.Decryptor.ReceiveNonce(msg[1:])
|
||||
} else if msg[0] == ProtocolFetchAll {
|
||||
case ProtocolNonce:
|
||||
if usingPassword {
|
||||
conn.Decryptor.ReceiveNonce(msg[1:])
|
||||
} else {
|
||||
conn.log("ignoring unexpected nonce on unencrypted connection")
|
||||
}
|
||||
case ProtocolFetchAll:
|
||||
// There are exactly two messages that relate to topology
|
||||
// updates.
|
||||
//
|
||||
@@ -517,7 +522,7 @@ func (conn *LocalConnection) receiveTCP(decoder *gob.Decoder) {
|
||||
// - elements where the payload was older than the
|
||||
// receiver's version are updated
|
||||
conn.SendTCP(Concat(ProtocolUpdateByte, conn.Router.Peers.EncodeAllPeers()))
|
||||
} else if msg[0] == ProtocolUpdate {
|
||||
case ProtocolUpdate:
|
||||
newUpdate, err := conn.Router.Peers.ApplyUpdate(msg[1:])
|
||||
if _, ok := err.(UnknownPeersError); err != nil && ok {
|
||||
// That update contained a peer we didn't know about;
|
||||
@@ -533,9 +538,9 @@ func (conn *LocalConnection) receiveTCP(decoder *gob.Decoder) {
|
||||
conn.Router.Routes.Recalculate()
|
||||
conn.Router.Ourself.BroadcastTCP(Concat(ProtocolUpdateByte, newUpdate))
|
||||
}
|
||||
} else if msg[0] == ProtocolPMTUVerified {
|
||||
case ProtocolPMTUVerified:
|
||||
conn.verifyPMTU <- int(binary.BigEndian.Uint16(msg[1:]))
|
||||
} else {
|
||||
default:
|
||||
conn.log("received unknown msg:\n", msg)
|
||||
}
|
||||
}
|
||||
|
||||
+10
-9
@@ -320,8 +320,9 @@ func (nd *NaClDecryptor) decrypt(buf []byte) ([]byte, error) {
|
||||
usedOffsets = decState.usedOffsets
|
||||
} else {
|
||||
highestOffsetSeen := decState.highestOffsetSeen
|
||||
if offsetNoFlags < (1<<13) && highestOffsetSeen > ((1<<14)+(1<<13)) &&
|
||||
(highestOffsetSeen-offsetNoFlags) > ((1<<14)+(1<<13)) {
|
||||
switch {
|
||||
case offsetNoFlags < (1<<13) && highestOffsetSeen > ((1<<14)+(1<<13)) &&
|
||||
(highestOffsetSeen-offsetNoFlags) > ((1<<14)+(1<<13)):
|
||||
// offset is in the first quarter, highestOffsetSeen is in
|
||||
// the top quarter and under a quarter behind us. We
|
||||
// interpret this as we need to move to the next nonce
|
||||
@@ -335,29 +336,29 @@ func (nd *NaClDecryptor) decrypt(buf []byte) ([]byte, error) {
|
||||
decState.highestOffsetSeen = offsetNoFlags
|
||||
nonce = decState.nonce
|
||||
usedOffsets = decState.usedOffsets
|
||||
} else if offsetNoFlags > highestOffsetSeen &&
|
||||
(offsetNoFlags-highestOffsetSeen) < (1<<13) {
|
||||
case offsetNoFlags > highestOffsetSeen &&
|
||||
(offsetNoFlags-highestOffsetSeen) < (1<<13):
|
||||
// offset is under a quarter above highestOffsetSeen. This
|
||||
// is ok - maybe some packet loss
|
||||
decState.highestOffsetSeen = offsetNoFlags
|
||||
nonce = decState.nonce
|
||||
usedOffsets = decState.usedOffsets
|
||||
} else if offsetNoFlags <= highestOffsetSeen &&
|
||||
(highestOffsetSeen-offsetNoFlags) < (1<<13) {
|
||||
case offsetNoFlags <= highestOffsetSeen &&
|
||||
(highestOffsetSeen-offsetNoFlags) < (1<<13):
|
||||
// offset is within a quarter of the highest we've
|
||||
// seen. This is ok - just assuming some out-of-order
|
||||
// delivery.
|
||||
nonce = decState.nonce
|
||||
usedOffsets = decState.usedOffsets
|
||||
} else if highestOffsetSeen < (1<<13) && offsetNoFlags > ((1<<14)+(1<<13)) &&
|
||||
(offsetNoFlags-highestOffsetSeen) > ((1<<14)+(1<<13)) {
|
||||
case highestOffsetSeen < (1<<13) && offsetNoFlags > ((1<<14)+(1<<13)) &&
|
||||
(offsetNoFlags-highestOffsetSeen) > ((1<<14)+(1<<13)):
|
||||
// offset is in the last quarter, highestOffsetSeen is in
|
||||
// the first quarter, and offset is under a quarter behind
|
||||
// us. This is ok - as above, just some out of order. But
|
||||
// here it means we're dealing with the previous nonce
|
||||
nonce = decState.previousNonce
|
||||
usedOffsets = decState.previousUsedOffsets
|
||||
} else {
|
||||
default:
|
||||
return nil, fmt.Errorf("Unexpected offset when decrypting UDP packet")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user