mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
les: fixed peerSet.Disconnect
This commit is contained in:
parent
0fc06ea8af
commit
6f1abbf2b5
1 changed files with 23 additions and 11 deletions
30
les/peer.go
30
les/peer.go
|
|
@ -873,10 +873,13 @@ func (ps *peerSet) Register(p *peer) error {
|
||||||
ps.lock.Unlock()
|
ps.lock.Unlock()
|
||||||
return errAlreadyRegistered
|
return errAlreadyRegistered
|
||||||
}
|
}
|
||||||
ps.active[p.id] = p
|
if _, ok := ps.inactive[p.id]; ok {
|
||||||
delete(ps.inactive, p.id)
|
delete(ps.inactive, p.id)
|
||||||
|
} else {
|
||||||
p.sendQueue = newExecQueue(100)
|
p.sendQueue = newExecQueue(100)
|
||||||
|
}
|
||||||
|
ps.active[p.id] = p
|
||||||
|
|
||||||
peers := make([]peerSetNotify, len(ps.notifyList))
|
peers := make([]peerSetNotify, len(ps.notifyList))
|
||||||
copy(peers, ps.notifyList)
|
copy(peers, ps.notifyList)
|
||||||
ps.lock.Unlock()
|
ps.lock.Unlock()
|
||||||
|
|
@ -904,7 +907,6 @@ func (ps *peerSet) Unregister(p *peer) error {
|
||||||
for _, n := range peers {
|
for _, n := range peers {
|
||||||
n.unregisterPeer(p)
|
n.unregisterPeer(p)
|
||||||
}
|
}
|
||||||
p.sendQueue.quit()
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -913,17 +915,27 @@ func (ps *peerSet) Unregister(p *peer) error {
|
||||||
// initiates disconnection at the networking layer.
|
// initiates disconnection at the networking layer.
|
||||||
func (ps *peerSet) Disconnect(id string) error {
|
func (ps *peerSet) Disconnect(id string) error {
|
||||||
ps.lock.Lock()
|
ps.lock.Lock()
|
||||||
p, ok := ps.active[id]
|
|
||||||
if ok {
|
var (
|
||||||
delete(ps.active, id)
|
peers []peerSetNotify
|
||||||
|
p *peer
|
||||||
|
ok bool
|
||||||
|
)
|
||||||
|
if p, ok = ps.active[id]; ok {
|
||||||
|
delete(ps.active, p.id)
|
||||||
|
peers = make([]peerSetNotify, len(ps.notifyList))
|
||||||
|
copy(peers, ps.notifyList)
|
||||||
|
} else if p, ok = ps.inactive[id]; ok {
|
||||||
|
delete(ps.inactive, id)
|
||||||
} else {
|
} else {
|
||||||
if p, ok = ps.inactive[id]; !ok {
|
|
||||||
ps.lock.Unlock()
|
ps.lock.Unlock()
|
||||||
return errNotRegistered
|
return errNotRegistered
|
||||||
}
|
}
|
||||||
delete(ps.inactive, id)
|
|
||||||
}
|
|
||||||
ps.lock.Unlock()
|
ps.lock.Unlock()
|
||||||
|
for _, n := range peers {
|
||||||
|
n.unregisterPeer(p)
|
||||||
|
}
|
||||||
|
p.sendQueue.quit()
|
||||||
p.Peer.Disconnect(p2p.DiscUselessPeer)
|
p.Peer.Disconnect(p2p.DiscUselessPeer)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue