From f0f672777866a524c36e767a6c313f93f574dd8c Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Fri, 12 Dec 2014 11:58:39 +0100 Subject: [PATCH] p2p: use an error type for disconnect requests Test-tastic. --- p2p/peer_error.go | 9 +++++++++ p2p/protocol.go | 3 +-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/p2p/peer_error.go b/p2p/peer_error.go index 88b870fbdf..0eb7ec838d 100644 --- a/p2p/peer_error.go +++ b/p2p/peer_error.go @@ -100,7 +100,16 @@ func (d DiscReason) String() string { return discReasonToString[d] } +type discRequestedError DiscReason + +func (err discRequestedError) Error() string { + return fmt.Sprintf("disconnect requested: %v", DiscReason(err)) +} + func discReasonForError(err error) DiscReason { + if reason, ok := err.(discRequestedError); ok { + return DiscReason(reason) + } peerError, ok := err.(*peerError) if !ok { return DiscSubprotocolError diff --git a/p2p/protocol.go b/p2p/protocol.go index 5af586f130..3f52205f59 100644 --- a/p2p/protocol.go +++ b/p2p/protocol.go @@ -158,8 +158,7 @@ func (bp *baseProtocol) handle(rw MsgReadWriter) error { if err := msg.Decode(&reason); err != nil { return err } - bp.peer.Disconnect(reason[0]) - return nil + return discRequestedError(reason[0]) case pingMsg: return bp.rw.EncodeMsg(pongMsg)