Skip to content

Commit

Permalink
Removed peers from peerlist as soon as they disconnect. Might fix eth…
Browse files Browse the repository at this point in the history
…ereum#13

We used to wait for the reaping timer to clean up the peerlist, not any longer
  • Loading branch information
Maran committed May 12, 2014
1 parent 8fe0864 commit 52b664b
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package eth

import (
"bytes"
"container/list"
"fmt"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethutil"
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 52b664b

Please sign in to comment.