aboutsummaryrefslogtreecommitdiffstats
path: root/eth/protocol.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-03-21 01:01:05 +0800
committerobscuren <geffobscura@gmail.com>2015-03-21 01:01:05 +0800
commitf4e9638867f5dab01eeb6db5fdbd85737a11fbd6 (patch)
tree8d8cbfeb2533a2b84e5f0927e9bfdd688cdffbb2 /eth/protocol.go
parent54dac59285ccc6a3af47201479ca556da2899e93 (diff)
parentecd10d2cf765072cd74347b9e0ca2bb85091450f (diff)
downloadgo-tangerine-f4e9638867f5dab01eeb6db5fdbd85737a11fbd6.tar.gz
go-tangerine-f4e9638867f5dab01eeb6db5fdbd85737a11fbd6.tar.zst
go-tangerine-f4e9638867f5dab01eeb6db5fdbd85737a11fbd6.zip
Merge branch 'ethersphere-frontier/blockpool' into conversion
Diffstat (limited to 'eth/protocol.go')
-rw-r--r--eth/protocol.go16
1 files changed, 10 insertions, 6 deletions
diff --git a/eth/protocol.go b/eth/protocol.go
index 6d610a663..494c1c1bb 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)
}
@@ -211,8 +213,7 @@ func (self *ethProtocol) handle() error {
var i int
iter := func() (hash common.Hash, ok bool) {
- var h common.Hash
- err := msgStream.Decode(&h)
+ err := msgStream.Decode(&hash)
if err == rlp.EOL {
return common.Hash{}, false
} else if err != nil {
@@ -288,7 +289,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 +335,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
}