Disconnecting / removing peers form the DHT and peerstore

Hi I have been banging my head against a wall with this now for a couple of days.

  • I have created a bootstrap node with DHT and peer discovery.

  • My peers are able to connect to the bootstrap node and discover more peers that they can connect to.

  • When I close / kill a peer I am unable to remove it form the peerStore or DHT.

  • From my other nodes and bootstrap node I am able to see that I am not connected to this peer anymore with

  • I I have tried to use the following to remove the peer

						err := myHost.Network().ClosePeer(peer.ID)
						if err != nil {
							fmt.Println("please handle me", err)

After this i am still able to see the peer in my peerStore and DHT/routing discovery

I have no idea what I am missing.

Remote peers stay in the routing table even if they go offline. The node doesn’t need to keep an open connection to all the remote peers that are in its routing table (it would be too much). It “refreshes” its routing table every 10 minutes.

A routing table “refresh” consists in probing all remote peers that are in the routing table, and verify that they are still online. If a remote peer fails to answer a probe during a refresh, it is evicted from the routing table.

So it is expected that a remote peer doesn’t immediately disappear from the routing table as soon as it goes offline, it should get flush within 10 minutes. However, myKdht.RoutingTable().RemovePeer(peer.ID) should remove the peer from the routing table (but not the peerstore though).

Thank you for the response.
What I am finding strange is that it is not getting removed routing table if I wait for 10+ minutes or try and remove it manually.
I am still able to pick it up via this here:

	peerChan, err := routingDiscovery.FindPeers(w.ctx, w.conf.Rendezvous)

When I have a bit of time I will post my code (a reduced version of it), this should be by tomorrow.

Why is this important to you? libp2p is designed to “loose” the peer information over time, gradually. It takes time for one peer to be “forgotten”.