Remove bootstrapped peers from DHT

215 Views Asked by At

I am using golang-libp2p in my project where I am using Kadmelia DHT for peer discovery. I can access info of bootstrapped peers in the following manner.

import (
   "github.com/libp2p/go-libp2p/core/peer"
)

for _, peerAddr := range dht.DefaultBootstrapPeers {
    peerInfo, _ := peer.AddrInfoFromP2pAddr(peerAddr)

I can see as I keep adding new peers, peerInfo list keeps on increasing, even after I restart the program. I am looking for a method to prune/remove existing bootstrapped peers. I have seen a pull request that talks about this issue but it seems like the method has not been included in the library. The link to the issue here.

Is it possible to prune bootstrapped peers in the golang implementation?

1

There are 1 best solutions below

0
On

Are you trying to remove the bootstrap peer from the DHT routing table, or to disconnect it from the host?

If you want to remove a peer from the DHT routing table, you can use the RemovePeer(p peer.ID) function.

dht.RoutingTable().RemovePeer(peerid)

If you want to close the connection to a peer, you can try ClosePeer(peer.ID) and RemovePeer(peer.ID)

dht.host.Network().ClosePeer(peerid)
dht.host.Peerstore().RemovePeer(peerid)