aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/peer_error_handler.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2014-11-04 20:21:44 +0800
committerFelix Lange <fjl@twurst.com>2014-11-22 04:52:45 +0800
commitf38052c499c1fee61423efeddb1f52677f1442e9 (patch)
tree6cc4c4e9739d61edeba9dc62781b2ebdeb0faf11 /p2p/peer_error_handler.go
parent8cf9ed0ea588e97f2baf0f834248727e8fbca18f (diff)
downloadgo-tangerine-f38052c499c1fee61423efeddb1f52677f1442e9.tar
go-tangerine-f38052c499c1fee61423efeddb1f52677f1442e9.tar.gz
go-tangerine-f38052c499c1fee61423efeddb1f52677f1442e9.tar.bz2
go-tangerine-f38052c499c1fee61423efeddb1f52677f1442e9.tar.lz
go-tangerine-f38052c499c1fee61423efeddb1f52677f1442e9.tar.xz
go-tangerine-f38052c499c1fee61423efeddb1f52677f1442e9.tar.zst
go-tangerine-f38052c499c1fee61423efeddb1f52677f1442e9.zip
p2p: rework protocol API
Diffstat (limited to 'p2p/peer_error_handler.go')
-rw-r--r--p2p/peer_error_handler.go31
1 files changed, 14 insertions, 17 deletions
diff --git a/p2p/peer_error_handler.go b/p2p/peer_error_handler.go
index ca6cae4db..47dcd14ff 100644
--- a/p2p/peer_error_handler.go
+++ b/p2p/peer_error_handler.go
@@ -18,17 +18,15 @@ type PeerErrorHandler struct {
address net.Addr
peerDisconnect chan DisconnectRequest
severity int
- peerErrorChan chan *PeerError
- blacklist Blacklist
+ errc chan error
}
-func NewPeerErrorHandler(address net.Addr, peerDisconnect chan DisconnectRequest, peerErrorChan chan *PeerError, blacklist Blacklist) *PeerErrorHandler {
+func NewPeerErrorHandler(address net.Addr, peerDisconnect chan DisconnectRequest, errc chan error) *PeerErrorHandler {
return &PeerErrorHandler{
quit: make(chan chan bool),
address: address,
peerDisconnect: peerDisconnect,
- peerErrorChan: peerErrorChan,
- blacklist: blacklist,
+ errc: errc,
}
}
@@ -45,10 +43,10 @@ func (self *PeerErrorHandler) Stop() {
func (self *PeerErrorHandler) listen() {
for {
select {
- case peerError, ok := <-self.peerErrorChan:
+ case err, ok := <-self.errc:
if ok {
- logger.Debugf("error %v\n", peerError)
- go self.handle(peerError)
+ logger.Debugf("error %v\n", err)
+ go self.handle(err)
} else {
return
}
@@ -59,8 +57,12 @@ func (self *PeerErrorHandler) listen() {
}
}
-func (self *PeerErrorHandler) handle(peerError *PeerError) {
+func (self *PeerErrorHandler) handle(err error) {
reason := DiscReason(' ')
+ peerError, ok := err.(*PeerError)
+ if !ok {
+ peerError = NewPeerError(MiscError, " %v", err)
+ }
switch peerError.Code {
case P2PVersionMismatch:
reason = DiscIncompatibleVersion
@@ -68,11 +70,11 @@ func (self *PeerErrorHandler) handle(peerError *PeerError) {
reason = DiscInvalidIdentity
case PubkeyForbidden:
reason = DiscUselessPeer
- case InvalidMsgCode, PacketTooShort, PayloadTooShort, MagicTokenMismatch, EmptyPayload, ProtocolBreach:
+ case InvalidMsgCode, PacketTooLong, PayloadTooShort, MagicTokenMismatch, ProtocolBreach:
reason = DiscProtocolError
case PingTimeout:
reason = DiscReadTimeout
- case WriteError, MiscError:
+ case ReadError, WriteError, MiscError:
reason = DiscNetworkError
case InvalidGenesis, InvalidNetworkId, InvalidProtocolVersion:
reason = DiscSubprotocolError
@@ -92,10 +94,5 @@ func (self *PeerErrorHandler) handle(peerError *PeerError) {
}
func (self *PeerErrorHandler) getSeverity(peerError *PeerError) int {
- switch peerError.Code {
- case ReadError:
- return 4 //tolerate 3 :)
- default:
- return 1
- }
+ return 1
}