-
Notifications
You must be signed in to change notification settings - Fork 991
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(peer-store): introduce libp2p-peer-store #5724
base: master
Are you sure you want to change the base?
Conversation
This is a very basic implementation, would love to hear more ideas on how to implement this! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for starting this effort @drHuangMHT!
If I understand the current implementation correctly, the purpose of this store is just to track connected peers, and explicitly added addresses. However, I think we have to keep in mind that protocols like kademlia or identify very frequently report all addresses that they learn as NewExternalAddrOfPeer
. So with the current MemoryStore
implementation, the store would grow unbounded with all of these addresses. I think there needs to be some GC strategy.
Also, after reading #4103 (comment), I think a peer store implementation could also do much more than just track explicitly added addresses, e.g.:
- track how valuable a know address is, by using infos about how the address info was received, if we connected to it already, etc
- implement a TTL for address records
- track other meta data for a peer, e.g. public key
I don't think this needs to be implemented in this PR. But I think we could forward more of the already present info to the Store
trait, so that a custom implementation can have more sophisticated logic.
misc/peer-store/src/store.rs
Outdated
/// Peers that are currently connected. | ||
connected_peers: HashSet<PeerId>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a case where using a HashSet<PeerId>
to track connected peers is unsuitable for a specific use case? If now, how about moving this into the Behavior
, so that the Store
only concerns the "address-book" part of this behavior?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea of Store
trait is to allow on-disk storage, now I think about it, this info will be changing in real time so it should be kept in memory anyway. Will move it into the behaviour itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we have MemoryStore<T=()>
so that we are able to store data for peers (like scoring etc):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we have
MemoryStore<T=()>
so that we are able to store data for peers (like scoring etc):
MemoryStore
is more of a reference implementation, I don't think it is necessary to include a generic parameter for customization since we are maintaining its internals.
misc/peer-store/src/behaviour.rs
Outdated
_role_override: libp2p_core::Endpoint, | ||
_port_use: libp2p_core::transport::PortUse, | ||
) -> Result<libp2p_swarm::THandler<Self>, libp2p_swarm::ConnectionDenied> { | ||
self.store.on_peer_connect(&peer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might make more sense to remove this for FromSwarm
events since a connection could be denied later on (ie connection limits, banned peer, etc.), so that way the store isnt exactly cluttered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense. Will favor the swarm event.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we instead define Store::handle_* methods that are called here and in the other NetworkBehaviour::handle_*
so that it allows us to further manage our peers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we instead define Store::handle_* methods that are called here and in the other
NetworkBehaviour::handle_*
so that it allows us to further manage our peers?
What are those specifically? The store no longer record connected peers.
misc/peer-store/src/store.rs
Outdated
/// - contains all observed addresses of peers; | ||
pub trait Store { | ||
/// Called when a peer connects. | ||
fn on_peer_connect(&mut self, peer: &PeerId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we are tracking peer connections too, should we also keep tabs on the ConnectionId
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can, but how to store it? I think there can be multiple connections from a single peer, no?
simplify Store trait, don't report conencted unless confirmed by swarm event
Oops that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for starting this @drHuangMHT, already looking good! left some notes to allow further customization.
cc @elenaf9
[package] | ||
name = "libp2p-peer-store" | ||
version = "0.1.0" | ||
edition = "2021" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can add yourself as the author here :)
misc/peer-store/src/store.rs
Outdated
/// Peers that are currently connected. | ||
connected_peers: HashSet<PeerId>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we have MemoryStore<T=()>
so that we are able to store data for peers (like scoring etc):
misc/peer-store/src/behaviour.rs
Outdated
_role_override: libp2p_core::Endpoint, | ||
_port_use: libp2p_core::transport::PortUse, | ||
) -> Result<libp2p_swarm::THandler<Self>, libp2p_swarm::ConnectionDenied> { | ||
self.store.on_peer_connect(&peer); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we instead define Store::handle_* methods that are called here and in the other NetworkBehaviour::handle_*
so that it allows us to further manage our peers?
Store now handles FromSwarm directly; rename some on_* methods; allow removing address; update records on FromSwarm::ConnectionEstablished
This can get very complicated very soon, for example how to record the activitiy on the address(there will be some overhead) and how to make it machine-readable(scoring system). The discussion will be quite lengthy.
I didn't see a good way to implement TTL(garbage collect) for records, any pointer?
I don't see the remote public key being available through swarm itself, be it in the form of |
Description
Introduce
libp2p-peer-store
for a peer store implementation.Related: #4103
Notes & open questions
Change checklist