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§

source

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.

source

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,

Remove one peer’s PeerInfo from the book indicated by peer_id.

source

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

source

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

source

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,

Fetch the PeerInfo indicated by peer_id.

source

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,

Reverse lookup PeerId by raddr

source

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.

source

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.

source

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,

Implementors§