1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
use std::{
net::SocketAddr,
time::{Duration, Instant},
};
use crate::protocol::handshake::Handshake;
use crate::{crypto::CryptoManager, SeqNumber, SocketID};
#[derive(Clone, Debug)]
pub struct Connection {
pub settings: ConnectionSettings,
pub handshake: Handshake,
}
#[derive(Debug, Clone)]
pub struct ConnectionSettings {
pub remote: SocketAddr,
pub remote_sockid: SocketID,
pub local_sockid: SocketID,
pub socket_start_time: Instant,
pub init_send_seq_num: SeqNumber,
pub init_recv_seq_num: SeqNumber,
pub max_packet_size: u32,
pub max_flow_size: u32,
pub send_tsbpd_latency: Duration,
pub recv_tsbpd_latency: Duration,
pub crypto_manager: Option<CryptoManager>,
pub stream_id: Option<String>,
}
impl ConnectionSettings {
pub fn get_timestamp(&self, at: Instant) -> i32 {
let elapsed = at - self.socket_start_time;
elapsed.as_micros() as i32
}
pub fn get_timestamp_now(&self) -> i32 {
self.get_timestamp(Instant::now())
}
}