1use std::{
2 net::SocketAddr,
3 time::{Duration, Instant},
4};
5
6use crate::protocol::handshake::Handshake;
7use crate::{SeqNumber, SocketID};
8
9#[derive(Clone, Debug)]
10pub struct Connection {
11 pub settings: ConnectionSettings,
12 pub handshake: Handshake,
13}
14
15#[derive(Debug, Clone, Copy)]
16pub struct ConnectionSettings {
17 pub remote: SocketAddr,
19
20 pub remote_sockid: SocketID,
22
23 pub local_sockid: SocketID,
25
26 pub socket_start_time: Instant,
28
29 pub init_seq_num: SeqNumber,
31
32 pub max_packet_size: u32,
34
35 pub max_flow_size: u32,
37
38 pub tsbpd_latency: Duration,
42}
43
44impl ConnectionSettings {
45 pub fn get_timestamp(&self, at: Instant) -> i32 {
47 let elapsed = at - self.socket_start_time;
48
49 elapsed.as_micros() as i32 }
51
52 pub fn get_timestamp_now(&self) -> i32 {
54 self.get_timestamp(Instant::now())
55 }
56}