Trait darkfi::net::session::Session

source ·
pub trait Session: Sync {
    // Required methods
    fn p2p(&self) -> P2pPtr;
    fn type_id(&self) -> SessionBitFlag;

    // Provided methods
    fn register_channel<'life0, 'life1, 'async_trait>(
        &'life0 self,
        channel: ChannelPtr,
        executor: Arc<Executor<'life1>>
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
    fn perform_handshake_protocols<'life0, 'life1, 'async_trait>(
        &'life0 self,
        protocol_version: Arc<ProtocolVersion>,
        channel: ChannelPtr,
        executor: Arc<Executor<'life1>>
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Session trait. Defines methods that are used across sessions. Implements registering the channel and initializing the channel by performing a network handshake.

Required Methods§

source

fn p2p(&self) -> P2pPtr

Returns a pointer to the p2p network interface

source

fn type_id(&self) -> SessionBitFlag

Return the session bit flag for the session type

Provided Methods§

source

fn register_channel<'life0, 'life1, 'async_trait>( &'life0 self, channel: ChannelPtr, executor: Arc<Executor<'life1>> ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Registers a new channel with the session. Performs a network handshake and starts the channel. If we need to pass Self as an Arc we can do so like this:

pub trait MyTrait: Send + Sync {
    async fn foo(&self, self_: Arc<dyn MyTrait>) {}
}
source

fn perform_handshake_protocols<'life0, 'life1, 'async_trait>( &'life0 self, protocol_version: Arc<ProtocolVersion>, channel: ChannelPtr, executor: Arc<Executor<'life1>> ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Performs network handshake to initialize channel. Adds the channel to the list of connected channels, and prepares to remove the channel when a stop signal is received.

Implementors§