go-libp2p icon indicating copy to clipboard operation
go-libp2p copied to clipboard

`peerstore.AddAddrs(..., ttl)` is very difficult to use correctly

Open sukunrt opened this issue 8 months ago • 0 comments
trafficstars

When users do AddAddrs(..., TTL) they want the TTL to count after the peer disconnects, not immediately after setting the TTL.

What happens instead is that the TTL is almost always discarded because identify has set a much higher TTL for the same addresses. This TTL ofcourse is just a marker value which means remove these on disconnection. So the addresses are actually removed well before TTL if the peer disconnects soon after the call to AddAddrs.

The suggested solution for users is to use their own address book and not share the libp2p host's address book. This helps in most of the cases, but the majority of the users would still prefer expiring addresses TTL after disconnection not from the time of calling.

Note: This is similar to what @MarcoPolo suggested here: https://github.com/libp2p/go-libp2p/issues/2355#issuecomment-2259499552 I'm proposing that we do this for addresses as well, not just protocols.

For the most recent misuse of the API: https://github.com/libp2p/go-libp2p-kad-dht/pull/1053#discussion_r1973770110

sukunrt avatar Feb 28 '25 15:02 sukunrt