diff options
author | obscuren <geffobscura@gmail.com> | 2015-03-21 00:42:25 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-03-21 00:42:25 +0800 |
commit | 1821d1af48e5fa11eb81fe7f6e5372737bb36ec9 (patch) | |
tree | d534f2059f6c14ac7f2dd1ab9996ef0cd4c34b95 /eth/protocol.go | |
parent | a59bb053f4d2a4a28341c645c051c4c323581a1b (diff) | |
parent | 66b29899c474abeab6c66060c9ea5bbff85b9efb (diff) | |
download | go-tangerine-1821d1af48e5fa11eb81fe7f6e5372737bb36ec9.tar go-tangerine-1821d1af48e5fa11eb81fe7f6e5372737bb36ec9.tar.gz go-tangerine-1821d1af48e5fa11eb81fe7f6e5372737bb36ec9.tar.bz2 go-tangerine-1821d1af48e5fa11eb81fe7f6e5372737bb36ec9.tar.lz go-tangerine-1821d1af48e5fa11eb81fe7f6e5372737bb36ec9.tar.xz go-tangerine-1821d1af48e5fa11eb81fe7f6e5372737bb36ec9.tar.zst go-tangerine-1821d1af48e5fa11eb81fe7f6e5372737bb36ec9.zip |
Merge branch 'frontier/blockpool' of https://github.com/ethersphere/go-ethereum into ethersphere-frontier/blockpool
Diffstat (limited to 'eth/protocol.go')
-rw-r--r-- | eth/protocol.go | 13 |
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 } |