diff options
Diffstat (limited to 'eth/handler.go')
-rw-r--r-- | eth/handler.go | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/eth/handler.go b/eth/handler.go index 777a9c7c0..aea33452c 100644 --- a/eth/handler.go +++ b/eth/handler.go @@ -2,7 +2,6 @@ package eth import ( "fmt" - "math" "math/big" "sync" "time" @@ -93,14 +92,22 @@ func NewProtocolManager(protocolVersion, networkId int, mux *event.TypeMux, txpo } func (pm *ProtocolManager) removePeer(id string) { - // Unregister the peer from the downloader - pm.downloader.UnregisterPeer(id) + // Short circuit if the peer was already removed + peer := pm.peers.Peer(id) + if peer == nil { + return + } + glog.V(logger.Debug).Infoln("Removing peer", id) - // Remove the peer from the Ethereum peer set too - glog.V(logger.Detail).Infoln("Removing peer", id) + // Unregister the peer from the downloader and Ethereum peer set + pm.downloader.UnregisterPeer(id) if err := pm.peers.Unregister(id); err != nil { glog.V(logger.Error).Infoln("Removal failed:", err) } + // Hard disconnect at the networking layer + if peer != nil { + peer.Peer.Disconnect(p2p.DiscUselessPeer) + } } func (pm *ProtocolManager) Start() { @@ -351,7 +358,7 @@ func (pm *ProtocolManager) verifyTd(peer *peer, request newBlockMsgData) error { func (pm *ProtocolManager) BroadcastBlock(hash common.Hash, block *types.Block) { // Broadcast block to a batch of peers not knowing about it peers := pm.peers.PeersWithoutBlock(hash) - peers = peers[:int(math.Sqrt(float64(len(peers))))] + //peers = peers[:int(math.Sqrt(float64(len(peers))))] for _, peer := range peers { peer.sendNewBlock(block) } |