status shows each home relay: connected, down with the error, or denied

iroh 1.3's home_relay_status, on GlobalStatus as relays (absent when
empty, so older clients parse it). The thing we lacked when fetches
timed out: whether this daemon can be reached through a relay at all.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
Bendik Aagaard Lynghaug
2026-10-03 14:08:41 +02:00
co-authored by Claude Fable 5.1
parent 7916e59acb
commit 7322812524
4 changed files with 57 additions and 1 deletions
+30
View File
@@ -324,6 +324,27 @@ pub struct GlobalStatus {
pub pins: u64,
/// Number of connected trusted peers.
pub connected_peers: u64,
/// The home relays this endpoint uses and how each is doing. Empty
/// when relays are off (LAN-only) or on a daemon before 0.1.10.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub relays: Vec<RelayInfo>,
}
/// One home relay's connection state (iroh's `home_relay_status`).
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct RelayInfo {
/// The relay URL.
pub url: String,
/// Whether the endpoint holds a connection to it right now.
pub connected: bool,
/// The most recent connection error, when not connected and an
/// attempt has failed; for a person to read, not to match on.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub last_error: Option<String>,
/// The relay's reason when it denied this endpoint's authentication:
/// the one failure retrying will not cure.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub auth_denied: Option<String>,
}
/// Status of one hash.
@@ -478,4 +499,13 @@ mod tests {
_ => panic!("wrong variant"),
}
}
#[test]
fn a_status_from_before_relays_still_parses() {
let old = r#"{"version":"0.1.9","protocol":2,"store_path":"/s","pins":1,"connected_peers":0}"#;
let status: GlobalStatus = serde_json::from_str(old).unwrap();
assert!(status.relays.is_empty());
let back = serde_json::to_string(&status).unwrap();
assert!(!back.contains("relays"), "empty stays absent for old clients: {back}");
}
}