[][src]Trait pea2pea::Messaging

pub trait Messaging: Pea2Pea where
    Self: Clone + Send + Sync + 'static, 
{ type Message: Send; pub fn read_message(
        &self,
        source: SocketAddr,
        buffer: &[u8]
    ) -> Result<Option<(Self::Message, usize)>>; pub fn enable_messaging(&self) { ... }
#[must_use] pub fn read_from_stream<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        conn_reader: &'life1 mut ConnectionReader,
        message_sender: &'life2 Sender<Self::Message>
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        'life1: 'async_trait,
        'life2: 'async_trait,
        Self: Sync + 'async_trait
, { ... }
#[must_use] pub fn process_message<'life0, 'async_trait>(
        &'life0 self,
        source: SocketAddr,
        message: Self::Message
    ) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
    where
        'life0: 'async_trait,
        Self: Sync + 'async_trait
, { ... } }

This protocol can be used to specify and enable messaging, i.e. handling of inbound messages and replying to them. If handshaking is enabled too, it goes into force only after the handshake has been concluded.

Associated Types

type Message: Send[src]

The final type of incoming messages.

Loading content...

Required methods

pub fn read_message(
    &self,
    source: SocketAddr,
    buffer: &[u8]
) -> Result<Option<(Self::Message, usize)>>
[src]

Reads a single inbound message from the given buffer; Ok(None) indicates that the message is incomplete, i.e. another read from the stream must be performed in order to produce the whole message. Alongside the message it returns the number of bytes it occupied in the buffer.

Loading content...

Provided methods

pub fn enable_messaging(&self)[src]

Prepares the node to receive messages and optionally respond to them.

#[must_use]pub fn read_from_stream<'life0, 'life1, 'life2, 'async_trait>(
    &'life0 self,
    conn_reader: &'life1 mut ConnectionReader,
    message_sender: &'life2 Sender<Self::Message>
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where
    'life0: 'async_trait,
    'life1: 'async_trait,
    'life2: 'async_trait,
    Self: Sync + 'async_trait, 
[src]

Performs a read from the stream. The default implementation is buffered; it sacrifices a bit of simplicity for better performance. A naive approach would be to read only the number of bytes expected for a single message (if all of them have a fixed size) or first the number of bytes expected for a header, and then the number of bytes of the payload, as specified by the header.

#[must_use]pub fn process_message<'life0, 'async_trait>(
    &'life0 self,
    source: SocketAddr,
    message: Self::Message
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>> where
    'life0: 'async_trait,
    Self: Sync + 'async_trait, 
[src]

Processes an inbound message. Can be used to update state, send replies etc.

Loading content...

Implementors

Loading content...