Skip to main content

fips_core/endpoint/
status.rs

1use crate::NodeAddr;
2use crate::node::{NodeEndpointPeer, NodeEndpointRelayStatus};
3
4/// Authenticated FIPS peer state visible to an embedded application.
5#[derive(Debug, Clone, PartialEq, Eq)]
6pub struct FipsEndpointPeer {
7    /// Peer Nostr public key.
8    pub npub: String,
9    /// Peer FIPS node address, derived from the public key and stable across npub encodings.
10    pub node_addr: NodeAddr,
11    /// Whether an authenticated link-layer peer is currently active.
12    pub connected: bool,
13    /// Current underlay transport address, when a link has authenticated.
14    pub transport_addr: Option<String>,
15    /// Current underlay transport kind, when known.
16    pub transport_type: Option<String>,
17    /// Authenticated link id.
18    pub link_id: u64,
19    /// Smoothed RTT in milliseconds, once measured by FIPS MMP.
20    pub srtt_ms: Option<u64>,
21    /// Age of the current SRTT sample in milliseconds.
22    pub srtt_age_ms: Option<u64>,
23    /// Link packets sent.
24    pub packets_sent: u64,
25    /// Link packets received.
26    pub packets_recv: u64,
27    /// Link bytes sent.
28    pub bytes_sent: u64,
29    /// Link bytes received.
30    pub bytes_recv: u64,
31    /// Whether a link-layer rekey is currently in progress.
32    pub rekey_in_progress: bool,
33    /// Whether this peer is draining an old key during rekey.
34    pub rekey_draining: bool,
35    /// Current link-layer key bit for active peers.
36    pub current_k_bit: Option<bool>,
37    /// Whether direct UDP probing is queued while this peer may still be
38    /// reachable through a fallback transport.
39    pub direct_probe_pending: bool,
40    /// Millisecond timestamp when the queued direct probe becomes eligible.
41    pub direct_probe_after_ms: Option<u64>,
42    /// Number of direct probe/retry attempts accumulated for this peer.
43    pub direct_probe_retry_count: u32,
44    /// Whether the queued direct probe is an unlimited auto-reconnect.
45    pub direct_probe_auto_reconnect: bool,
46    /// Millisecond timestamp when a bounded direct probe/retry entry expires.
47    pub direct_probe_expires_at_ms: Option<u64>,
48    /// Consecutive Nostr traversal failures recorded for this peer.
49    pub nostr_traversal_consecutive_failures: u32,
50    /// Whether Nostr traversal is currently cooling down for this peer.
51    pub nostr_traversal_in_cooldown: bool,
52    /// Millisecond timestamp when Nostr traversal cooldown ends.
53    pub nostr_traversal_cooldown_until_ms: Option<u64>,
54    /// Last observed Nostr timestamp skew in milliseconds for this peer.
55    pub nostr_traversal_last_observed_skew_ms: Option<i64>,
56}
57
58/// Live Nostr relay state visible to an embedded application.
59#[derive(Debug, Clone, PartialEq, Eq)]
60pub struct FipsEndpointRelayStatus {
61    pub url: String,
62    pub status: String,
63}
64
65impl From<NodeEndpointPeer> for FipsEndpointPeer {
66    fn from(peer: NodeEndpointPeer) -> Self {
67        Self {
68            npub: peer.npub,
69            node_addr: peer.node_addr,
70            connected: peer.connected,
71            transport_addr: peer.transport_addr,
72            transport_type: peer.transport_type,
73            link_id: peer.link_id,
74            srtt_ms: peer.srtt_ms,
75            srtt_age_ms: peer.srtt_age_ms,
76            packets_sent: peer.packets_sent,
77            packets_recv: peer.packets_recv,
78            bytes_sent: peer.bytes_sent,
79            bytes_recv: peer.bytes_recv,
80            rekey_in_progress: peer.rekey_in_progress,
81            rekey_draining: peer.rekey_draining,
82            current_k_bit: peer.current_k_bit,
83            direct_probe_pending: peer.direct_probe_pending,
84            direct_probe_after_ms: peer.direct_probe_after_ms,
85            direct_probe_retry_count: peer.direct_probe_retry_count,
86            direct_probe_auto_reconnect: peer.direct_probe_auto_reconnect,
87            direct_probe_expires_at_ms: peer.direct_probe_expires_at_ms,
88            nostr_traversal_consecutive_failures: peer.nostr_traversal_consecutive_failures,
89            nostr_traversal_in_cooldown: peer.nostr_traversal_in_cooldown,
90            nostr_traversal_cooldown_until_ms: peer.nostr_traversal_cooldown_until_ms,
91            nostr_traversal_last_observed_skew_ms: peer.nostr_traversal_last_observed_skew_ms,
92        }
93    }
94}
95
96impl From<NodeEndpointRelayStatus> for FipsEndpointRelayStatus {
97    fn from(relay: NodeEndpointRelayStatus) -> Self {
98        Self {
99            url: relay.url,
100            status: relay.status,
101        }
102    }
103}