Session

Trait Session 

Source
pub trait Session: Debug {
    type SendEvent: Debug + SessionEventAddress;
    type ReceiveEvent: Debug + SessionEventAddress;

    // Required methods
    fn create_session(
        config: &Config,
        address: SocketAddr,
        time: Instant,
    ) -> Self;
    fn is_established(&self) -> bool;
    fn should_drop(
        &mut self,
        time: Instant,
    ) -> (bool, Vec<Action<Self::ReceiveEvent>>);
    fn process_packet(
        &mut self,
        payload: &[u8],
        time: Instant,
    ) -> Vec<Action<Self::ReceiveEvent>>;
    fn process_event(
        &mut self,
        event: Self::SendEvent,
        time: Instant,
    ) -> Vec<Action<Self::ReceiveEvent>>;
    fn update(&mut self, time: Instant) -> Vec<Action<Self::ReceiveEvent>>;
}
Expand description

Manages the lifecycle and state of a peer session. Defines a type of Send and Receive events used by a session.

Required Associated Types§

Source

type SendEvent: Debug + SessionEventAddress

Defines a user event type.

Source

type ReceiveEvent: Debug + SessionEventAddress

Defines a session event type.

Required Methods§

Source

fn create_session(config: &Config, address: SocketAddr, time: Instant) -> Self

Creates new session and initialize it.

Source

fn is_established(&self) -> bool

Sessions are considered established once they have both had a send and a receive.

Source

fn should_drop( &mut self, time: Instant, ) -> (bool, Vec<Action<Self::ReceiveEvent>>)

Determines if the session should be dropped due to its state.

Source

fn process_packet( &mut self, payload: &[u8], time: Instant, ) -> Vec<Action<Self::ReceiveEvent>>

Processes a received packet: parse it and emit an event.

Source

fn process_event( &mut self, event: Self::SendEvent, time: Instant, ) -> Vec<Action<Self::ReceiveEvent>>

Processes a received event and send a packet.

Source

fn update(&mut self, time: Instant) -> Vec<Action<Self::ReceiveEvent>>

Processes session-related tasks: resend dropped packets, send heartbeat, etc.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl Session for Peer

Source§

type SendEvent = Packet

Source§

type ReceiveEvent = SocketEvent

Source§

fn create_session(config: &Config, address: SocketAddr, time: Instant) -> Peer

Source§

fn is_established(&self) -> bool

Source§

fn should_drop( &mut self, time: Instant, ) -> (bool, Vec<Action<Self::ReceiveEvent>>)

Source§

fn process_packet( &mut self, payload: &[u8], time: Instant, ) -> Vec<Action<Self::ReceiveEvent>>

Source§

fn process_event( &mut self, event: Self::SendEvent, _time: Instant, ) -> Vec<Action<Self::ReceiveEvent>>

Source§

fn update(&mut self, time: Instant) -> Vec<Action<Self::ReceiveEvent>>

Implementors§