Skip to main content

iroh_http_core/endpoint/
stats.rs

1//! Endpoint observability types — snapshots, events, peer statistics.
2
3use serde::{Deserialize, Serialize};
4
5/// Serialisable node address: node ID + relay and direct addresses.
6#[derive(Debug, Clone, Serialize, Deserialize)]
7pub struct NodeAddrInfo {
8    /// Base32-encoded public key.
9    pub id: String,
10    /// Relay URLs and/or `ip:port` direct addresses.
11    pub addrs: Vec<String>,
12}
13
14/// Endpoint-level observability snapshot.
15///
16/// Returned by [`super::IrohEndpoint::endpoint_stats`].  All counts are
17/// point-in-time reads and may change between calls.
18#[derive(Debug, Clone, Serialize, Deserialize, Default)]
19#[serde(rename_all = "camelCase")]
20pub struct EndpointStats {
21    /// Number of currently open body reader handles.
22    pub active_readers: usize,
23    /// Number of currently open body writer handles.
24    pub active_writers: usize,
25    /// Number of live QUIC sessions (WebTransport connections).
26    pub active_sessions: usize,
27    /// Total number of allocated (reader + writer + session + other) handles.
28    pub total_handles: usize,
29    /// Number of QUIC connections currently cached in the connection pool.
30    pub pool_size: usize,
31    /// Number of live QUIC connections accepted by the serve loop.
32    pub active_connections: usize,
33    /// Number of HTTP requests currently being processed.
34    pub active_requests: usize,
35    /// Number of live path-change subscriptions.
36    pub active_path_subscriptions: usize,
37    /// Number of live path-change watcher tasks.
38    pub active_path_watchers: usize,
39}
40
41/// A connection lifecycle event fired when a QUIC peer connection opens or closes.
42#[derive(Debug, Clone, Serialize, Deserialize)]
43#[serde(rename_all = "camelCase")]
44pub struct ConnectionEvent {
45    /// Base32-encoded public key of the peer.
46    pub peer_id: String,
47    /// `true` when this is the first connection from the peer (0→1), `false` when the last one closes (1→0).
48    pub connected: bool,
49}
50
51/// Per-peer connection statistics.
52#[derive(Debug, Clone, Serialize, Deserialize)]
53pub struct PeerStats {
54    /// Whether the peer is connected via a relay server (vs direct).
55    pub relay: bool,
56    /// Active relay URL, if any.
57    pub relay_url: Option<String>,
58    /// All known paths to this peer.
59    pub paths: Vec<PathInfo>,
60    /// Round-trip time in milliseconds.  `None` if no active QUIC connection is pooled.
61    pub rtt_ms: Option<f64>,
62    /// Total UDP bytes sent to this peer.  `None` if no active QUIC connection is pooled.
63    pub bytes_sent: Option<u64>,
64    /// Total UDP bytes received from this peer.  `None` if no active QUIC connection is pooled.
65    pub bytes_received: Option<u64>,
66    /// Total packets lost on the QUIC path.  `None` if no active QUIC connection is pooled.
67    pub lost_packets: Option<u64>,
68    /// Total packets sent on the QUIC path.  `None` if no active QUIC connection is pooled.
69    pub sent_packets: Option<u64>,
70    /// Current congestion window in bytes.  `None` if no active QUIC connection is pooled.
71    pub congestion_window: Option<u64>,
72}
73
74/// Network path information for a single transport address.
75#[derive(Debug, Clone, Serialize, Deserialize)]
76pub struct PathInfo {
77    /// Whether this path goes through a relay server.
78    pub relay: bool,
79    /// The relay URL (if relay) or `ip:port` (if direct).
80    pub addr: String,
81    /// Whether this is the currently selected/active path.
82    pub active: bool,
83}