aboutsummaryrefslogtreecommitdiffstats
path: root/eth
diff options
context:
space:
mode:
authorzelig <viktor.tron@gmail.com>2015-03-20 06:46:54 +0800
committerzelig <viktor.tron@gmail.com>2015-03-20 18:41:40 +0800
commit50661f0e683b4975894a0e8fe16024724adef72d (patch)
tree1a7769500acdd3d2b5815c472b7e6701e8ae2d8f /eth
parent01ff0b3176e6d83dcc5e6716f04301de71e3fc9e (diff)
downloadgo-tangerine-50661f0e683b4975894a0e8fe16024724adef72d.tar
go-tangerine-50661f0e683b4975894a0e8fe16024724adef72d.tar.gz
go-tangerine-50661f0e683b4975894a0e8fe16024724adef72d.tar.bz2
go-tangerine-50661f0e683b4975894a0e8fe16024724adef72d.tar.lz
go-tangerine-50661f0e683b4975894a0e8fe16024724adef72d.tar.xz
go-tangerine-50661f0e683b4975894a0e8fe16024724adef72d.tar.zst
go-tangerine-50661f0e683b4975894a0e8fe16024724adef72d.zip
peer suspension to disallow reconnect after disconnect on fatal error for set period (PeerSuspensionInterval)
Diffstat (limited to 'eth')
-rw-r--r--eth/protocol.go13
1 files changed, 9 insertions, 4 deletions
diff --git a/eth/protocol.go b/eth/protocol.go
index 6d610a663..1999d9807 100644
--- a/eth/protocol.go
+++ b/eth/protocol.go
@@ -42,6 +42,7 @@ const (
ErrGenesisBlockMismatch
ErrNoStatusMsg
ErrExtraStatusMsg
+ ErrSuspendedPeer
)
var errorToString = map[int]string{
@@ -53,6 +54,7 @@ var errorToString = map[int]string{
ErrGenesisBlockMismatch: "Genesis block mismatch",
ErrNoStatusMsg: "No status message",
ErrExtraStatusMsg: "Extra status message",
+ ErrSuspendedPeer: "Suspended peer",
}
// ethProtocol represents the ethereum wire protocol
@@ -85,7 +87,7 @@ type chainManager interface {
type blockPool interface {
AddBlockHashes(next func() (common.Hash, bool), peerId string)
AddBlock(block *types.Block, peerId string)
- AddPeer(td *big.Int, currentBlock common.Hash, peerId string, requestHashes func(common.Hash) error, requestBlocks func([]common.Hash) error, peerError func(*errs.Error)) (best bool)
+ AddPeer(td *big.Int, currentBlock common.Hash, peerId string, requestHashes func(common.Hash) error, requestBlocks func([]common.Hash) error, peerError func(*errs.Error)) (best bool, suspended bool)
RemovePeer(peerId string)
}
@@ -288,7 +290,7 @@ func (self *ethProtocol) handle() error {
// to simplify backend interface adding a new block
// uses AddPeer followed by AddBlock only if peer is the best peer
// (or selected as new best peer)
- if self.blockPool.AddPeer(request.TD, hash, self.id, self.requestBlockHashes, self.requestBlocks, self.protoErrorDisconnect) {
+ if best, _ := self.blockPool.AddPeer(request.TD, hash, self.id, self.requestBlockHashes, self.requestBlocks, self.protoErrorDisconnect); best {
self.blockPool.AddBlock(request.Block, self.id)
}
@@ -334,9 +336,12 @@ func (self *ethProtocol) handleStatus() error {
return self.protoError(ErrProtocolVersionMismatch, "%d (!= %d)", status.ProtocolVersion, self.protocolVersion)
}
- self.peer.Infof("Peer is [eth] capable (%d/%d). TD=%v H=%x\n", status.ProtocolVersion, status.NetworkId, status.TD, status.CurrentBlock[:4])
+ _, suspended := self.blockPool.AddPeer(status.TD, status.CurrentBlock, self.id, self.requestBlockHashes, self.requestBlocks, self.protoErrorDisconnect)
+ if suspended {
+ return self.protoError(ErrSuspendedPeer, "")
+ }
- self.blockPool.AddPeer(status.TD, status.CurrentBlock, self.id, self.requestBlockHashes, self.requestBlocks, self.protoErrorDisconnect)
+ self.peer.Infof("Peer is [eth] capable (%d/%d). TD=%v H=%x\n", status.ProtocolVersion, status.NetworkId, status.TD, status.CurrentBlock[:4])
return nil
}