Files
tsunagi/vendor/iroh/src/tls/name.rs
T
Aleksandr Bogomiakov 2b0c938487 Bound iroh path retries to prevent multi-connection OOM
A long-running rc.33 daemon reached OOM with roughly 22 GiB resident and
24 GiB swapped. Live inspection found 40 GiB and 10/20 GiB anonymous
container mappings; the active worker stack and tracing metadata identified
iroh's scheduled path-open retry loop. In iroh 1.2.0 every failed connection
requeues the same path, while each retry visits every connection again.
Separate control and data connections multiply the queue geometrically.

Vendor the published iroh 1.2.0 source and select it with a workspace Cargo
patch. Deduplicate retry admission and cap distinct pending paths at 64,
evicting the oldest before inserting a new candidate. Keep the current and
next retry batches bounded without combining control/data connections or
changing wire protocols, identity derivation, authentication or state.
Document source provenance, the live evidence and removal conditions.
Upstream PR 4551 merged on October 6, but inspection of the official 1.3.0
crate still shows the unconditional enqueue, so that upgrade alone is not
a fix. No version bump, release tag or installed-service change.

The default workspace suite includes the exact vendored admission module.
Three regressions failed with the original enqueue and pass with the fix:
repeated failures across connections, duplicate admission at capacity, and
10,000 distinct candidates with bounded length/capacity and FIFO eviction.
Transport integration tests continue using real endpoints and encryption.

Checks on Linux in nix develop:
- cargo fmt --all -- --check
- cargo clippy --locked --workspace --all-targets -- -D warnings
- cargo test --locked --workspace --all-targets, with only the inherited
  TSUNAGI_CONTROL_SOCKET removed from the test environment
- git diff --cached --check

Initial full-suite runs failed six DNS readiness checks because the inherited
system socket path overrode their temporary state directories. Clearing that
environment variable resolves those failures without changing application code.
Root/network-dependent ignored tests and other operating systems were not run.
2026-10-14 23:28:53 +01:00

68 lines
2.4 KiB
Rust

//! Implementation of encoding iroh EndpointIds as domain names.
//!
//! We used to send this name via SNI up until iroh version 1.0.3, but stopped doing so in
//! versions after that. It is now used only locally by the `ServerCertificateVerifier` and
//! to separate the buckets for 0-RTT session tickets.
//!
//! We used to use a constant "localhost" for the TLS server name - however, that affects
//! 0-RTT and would put all of the TLS session tickets we receive into the same bucket in
//! the TLS session ticket cache.
//! So we choose something that'd dependent on the EndpointId.
//! We cannot use hex to encode the EndpointId, as that'd encode to 64 characters, but we only
//! have 63 maximum per DNS subdomain. Base32 is the next best alternative.
//! We use the `.invalid` TLD, as that's specified (in RFC 2606) to never actually resolve
//! "for real", unlike `.localhost` which is allowed to resolve to `127.0.0.1`.
//! We also add "iroh" as a subdomain, although those 5 bytes might not be necessary.
//! We *could* decide to remove that indicator in the future likely without breakage.
use data_encoding::BASE32_DNSSEC;
use iroh_base::EndpointId;
pub(crate) fn encode(endpoint_id: EndpointId) -> String {
format!(
"{}.iroh.invalid",
BASE32_DNSSEC.encode(endpoint_id.as_bytes())
)
}
pub(crate) fn decode(name: &str) -> Option<EndpointId> {
let [base32_endpoint_id, "iroh", "invalid"] = name.split(".").collect::<Vec<_>>()[..] else {
return None;
};
EndpointId::from_bytes(
&BASE32_DNSSEC
.decode(base32_endpoint_id.as_bytes())
.ok()?
.try_into()
.ok()?,
)
.ok()
}
#[cfg(test)]
mod tests {
use iroh_base::SecretKey;
use rand::{RngExt, SeedableRng};
#[test]
fn test_roundtrip() {
let mut rng = rand_chacha::ChaCha8Rng::seed_from_u64(0u64);
let key = SecretKey::from_bytes(&rng.random());
let endpoint_id = key.public();
println!("{}", super::encode(endpoint_id));
assert_eq!(
Some(endpoint_id),
super::decode(&super::encode(endpoint_id))
);
}
#[test]
fn test_snapshot() {
let key = SecretKey::from_bytes(&[0; 32]);
assert_eq!(
super::encode(key.public()),
"7dl2ff6emqi2qol3l382krodedij45bn3nh479hqo14a32qpr8kg.iroh.invalid",
);
}
}