do not shut down connections on PacketDecodingError
This commit is contained in:
1 parent
f4ba0f7287
commit
a5a91ebb33
2 files changed
+14
-13
No files matched your search
+2
-3
@@ -271,8 +271,7 @@ type NaClDecryptorInstance struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type PacketDecodingError struct {
|
type PacketDecodingError struct {
|
||||||
Fatal bool
|
Desc string
|
||||||
Desc string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewNonDecryptor(conn *LocalConnection) *NonDecryptor {
|
func NewNonDecryptor(conn *LocalConnection) *NonDecryptor {
|
||||||
@@ -335,7 +334,7 @@ func (nd *NaClDecryptor) ReceiveNonce(msg []byte) {
|
|||||||
func (nd *NaClDecryptor) IterateFrames(packet []byte, consumer FrameConsumer) error {
|
func (nd *NaClDecryptor) IterateFrames(packet []byte, consumer FrameConsumer) error {
|
||||||
buf, err := nd.decrypt(packet)
|
buf, err := nd.decrypt(packet)
|
||||||
if err != nil {
|
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)
|
return nd.NonDecryptor.IterateFrames(buf, consumer)
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-10
@@ -250,16 +250,18 @@ func (router *Router) udpReader(conn *net.UDPConn, po PacketSink) {
|
|||||||
if !ok {
|
if !ok {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
err = relayConn.Decryptor.IterateFrames(packet, router.handleUDPPacketFunc(dec, sender, po))
|
if err := relayConn.Decryptor.IterateFrames(packet, router.handleUDPPacketFunc(dec, sender, po)); err != nil {
|
||||||
if pde, ok := err.(PacketDecodingError); ok {
|
// Errors during UDP packet decoding / processing are
|
||||||
if pde.Fatal {
|
// non-fatal. One common cause is that we receive and
|
||||||
relayConn.Shutdown(pde)
|
// attempt to decrypt a "stray" packet. This can actually
|
||||||
} else {
|
// happen quite easily if there is some connection churn
|
||||||
relayConn.Log(pde.Error())
|
// between two peers. After all, UDP isn't a
|
||||||
}
|
// connection-oriented protocol, yet we pretend it is.
|
||||||
continue
|
//
|
||||||
}
|
// If anything really is seriously, unrecoverably amiss
|
||||||
if err != nil {
|
// with a connection, that will typically result in missed
|
||||||
|
// heartbeats and the connection getting shut down because
|
||||||
|
// of that.
|
||||||
relayConn.Log(err)
|
relayConn.Log(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user