Trait xstack::peerbook_syscall::DriverPeerBook
source · pub trait DriverPeerBook: Sync + Send {
// Required methods
fn insert<'life0, 'async_trait>(
&'life0 self,
peer_info: PeerInfo,
) -> Pin<Box<dyn Future<Output = Result<Option<PeerInfo>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn remove<'life0, 'life1, 'async_trait>(
&'life0 self,
peer_id: &'life1 PeerId,
) -> Pin<Box<dyn Future<Output = Result<Option<PeerInfo>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn appear<'life0, 'life1, 'async_trait>(
&'life0 self,
peer_id: &'life1 PeerId,
timestamp: SystemTime,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn disappear<'life0, 'life1, 'async_trait>(
&'life0 self,
peer_id: &'life1 PeerId,
timestamp: SystemTime,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
peer_id: &'life1 PeerId,
) -> Pin<Box<dyn Future<Output = Result<Option<PeerInfo>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn listen_on<'life0, 'life1, 'async_trait>(
&'life0 self,
raddr: &'life1 Multiaddr,
) -> Pin<Box<dyn Future<Output = Result<Option<PeerId>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn len<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = usize> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn choose_peers<'life0, 'life1, 'async_trait>(
&'life0 self,
protocol_id: &'life1 str,
limits: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<PeerId>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn choose_nat_peers<'life0, 'async_trait>(
&'life0 self,
limits: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<Multiaddr>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}Expand description
The customize PeerBook must implement this trait.
The stabilization of async functions in traits in Rust 1.75 did not include support for using traits containing async functions as dyn Trait, so we use the async_trait crate to define this trait, to know how to implement the async trait, visit its documentation.
Required Methods§
sourcefn insert<'life0, 'async_trait>(
&'life0 self,
peer_info: PeerInfo,
) -> Pin<Box<dyn Future<Output = Result<Option<PeerInfo>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn insert<'life0, 'async_trait>(
&'life0 self,
peer_info: PeerInfo,
) -> Pin<Box<dyn Future<Output = Result<Option<PeerInfo>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Insert a new peer informations.
Returns an older version of the PeerInfo if existing.
sourcefn remove<'life0, 'life1, 'async_trait>(
&'life0 self,
peer_id: &'life1 PeerId,
) -> Pin<Box<dyn Future<Output = Result<Option<PeerInfo>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn remove<'life0, 'life1, 'async_trait>(
&'life0 self,
peer_id: &'life1 PeerId,
) -> Pin<Box<dyn Future<Output = Result<Option<PeerInfo>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
sourcefn appear<'life0, 'life1, 'async_trait>(
&'life0 self,
peer_id: &'life1 PeerId,
timestamp: SystemTime,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn appear<'life0, 'life1, 'async_trait>(
&'life0 self,
peer_id: &'life1 PeerId,
timestamp: SystemTime,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Call this function when the peer is connected.
when the peer is non-existent in the book, returns Error::PeerNotFound
sourcefn disappear<'life0, 'life1, 'async_trait>(
&'life0 self,
peer_id: &'life1 PeerId,
timestamp: SystemTime,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn disappear<'life0, 'life1, 'async_trait>(
&'life0 self,
peer_id: &'life1 PeerId,
timestamp: SystemTime,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Call this function when the peer is disconnected.
when the peer is non-existent in the book, returns Error::PeerNotFound
sourcefn get<'life0, 'life1, 'async_trait>(
&'life0 self,
peer_id: &'life1 PeerId,
) -> Pin<Box<dyn Future<Output = Result<Option<PeerInfo>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn get<'life0, 'life1, 'async_trait>(
&'life0 self,
peer_id: &'life1 PeerId,
) -> Pin<Box<dyn Future<Output = Result<Option<PeerInfo>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
sourcefn listen_on<'life0, 'life1, 'async_trait>(
&'life0 self,
raddr: &'life1 Multiaddr,
) -> Pin<Box<dyn Future<Output = Result<Option<PeerId>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn listen_on<'life0, 'life1, 'async_trait>(
&'life0 self,
raddr: &'life1 Multiaddr,
) -> Pin<Box<dyn Future<Output = Result<Option<PeerId>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
sourcefn len<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = usize> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn len<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = usize> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Returns the peer book size.
sourcefn choose_peers<'life0, 'life1, 'async_trait>(
&'life0 self,
protocol_id: &'life1 str,
limits: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<PeerId>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn choose_peers<'life0, 'life1, 'async_trait>(
&'life0 self,
protocol_id: &'life1 str,
limits: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<PeerId>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Randomly select peers by protoco_id.