Skip to main content

prns_runtime/runtime/
rns_management.rs

1use alloc::string::String;
2use alloc::vec::Vec;
3
4use prns_core::interfaces::rns_management::{
5    RnsAnnounceRateEntry, RnsAnnounceRateTable, RnsInterfaceAccessCode, RnsInterfaceStats,
6    RnsInterfaceStatsEntry,
7};
8
9use super::node_introspection::{
10    logical_interface_inventory, AnnounceRateSnapshot, InterfaceInventoryEntry,
11};
12
13pub fn interface_stats(inventory: Vec<InterfaceInventoryEntry<String>>) -> RnsInterfaceStats {
14    RnsInterfaceStats::new(
15        logical_interface_inventory(inventory)
16            .into_iter()
17            .map(|entry| {
18                let access_code = entry.ifac.map(|access_code| {
19                    RnsInterfaceAccessCode::new(
20                        access_code.signature,
21                        access_code.size,
22                        access_code.network_name,
23                    )
24                });
25                RnsInterfaceStatsEntry::new(entry.name, entry.snapshot, access_code)
26            })
27            .collect(),
28    )
29}
30
31pub fn announce_rate_table(entries: Vec<AnnounceRateSnapshot>) -> RnsAnnounceRateTable {
32    RnsAnnounceRateTable::new(
33        entries
34            .into_iter()
35            .map(|entry| {
36                RnsAnnounceRateEntry::new(
37                    entry.destination,
38                    entry.last_allowed_announce_at,
39                    entry.blocked_until,
40                    entry.rate_violations,
41                    entry.observed_at,
42                )
43            })
44            .collect(),
45    )
46}