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§
Sourcetype SendEvent: Debug + SessionEventAddress
type SendEvent: Debug + SessionEventAddress
Defines a user event type.
Sourcetype ReceiveEvent: Debug + SessionEventAddress
type ReceiveEvent: Debug + SessionEventAddress
Defines a session event type.
Required Methods§
Sourcefn create_session(config: &Config, address: SocketAddr, time: Instant) -> Self
fn create_session(config: &Config, address: SocketAddr, time: Instant) -> Self
Creates new session and initialize it.
Sourcefn is_established(&self) -> bool
fn is_established(&self) -> bool
Sessions are considered established once they have both had a send and a receive.
Sourcefn should_drop(
&mut self,
time: Instant,
) -> (bool, Vec<Action<Self::ReceiveEvent>>)
fn should_drop( &mut self, time: Instant, ) -> (bool, Vec<Action<Self::ReceiveEvent>>)
Determines if the session should be dropped due to its state.
Sourcefn process_packet(
&mut self,
payload: &[u8],
time: Instant,
) -> Vec<Action<Self::ReceiveEvent>>
fn process_packet( &mut self, payload: &[u8], time: Instant, ) -> Vec<Action<Self::ReceiveEvent>>
Processes a received packet: parse it and emit an event.
Sourcefn process_event(
&mut self,
event: Self::SendEvent,
time: Instant,
) -> Vec<Action<Self::ReceiveEvent>>
fn process_event( &mut self, event: Self::SendEvent, time: Instant, ) -> Vec<Action<Self::ReceiveEvent>>
Processes a received event and send a packet.
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.