From a5a91ebb331c3f04465c6b89a5c58e5a909720d7 Mon Sep 17 00:00:00 2001 From: Matthias Radestock Date: Wed, 15 Apr 2015 21:52:56 +0100 Subject: [PATCH] do not shut down connections on PacketDecodingError --- router/crypto.go | 5 ++--- router/router.go | 22 ++++++++++++---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/router/crypto.go b/router/crypto.go index 08645df1..7c2c0b4f 100644 --- a/router/crypto.go +++ b/router/crypto.go @@ -271,8 +271,7 @@ type NaClDecryptorInstance struct { } type PacketDecodingError struct { - Fatal bool - Desc string + Desc string } func NewNonDecryptor(conn *LocalConnection) *NonDecryptor { @@ -335,7 +334,7 @@ func (nd *NaClDecryptor) ReceiveNonce(msg []byte) { func (nd *NaClDecryptor) IterateFrames(packet []byte, consumer FrameConsumer) error { buf, err := nd.decrypt(packet) if err != nil { - return PacketDecodingError{Fatal: true, Desc: fmt.Sprint("decryption failed; ", err)} + return PacketDecodingError{Desc: fmt.Sprint("decryption failed; ", err)} } return nd.NonDecryptor.IterateFrames(buf, consumer) } diff --git a/router/router.go b/router/router.go index 797dccf6..092a3842 100644 --- a/router/router.go +++ b/router/router.go @@ -250,16 +250,18 @@ func (router *Router) udpReader(conn *net.UDPConn, po PacketSink) { if !ok { continue } - err = relayConn.Decryptor.IterateFrames(packet, router.handleUDPPacketFunc(dec, sender, po)) - if pde, ok := err.(PacketDecodingError); ok { - if pde.Fatal { - relayConn.Shutdown(pde) - } else { - relayConn.Log(pde.Error()) - } - continue - } - if err != nil { + if err := relayConn.Decryptor.IterateFrames(packet, router.handleUDPPacketFunc(dec, sender, po)); err != nil { + // Errors during UDP packet decoding / processing are + // non-fatal. One common cause is that we receive and + // attempt to decrypt a "stray" packet. This can actually + // happen quite easily if there is some connection churn + // between two peers. After all, UDP isn't a + // connection-oriented protocol, yet we pretend it is. + // + // If anything really is seriously, unrecoverably amiss + // with a connection, that will typically result in missed + // heartbeats and the connection getting shut down because + // of that. relayConn.Log(err) } }