1use std::{fmt::Debug, net::SocketAddr, time::Instant};
2
3use bitfold_core::config::Config;
4
5use super::event_types::Action;
6
7pub trait SessionEventAddress {
9 fn address(&self) -> SocketAddr;
11}
12
13pub trait Session: Debug {
16 type SendEvent: Debug + SessionEventAddress;
18 type ReceiveEvent: Debug + SessionEventAddress;
20
21 fn create_session(config: &Config, address: SocketAddr, time: Instant) -> Self;
23
24 fn is_established(&self) -> bool;
26
27 fn should_drop(&mut self, time: Instant) -> (bool, Vec<Action<Self::ReceiveEvent>>);
29
30 fn process_packet(&mut self, payload: &[u8], time: Instant) -> Vec<Action<Self::ReceiveEvent>>;
32
33 fn process_event(
35 &mut self,
36 event: Self::SendEvent,
37 time: Instant,
38 ) -> Vec<Action<Self::ReceiveEvent>>;
39
40 fn update(&mut self, time: Instant) -> Vec<Action<Self::ReceiveEvent>>;
42}