RFC: Identify
should remember discovered peers and assist in peer discovery using addresses_of_peer
#2216
Description
While implementing an address book here, I realized that we might be able to achieve the same functionality by adjusting how our existing protocols work. In particular, not all of our discovery-like protocols are currently assisting in peer discovery via addresses_of_peer
. Identify
for example does not override addresses_of_peer
.
What do people think about changing that so that we remember the reported addresses of peers that we have discovered? I think the only issue here is that we potentially have an unbounded memory growth because there isn't really a natural event that we could leverage to clean-up old addresses.
Solutions I could think of:
- Use a LRU cache and simply cap its storage at some number of entries.
- Assign a TTL to each entry and have it expire automatically.
Ideally, Identify
would also react to dial failures and remove entries that it reported but which turned out to be useless.
Having Identify
remember reported addresses is particularly useful if:
- Node A knows about its own, externally reachable address
- Node B does not know about external addresses of node A
- Node A dials node B
- Node B learns via
/identify
about A's external addresses - The Connection between node A and B gets closed
If Identify
would remember the externally reachable addresses that have previously been identified, Node B would now be able to establish a connection to A by simply dialing its PeerId
.
Currently, users of rust-libp2p
have to actively handle IdentifyEvent
and add all reported addresses to some other NetworkBehaviour
that will report it as part of addresses_of_peer
later.