libp2p_peer_store/store.rs
1use std::{
2 fmt::Debug,
3 task::{Context, Poll},
4};
5
6use libp2p_core::{Multiaddr, PeerId};
7use libp2p_swarm::FromSwarm;
8
9/// A store that contains all observed addresses of peers.
10pub trait Store {
11 /// Event generated by the store and emitted to [`Swarm`](libp2p_swarm::Swarm).
12 /// [`Behaviour`](crate::Behaviour) cannot handle this event.
13 type Event: Debug + Send;
14
15 /// How this store handles events from [`Swarm`](libp2p_swarm::Swarm).
16 fn on_swarm_event(&mut self, event: &FromSwarm);
17
18 /// Get all stored addresses of the peer.
19 fn addresses_of_peer(&self, peer: &PeerId) -> Option<impl Iterator<Item = &Multiaddr>>;
20
21 /// Polls for things that the store should do.
22 /// The task should be waked up to emit events to [`Behaviour`](crate::Behaviour) and
23 /// [`Swarm`](libp2p_swarm::Swarm).
24 fn poll(&mut self, cx: &mut Context<'_>) -> Poll<Self::Event>;
25}