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}
36
37/// A connection lifecycle event fired when a QUIC peer connection opens or closes.
38#[derive(Debug, Clone, Serialize, Deserialize)]
39#[serde(rename_all = "camelCase")]
40pub struct ConnectionEvent {
41 /// Base32-encoded public key of the peer.
42 pub peer_id: String,
43 /// `true` when this is the first connection from the peer (0→1), `false` when the last one closes (1→0).
44 pub connected: bool,
45}
46
47/// Per-peer connection statistics.
48#[derive(Debug, Clone, Serialize, Deserialize)]
49pub struct PeerStats {
50 /// Whether the peer is connected via a relay server (vs direct).
51 pub relay: bool,
52 /// Active relay URL, if any.
53 pub relay_url: Option<String>,
54 /// All known paths to this peer.
55 pub paths: Vec<PathInfo>,
56 /// Round-trip time in milliseconds. `None` if no active QUIC connection is pooled.
57 pub rtt_ms: Option<f64>,
58 /// Total UDP bytes sent to this peer. `None` if no active QUIC connection is pooled.
59 pub bytes_sent: Option<u64>,
60 /// Total UDP bytes received from this peer. `None` if no active QUIC connection is pooled.
61 pub bytes_received: Option<u64>,
62 /// Total packets lost on the QUIC path. `None` if no active QUIC connection is pooled.
63 pub lost_packets: Option<u64>,
64 /// Total packets sent on the QUIC path. `None` if no active QUIC connection is pooled.
65 pub sent_packets: Option<u64>,
66 /// Current congestion window in bytes. `None` if no active QUIC connection is pooled.
67 pub congestion_window: Option<u64>,
68}
69
70/// Network path information for a single transport address.
71#[derive(Debug, Clone, Serialize, Deserialize)]
72pub struct PathInfo {
73 /// Whether this path goes through a relay server.
74 pub relay: bool,
75 /// The relay URL (if relay) or `ip:port` (if direct).
76 pub addr: String,
77 /// Whether this is the currently selected/active path.
78 pub active: bool,
79}