rns_core/transport/
tables.rs1use alloc::vec::Vec;
2
3use super::types::InterfaceId;
4
5#[derive(Debug, Clone)]
7pub struct PathEntry {
8 pub timestamp: f64,
9 pub next_hop: [u8; 16],
10 pub hops: u8,
11 pub expires: f64,
12 pub random_blobs: Vec<[u8; 10]>,
13 pub receiving_interface: InterfaceId,
14 pub packet_hash: [u8; 32],
15 pub announce_raw: Option<Vec<u8>>,
17}
18
19#[derive(Debug, Clone)]
21pub struct AnnounceEntry {
22 pub timestamp: f64,
23 pub retransmit_timeout: f64,
24 pub retries: u8,
25 pub received_from: [u8; 16],
26 pub hops: u8,
27 pub packet_raw: Vec<u8>,
28 pub packet_data: Vec<u8>,
29 pub destination_hash: [u8; 16],
30 pub context_flag: u8,
31 pub local_rebroadcasts: u8,
32 pub block_rebroadcasts: bool,
33 pub attached_interface: Option<InterfaceId>,
34}
35
36#[derive(Debug, Clone)]
38pub struct ReverseEntry {
39 pub receiving_interface: InterfaceId,
40 pub outbound_interface: InterfaceId,
41 pub timestamp: f64,
42}
43
44#[derive(Debug, Clone)]
46pub struct LinkEntry {
47 pub timestamp: f64,
48 pub next_hop_transport_id: [u8; 16],
49 pub next_hop_interface: InterfaceId,
50 pub remaining_hops: u8,
51 pub received_interface: InterfaceId,
52 pub taken_hops: u8,
53 pub destination_hash: [u8; 16],
54 pub validated: bool,
55 pub proof_timeout: f64,
56}
57
58#[derive(Debug, Clone)]
60pub struct RateEntry {
61 pub last: f64,
62 pub rate_violations: u32,
63 pub blocked_until: f64,
64 pub timestamps: Vec<f64>,
65}
66
67#[cfg(test)]
68mod tests {
69 use super::*;
70
71 #[test]
72 fn test_path_entry_creation() {
73 let entry = PathEntry {
74 timestamp: 1000.0,
75 next_hop: [0xAA; 16],
76 hops: 3,
77 expires: 2000.0,
78 random_blobs: Vec::new(),
79 receiving_interface: InterfaceId(1),
80 packet_hash: [0xBB; 32],
81 announce_raw: None,
82 };
83 assert_eq!(entry.hops, 3);
84 assert_eq!(entry.receiving_interface, InterfaceId(1));
85 }
86
87 #[test]
88 fn test_link_entry_creation() {
89 let entry = LinkEntry {
90 timestamp: 100.0,
91 next_hop_transport_id: [0x11; 16],
92 next_hop_interface: InterfaceId(2),
93 remaining_hops: 5,
94 received_interface: InterfaceId(3),
95 taken_hops: 2,
96 destination_hash: [0x22; 16],
97 validated: false,
98 proof_timeout: 200.0,
99 };
100 assert!(!entry.validated);
101 assert_eq!(entry.remaining_hops, 5);
102 }
103
104 #[test]
105 fn test_rate_entry_creation() {
106 let entry = RateEntry {
107 last: 50.0,
108 rate_violations: 0,
109 blocked_until: 0.0,
110 timestamps: Vec::new(),
111 };
112 assert_eq!(entry.rate_violations, 0);
113 }
114}