diff --git a/doc/2026-10-12T21-22-53Z_phase_7_connectivity/2026-10-12T21-22-53Z_phase_7_connectivity.md b/doc/2026-10-12T21-22-53Z_phase_7_connectivity/2026-10-12T21-22-53Z_phase_7_connectivity.md index b46a99717f..c67eeb5b7b 100644 --- a/doc/2026-10-12T21-22-53Z_phase_7_connectivity/2026-10-12T21-22-53Z_phase_7_connectivity.md +++ b/doc/2026-10-12T21-22-53Z_phase_7_connectivity/2026-10-12T21-22-53Z_phase_7_connectivity.md @@ -10,8 +10,13 @@ ## Steps -| Step | Track | Status | Commits | Tests | Notes | -| ---- | ----- | --------------------- | ------------------ | -------------------------------------- | -------------------------------------- | +| Step | Track | Status | Commits | Tests | Notes | +| ---- | ----- | --------------------- | ---------------------------- | ------------------------------------------------------- | ------------------------------------------- | +| P7.1 | relay | done | 80feb48b, ff844396 | relay_ops: 21 (14 red before the mode) | tunnel and vps modes in relay.kit.toml | +| P7.2 | - | blocked on owner's go | | | design only | +| P7.3 | dht | done (server-wide) | 1c91f76a, 5249c60a, 61f7e00c | dht_opt_in 3; dht unit 5; dht_testnet 2 (`dht` feature) | server-wide --dht on serve; publish enabled | +| P7.4 | - | none now | | | decision 13 | +| P7.5 | - | owner-blocked | | | accounts and networks | ## 2026-10-12T21:40:00Z Note: P7.1 relay kit modes @@ -22,8 +27,10 @@ - The S11 findings applied: `KillSignal=SIGINT` in both modes, `ConditionPathExists` for the config, metrics on loopback, no `secret_key`. Not applied: a systemd test (S11 did not run under systemd). - Design connectivity ยง4.2 step 4 now names the vps drop-in, so a VPS install gets the port capability. - Owner-blocked (P7.5): running either mode on a real host, with a Cloudflare Tunnel or a VPS, and checking `/ping`, `/generate_204`, and the systemd KillSignal behaviour. Not deployed here. -| P7.1 | relay | done | 80feb48b, ff844396 | relay_ops: 21 (14 red before the mode) | tunnel and vps modes in relay.kit.toml | -| P7.2 | - | blocked on owner's go | | | design only | -| P7.3 | dht | done (endpoint-wide) | 1c91f76a, 5249c60a, 61f7e00c | dht_opt_in 3 (red: E0432 at 1c91f76a); dht unit 4; dht_testnet 2 (`dht` feature) | see note 2026-10-12T21-36-10Z | -| P7.4 | - | none now | | | decision 13 | -| P7.5 | - | owner-blocked | | | accounts and networks | + +## 2026-10-12T22:05:00Z Note: P7.3 DHT server-wide config and publishing decisions + +- The owner decided: "dht can be server wide config. sure, publish. yes skip beekem for now." +- Scoping: `DhtPolicy::Server` (`from_server`) adds server-wide DHT enablement. `--dht` flag wired into `id serve` (mirrors `--no-mdns`). +- Publishing: `iroh-mainline-address-lookup` builder keeps publishing enabled (default). +- BeeKEM: P8.7 remains skipped as decided. diff --git a/pkgs/id/src/cli.rs b/pkgs/id/src/cli.rs index 6e78de0dda..4cdc5a8223 100644 --- a/pkgs/id/src/cli.rs +++ b/pkgs/id/src/cli.rs @@ -316,6 +316,13 @@ pub enum Command { /// environments where multicast traffic is blocked or unwanted. #[arg(long)] no_mdns: bool, + /// Enable mainline DHT address lookup and publishing. + /// + /// By default, the server does not use the mainline BitTorrent DHT + /// for address discovery. This flag enables DHT lookup and publishing + /// for the server's endpoint. + #[arg(long)] + dht: bool, /// Port for the Iroh QUIC endpoint (peer-to-peer protocol). /// /// By default, the OS assigns a random available port (0). @@ -2976,6 +2983,17 @@ mod tests { } } + #[test] + fn test_cli_parse_serve_dht() { + let cli = Cli::parse_from(["id", "serve", "--dht"]); + match cli.command { + Some(Command::Serve { dht, .. }) => { + assert!(dht); + } + _ => panic!("Expected Serve command"), + } + } + #[test] fn test_cli_parse_peers_no_mdns() { let cli = Cli::parse_from(["id", "peers", "--no-mdns"]); diff --git a/pkgs/id/src/commands/serve.rs b/pkgs/id/src/commands/serve.rs index 64999e39db..9f7d3e71bf 100644 --- a/pkgs/id/src/commands/serve.rs +++ b/pkgs/id/src/commands/serve.rs @@ -275,6 +275,8 @@ pub struct ServeOptions { pub replace_defaults: bool, /// Disable mDNS. pub no_mdns: bool, + /// Enable mainline DHT address lookup and publishing. + pub dht: bool, /// Iroh QUIC port (0 = random). pub iroh_port: u16, /// Address the web interface binds to. @@ -672,6 +674,7 @@ pub async fn cmd_serve(opts: ServeOptions) -> Result<()> { no_default_topic, replace_defaults, no_mdns, + dht, iroh_port, bind, web_token, @@ -724,6 +727,17 @@ pub async fn cmd_serve(opts: ServeOptions) -> Result<()> { if !no_mdns { builder = builder.address_lookup(MdnsAddressLookup::builder()); } + let dht_policy = crate::dht::DhtPolicy::from_server(dht); + #[cfg(feature = "dht")] + if dht_policy.is_on() { + builder = crate::dht::with_lookup(&dht_policy, builder, crate::dht::mainline()); + } + #[cfg(not(feature = "dht"))] + if dht_policy.is_on() { + warn!( + "--dht was requested, but `id` was compiled without the optional `dht` feature; DHT lookup is not active" + ); + } if iroh_port != 0 { builder = builder.bind_addr(std::net::SocketAddrV4::new( Ipv4Addr::UNSPECIFIED, diff --git a/pkgs/id/src/dht.rs b/pkgs/id/src/dht.rs index cfdf347051..8fa951c5d7 100644 --- a/pkgs/id/src/dht.rs +++ b/pkgs/id/src/dht.rs @@ -20,12 +20,19 @@ pub enum DhtPolicy { /// No DHT: no publish and no lookup. The default. #[default] Off, + /// The DHT is enabled as a server-wide setting. + Server, /// The DHT is on for the endpoint because these worlds opted in. Worlds /// that did not opt in share the endpoint, so they use the DHT too. Endpoint(BTreeSet), } impl DhtPolicy { + /// Server-wide DHT policy. + pub const fn from_server(enabled: bool) -> Self { + if enabled { Self::Server } else { Self::Off } + } + /// The policy for the worlds that opted in. With no world opted in, the /// DHT is off. pub fn from_worlds(opted_in: I) -> Self @@ -43,13 +50,13 @@ impl DhtPolicy { /// Whether the endpoint uses the DHT. pub const fn is_on(&self) -> bool { - matches!(self, Self::Endpoint(_)) + matches!(self, Self::Server | Self::Endpoint(_)) } - /// The worlds that opted in, in name order. Empty when the DHT is off. + /// The worlds that opted in, in name order. Empty when the DHT is off or server-wide. pub fn opted_in(&self) -> impl Iterator { let worlds = match self { - Self::Off => None, + Self::Off | Self::Server => None, Self::Endpoint(worlds) => Some(worlds), }; worlds.into_iter().flatten().map(String::as_str) @@ -90,6 +97,17 @@ mod tests { assert!(!DhtPolicy::default().is_on()); } + #[test] + fn test_server_wide_dht_policy() { + assert_eq!(DhtPolicy::from_server(false), DhtPolicy::Off); + assert!(!DhtPolicy::from_server(false).is_on()); + + let policy = DhtPolicy::from_server(true); + assert_eq!(policy, DhtPolicy::Server); + assert!(policy.is_on()); + assert_eq!(policy.opted_in().count(), 0); + } + #[test] fn test_no_opted_in_world_is_off() { let policy = DhtPolicy::from_worlds(Vec::::new()); diff --git a/pkgs/id/src/main.rs b/pkgs/id/src/main.rs index 09e7ebbd41..489a59c02e 100644 --- a/pkgs/id/src/main.rs +++ b/pkgs/id/src/main.rs @@ -159,6 +159,7 @@ async fn main() -> Result<()> { no_default_topic, replace_defaults, no_mdns, + dht, iroh_port, bind, web_token, @@ -199,6 +200,7 @@ async fn main() -> Result<()> { no_default_topic, replace_defaults, no_mdns, + dht, iroh_port, bind, web_token,