diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-02-28 18:22:05 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-02-28 18:22:05 +0800 |
commit | 965407f2388b4da18fcc65f1e2caab3fdf5718e7 (patch) | |
tree | 6bc5102c4bc17b821aac9e7211f292d7325f900f /p2p/peer_error.go | |
parent | dc0a006c7cc4bb1a9690924bf0fd7a7da9d36384 (diff) | |
parent | 96ae35e2ac8c360781407d7294081aabdcbb3652 (diff) | |
download | dexon-965407f2388b4da18fcc65f1e2caab3fdf5718e7.tar dexon-965407f2388b4da18fcc65f1e2caab3fdf5718e7.tar.gz dexon-965407f2388b4da18fcc65f1e2caab3fdf5718e7.tar.bz2 dexon-965407f2388b4da18fcc65f1e2caab3fdf5718e7.tar.lz dexon-965407f2388b4da18fcc65f1e2caab3fdf5718e7.tar.xz dexon-965407f2388b4da18fcc65f1e2caab3fdf5718e7.tar.zst dexon-965407f2388b4da18fcc65f1e2caab3fdf5718e7.zip |
Merge pull request #3709 from fjl/p2p-context-log
p2p, p2p/discover, p2p/nat: rework logging using context keys
Diffstat (limited to 'p2p/peer_error.go')
-rw-r--r-- | p2p/peer_error.go | 34 |
1 files changed, 20 insertions, 14 deletions
diff --git a/p2p/peer_error.go b/p2p/peer_error.go index 62c7b665d..a1cddb707 100644 --- a/p2p/peer_error.go +++ b/p2p/peer_error.go @@ -17,6 +17,7 @@ package p2p import ( + "errors" "fmt" ) @@ -51,6 +52,8 @@ func (self *peerError) Error() string { return self.message } +var errProtocolReturned = errors.New("protocol returned") + type DiscReason uint const ( @@ -70,24 +73,24 @@ const ( ) var discReasonToString = [...]string{ - DiscRequested: "Disconnect requested", - DiscNetworkError: "Network error", - DiscProtocolError: "Breach of protocol", - DiscUselessPeer: "Useless peer", - DiscTooManyPeers: "Too many peers", - DiscAlreadyConnected: "Already connected", - DiscIncompatibleVersion: "Incompatible P2P protocol version", - DiscInvalidIdentity: "Invalid node identity", - DiscQuitting: "Client quitting", - DiscUnexpectedIdentity: "Unexpected identity", - DiscSelf: "Connected to self", - DiscReadTimeout: "Read timeout", - DiscSubprotocolError: "Subprotocol error", + DiscRequested: "disconnect requested", + DiscNetworkError: "network error", + DiscProtocolError: "breach of protocol", + DiscUselessPeer: "useless peer", + DiscTooManyPeers: "too many peers", + DiscAlreadyConnected: "already connected", + DiscIncompatibleVersion: "incompatible p2p protocol version", + DiscInvalidIdentity: "invalid node identity", + DiscQuitting: "client quitting", + DiscUnexpectedIdentity: "unexpected identity", + DiscSelf: "connected to self", + DiscReadTimeout: "read timeout", + DiscSubprotocolError: "subprotocol error", } func (d DiscReason) String() string { if len(discReasonToString) < int(d) { - return fmt.Sprintf("Unknown Reason(%d)", d) + return fmt.Sprintf("unknown disconnect reason %d", d) } return discReasonToString[d] } @@ -100,6 +103,9 @@ func discReasonForError(err error) DiscReason { if reason, ok := err.(DiscReason); ok { return reason } + if err == errProtocolReturned { + return DiscQuitting + } peerError, ok := err.(*peerError) if ok { switch peerError.code { |