aboutsummaryrefslogtreecommitdiffstats
path: root/eth/peer.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-05-09 20:59:41 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-05-09 20:59:41 +0800
commit756b62988c15afc748c529610f29769a89f86c35 (patch)
tree4828236bb18861a9527f184d33f8df410d37ae19 /eth/peer.go
parentdc7f202ecd39db925c2d425fea36084efcda5ecc (diff)
parent56ed6152a11592d20220daf6322e94a009e6236d (diff)
downloaddexon-756b62988c15afc748c529610f29769a89f86c35.tar
dexon-756b62988c15afc748c529610f29769a89f86c35.tar.gz
dexon-756b62988c15afc748c529610f29769a89f86c35.tar.bz2
dexon-756b62988c15afc748c529610f29769a89f86c35.tar.lz
dexon-756b62988c15afc748c529610f29769a89f86c35.tar.xz
dexon-756b62988c15afc748c529610f29769a89f86c35.tar.zst
dexon-756b62988c15afc748c529610f29769a89f86c35.zip
Merge pull request #2523 from fjl/shutdown
core, eth, miner: improve shutdown synchronisation
Diffstat (limited to 'eth/peer.go')
-rw-r--r--eth/peer.go21
1 files changed, 19 insertions, 2 deletions
diff --git a/eth/peer.go b/eth/peer.go
index 15ba22ff5..8eb41b0f9 100644
--- a/eth/peer.go
+++ b/eth/peer.go
@@ -34,6 +34,7 @@ import (
)
var (
+ errClosed = errors.New("peer set is closed")
errAlreadyRegistered = errors.New("peer is already registered")
errNotRegistered = errors.New("peer is not registered")
)
@@ -351,8 +352,9 @@ func (p *peer) String() string {
// peerSet represents the collection of active peers currently participating in
// the Ethereum sub-protocol.
type peerSet struct {
- peers map[string]*peer
- lock sync.RWMutex
+ peers map[string]*peer
+ lock sync.RWMutex
+ closed bool
}
// newPeerSet creates a new peer set to track the active participants.
@@ -368,6 +370,9 @@ func (ps *peerSet) Register(p *peer) error {
ps.lock.Lock()
defer ps.lock.Unlock()
+ if ps.closed {
+ return errClosed
+ }
if _, ok := ps.peers[p.id]; ok {
return errAlreadyRegistered
}
@@ -450,3 +455,15 @@ func (ps *peerSet) BestPeer() *peer {
}
return bestPeer
}
+
+// Close disconnects all peers.
+// No new peers can be registered after Close has returned.
+func (ps *peerSet) Close() {
+ ps.lock.Lock()
+ defer ps.lock.Unlock()
+
+ for _, p := range ps.peers {
+ p.Disconnect(p2p.DiscQuitting)
+ }
+ ps.closed = true
+}