aboutsummaryrefslogtreecommitdiffstats
path: root/peer.go
diff options
context:
space:
mode:
authorMaran <maran.hidskes@gmail.com>2014-05-12 22:30:21 +0800
committerMaran <maran.hidskes@gmail.com>2014-05-12 22:32:21 +0800
commit52b664b0aec24bffc040da06bbe8be1d3e7e4ab8 (patch)
tree1f2d235e6e2b66cb0d05e12bde90017bba2feb0c /peer.go
parent8fe0864680b40c3fa5e47775856d8ae1997ba003 (diff)
downloadgo-tangerine-52b664b0aec24bffc040da06bbe8be1d3e7e4ab8.tar
go-tangerine-52b664b0aec24bffc040da06bbe8be1d3e7e4ab8.tar.gz
go-tangerine-52b664b0aec24bffc040da06bbe8be1d3e7e4ab8.tar.bz2
go-tangerine-52b664b0aec24bffc040da06bbe8be1d3e7e4ab8.tar.lz
go-tangerine-52b664b0aec24bffc040da06bbe8be1d3e7e4ab8.tar.xz
go-tangerine-52b664b0aec24bffc040da06bbe8be1d3e7e4ab8.tar.zst
go-tangerine-52b664b0aec24bffc040da06bbe8be1d3e7e4ab8.zip
Removed peers from peerlist as soon as they disconnect. Might fix #13
We used to wait for the reaping timer to clean up the peerlist, not any longer
Diffstat (limited to 'peer.go')
-rw-r--r--peer.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/peer.go b/peer.go
index 359e83566..932dbdc18 100644
--- a/peer.go
+++ b/peer.go
@@ -2,6 +2,7 @@ package eth
import (
"bytes"
+ "container/list"
"fmt"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethutil"
@@ -515,6 +516,15 @@ func (p *Peer) Stop() {
p.writeMessage(ethwire.NewMessage(ethwire.MsgDiscTy, ""))
p.conn.Close()
}
+
+ // Pre-emptively remove the peer; don't wait for reaping. We already know it's dead if we are here
+ p.ethereum.peerMut.Lock()
+ defer p.ethereum.peerMut.Unlock()
+ eachPeer(p.ethereum.peers, func(peer *Peer, e *list.Element) {
+ if peer == p {
+ p.ethereum.peers.Remove(e)
+ }
+ })
}
func (p *Peer) pushHandshake() error {