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    /// Last outbound end-to-end session route: `direct` when the first hop was
38    /// the destination peer, `fallback` when traffic went through another peer.
39    pub last_outbound_route: Option<String>,
40    /// Whether direct UDP probing is queued while this peer may still be
41    /// reachable through a fallback transport.
42    pub direct_probe_pending: bool,
43    /// Millisecond timestamp when the queued direct probe becomes eligible.
44    pub direct_probe_after_ms: Option<u64>,
45    /// Number of direct probe/retry attempts accumulated for this peer.
46    pub direct_probe_retry_count: u32,
47    /// Whether the queued direct probe is an unlimited auto-reconnect.
48    pub direct_probe_auto_reconnect: bool,
49    /// Millisecond timestamp when a bounded direct probe/retry entry expires.
50    pub direct_probe_expires_at_ms: Option<u64>,
51    /// Consecutive Nostr traversal failures recorded for this peer.
52    pub nostr_traversal_consecutive_failures: u32,
53    /// Whether Nostr traversal is currently cooling down for this peer.
54    pub nostr_traversal_in_cooldown: bool,
55    /// Millisecond timestamp when Nostr traversal cooldown ends.
56    pub nostr_traversal_cooldown_until_ms: Option<u64>,
57    /// Last observed Nostr timestamp skew in milliseconds for this peer.
58    pub nostr_traversal_last_observed_skew_ms: Option<i64>,
59}
60
61/// Live Nostr relay state visible to an embedded application.
62#[derive(Debug, Clone, PartialEq, Eq)]
63pub struct FipsEndpointRelayStatus {
64    pub url: String,
65    pub status: String,
66}
67
68impl From<NodeEndpointPeer> for FipsEndpointPeer {
69    fn from(peer: NodeEndpointPeer) -> Self {
70        Self {
71            npub: peer.npub,
72            node_addr: peer.node_addr,
73            connected: peer.connected,
74            transport_addr: peer.transport_addr,
75            transport_type: peer.transport_type,
76            link_id: peer.link_id,
77            srtt_ms: peer.srtt_ms,
78            srtt_age_ms: peer.srtt_age_ms,
79            packets_sent: peer.packets_sent,
80            packets_recv: peer.packets_recv,
81            bytes_sent: peer.bytes_sent,
82            bytes_recv: peer.bytes_recv,
83            rekey_in_progress: peer.rekey_in_progress,
84            rekey_draining: peer.rekey_draining,
85            current_k_bit: peer.current_k_bit,
86            last_outbound_route: peer.last_outbound_route,
87            direct_probe_pending: peer.direct_probe_pending,
88            direct_probe_after_ms: peer.direct_probe_after_ms,
89            direct_probe_retry_count: peer.direct_probe_retry_count,
90            direct_probe_auto_reconnect: peer.direct_probe_auto_reconnect,
91            direct_probe_expires_at_ms: peer.direct_probe_expires_at_ms,
92            nostr_traversal_consecutive_failures: peer.nostr_traversal_consecutive_failures,
93            nostr_traversal_in_cooldown: peer.nostr_traversal_in_cooldown,
94            nostr_traversal_cooldown_until_ms: peer.nostr_traversal_cooldown_until_ms,
95            nostr_traversal_last_observed_skew_ms: peer.nostr_traversal_last_observed_skew_ms,
96        }
97    }
98}
99
100impl From<NodeEndpointRelayStatus> for FipsEndpointRelayStatus {
101    fn from(relay: NodeEndpointRelayStatus) -> Self {
102        Self {
103            url: relay.url,
104            status: relay.status,
105        }
106    }
107}