mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
swarm/network, swamr/network/stream: Kademlia close addr count and depth change chans
This commit is contained in:
parent
fa785341bf
commit
3df5784076
2 changed files with 28 additions and 0 deletions
|
|
@ -333,6 +333,18 @@ func (k *Kademlia) NeighbourhoodDepthC() <-chan int {
|
|||
return k.nDepthC
|
||||
}
|
||||
|
||||
// CloseNeighbourhoodDepthC closes the channel returned by
|
||||
// NeighbourhoodDepthC and stops sending neighbourhood change.
|
||||
func (k *Kademlia) CloseNeighbourhoodDepthC() {
|
||||
k.lock.Lock()
|
||||
defer k.lock.Unlock()
|
||||
|
||||
if k.nDepthC != nil {
|
||||
close(k.nDepthC)
|
||||
k.nDepthC = nil
|
||||
}
|
||||
}
|
||||
|
||||
// sendNeighbourhoodDepthChange sends new neighbourhood depth to k.nDepth channel
|
||||
// if it is initialized.
|
||||
func (k *Kademlia) sendNeighbourhoodDepthChange() {
|
||||
|
|
@ -362,6 +374,18 @@ func (k *Kademlia) AddrCountC() <-chan int {
|
|||
return k.addrCountC
|
||||
}
|
||||
|
||||
// CloseAddrCountC closes the channel returned by
|
||||
// AddrCountC and stops sending address count change.
|
||||
func (k *Kademlia) CloseAddrCountC() {
|
||||
k.lock.Lock()
|
||||
defer k.lock.Unlock()
|
||||
|
||||
if k.addrCountC != nil {
|
||||
close(k.addrCountC)
|
||||
k.addrCountC = nil
|
||||
}
|
||||
}
|
||||
|
||||
// Off removes a peer from among live peers
|
||||
func (k *Kademlia) Off(p *Peer) {
|
||||
k.lock.Lock()
|
||||
|
|
|
|||
|
|
@ -409,6 +409,10 @@ func (r *Registry) Quit(peerId enode.ID, s Stream) error {
|
|||
}
|
||||
|
||||
func (r *Registry) Close() error {
|
||||
// Stop sending neighborhood depth change and address count
|
||||
// change from Kademlia that were initiated in NewRegistry constructor.
|
||||
r.delivery.kad.CloseNeighbourhoodDepthC()
|
||||
r.delivery.kad.CloseAddrCountC()
|
||||
close(r.close)
|
||||
return r.intervalsStore.Close()
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue