contactArbitraryPeer only if not already in peer list.

Remove nodes from Kademlia structure when appropriate.
This commit is contained in:
Kleissner
2021-03-16 15:55:13 +01:00
parent e8b53051f2
commit 81fd372b0a
2 changed files with 8 additions and 0 deletions

View File

@@ -195,6 +195,11 @@ func autoMulticastBroadcast() {
}
func contactArbitraryPeer(publicKey *btcec.PublicKey, ip net.IP, port uint16) {
// check first if peer is already in the list!
if peer := PeerlistLookup(publicKey); peer != nil {
return
}
packets, err := msgEncodeAnnouncement(true, true, nil, nil, nil)
if len(packets) == 0 || err != nil {
return

View File

@@ -112,6 +112,9 @@ func PeerlistRemove(peer *PeerInfo) {
peerlistMutex.Lock()
defer peerlistMutex.Unlock()
// remove from Kademlia
nodesDHT.RemoveNode(peer.NodeID)
delete(peerList, publicKey2Compressed(peer.PublicKey))
}