From fd3e1061e01690c7046a0d80635284c1592b7699 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Fri, 13 Feb 2015 15:06:06 +0100 Subject: [PATCH] p2p: handle disconnect before protocol handshake --- p2p/peer.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/p2p/peer.go b/p2p/peer.go index f779c1c02..6aa78045b 100644 --- a/p2p/peer.go +++ b/p2p/peer.go @@ -255,6 +255,13 @@ func readProtocolHandshake(p *Peer, rw MsgReadWriter) error { if err != nil { return err } + if msg.Code == discMsg { + // disconnect before protocol handshake is valid according to the + // spec and we send it ourself if Server.addPeer fails. + var reason DiscReason + rlp.Decode(msg.Payload, &reason) + return discRequestedError(reason) + } if msg.Code != handshakeMsg { return newPeerError(errProtocolBreach, "expected handshake, got %x", msg.Code) }