diff options
author | obscuren <geffobscura@gmail.com> | 2015-05-26 20:51:41 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-05-26 20:51:41 +0800 |
commit | 2f2dd80e480d90fa3bd2f5b2f2413a0eb51f3fa9 (patch) | |
tree | 4fb20244d3c10cdbeb85b993ac6d2e73f73016fa /p2p/peer_error.go | |
parent | e6b143b00dcdb3841d41af0e9a1942f5c24d669f (diff) | |
parent | d74ee40c86fed3a48d88de1094efc0a2f464b659 (diff) | |
download | go-tangerine-0.9.24.tar go-tangerine-0.9.24.tar.gz go-tangerine-0.9.24.tar.bz2 go-tangerine-0.9.24.tar.lz go-tangerine-0.9.24.tar.xz go-tangerine-0.9.24.tar.zst go-tangerine-0.9.24.zip |
Merge branch 'develop'v0.9.24
Diffstat (limited to 'p2p/peer_error.go')
-rw-r--r-- | p2p/peer_error.go | 56 |
1 files changed, 12 insertions, 44 deletions
diff --git a/p2p/peer_error.go b/p2p/peer_error.go index a912f6064..6938a9801 100644 --- a/p2p/peer_error.go +++ b/p2p/peer_error.go @@ -5,39 +5,17 @@ import ( ) const ( - errMagicTokenMismatch = iota - errRead - errWrite - errMisc - errInvalidMsgCode + errInvalidMsgCode = iota errInvalidMsg - errP2PVersionMismatch - errPubkeyInvalid - errPubkeyForbidden - errProtocolBreach - errPingTimeout - errInvalidNetworkId - errInvalidProtocolVersion ) var errorToString = map[int]string{ - errMagicTokenMismatch: "magic token mismatch", - errRead: "read error", - errWrite: "write error", - errMisc: "misc error", - errInvalidMsgCode: "invalid message code", - errInvalidMsg: "invalid message", - errP2PVersionMismatch: "P2P Version Mismatch", - errPubkeyInvalid: "public key invalid", - errPubkeyForbidden: "public key forbidden", - errProtocolBreach: "protocol Breach", - errPingTimeout: "ping timeout", - errInvalidNetworkId: "invalid network id", - errInvalidProtocolVersion: "invalid protocol version", + errInvalidMsgCode: "invalid message code", + errInvalidMsg: "invalid message", } type peerError struct { - Code int + code int message string } @@ -107,23 +85,13 @@ func discReasonForError(err error) DiscReason { return reason } peerError, ok := err.(*peerError) - if !ok { - return DiscSubprotocolError - } - switch peerError.Code { - case errP2PVersionMismatch: - return DiscIncompatibleVersion - case errPubkeyInvalid: - return DiscInvalidIdentity - case errPubkeyForbidden: - return DiscUselessPeer - case errInvalidMsgCode, errMagicTokenMismatch, errProtocolBreach: - return DiscProtocolError - case errPingTimeout: - return DiscReadTimeout - case errRead, errWrite: - return DiscNetworkError - default: - return DiscSubprotocolError + if ok { + switch peerError.code { + case errInvalidMsgCode, errInvalidMsg: + return DiscProtocolError + default: + return DiscSubprotocolError + } } + return DiscSubprotocolError } |