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
mod connection_id;
pub use connection_id::*;
mod local_cid;
pub use local_cid::*;
mod remote_cid;
pub use remote_cid::*;
use crate::role::Role;
/// When issuing a CID to the peer, be careful not to duplicate
/// other local connection IDs, as this will cause routing conflicts.
pub trait GenUniqueCid {
/// Generate a unique connection ID.
#[must_use]
fn gen_unique_cid(&self) -> ConnectionId;
}
pub trait RetireCid {
/// Retire a connection ID.
fn retire_cid(&self, cid: ConnectionId);
}
/// Connection ID registry.
///
/// - `local` represents the management of connection IDs issued by me to peer,
/// - `remote` represents the reception of connection IDs issued by peer,
/// which will be used by the path.
#[derive(Debug, Clone)]
pub struct Registry<LOCAL, REMOTE> {
pub local: LOCAL,
pub remote: REMOTE,
role: Role,
origin_dcid: ConnectionId,
}
impl<LOCAL, REMOTE> Registry<LOCAL, REMOTE> {
/// Create a new connection ID registry.
pub fn new(role: Role, origin_dcid: ConnectionId, local: LOCAL, remote: REMOTE) -> Self {
Self {
role,
origin_dcid,
local,
remote,
}
}
pub fn role(&self) -> Role {
self.role
}
pub fn origin_dcid(&self) -> ConnectionId {
self.origin_dcid
}
}