Make joining a network idempotent and shut down cleanly on every path
Running `tsunagi up` twice with the same arguments failed with "network ... is already active", and then dropped the iroh endpoint without closing it. A configured network is activated automatically at startup, so the second run found it already up. `join_network` is declarative — "be a member of this network" — so joining one that is already active now succeeds and changes nothing. `activate_network` stays strict for callers that specifically want to know whether an inactive network was started. The CLI now closes the agent on the error path too, and handles SIGTERM as well as Ctrl-C, so a service manager stopping the agent gets the same clean shutdown an interactive user does. Also documents the two lookups people conflate: resolving one endpoint's address is iroh's public pkarr/DNS service and works today, which is why `--peer <endpoint-id>` needs no address; finding who is in a network is this project's `NetworkDiscovery` and is still static bootstrap only. Notes in the README and the threat model that `n0` and `direct` publish this endpoint's addresses to a public third-party service. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -99,11 +99,11 @@ wireguard: tsunkkcp43lmdje on fd15:1d9e:fa21:f201:…/64 mtu 1100, 1/1 tunnel(s)
|
||||
|
||||
Notes:
|
||||
|
||||
- Only one side needs `--peer`; the link is bidirectional. Peer discovery
|
||||
beyond this manual bootstrap is future work.
|
||||
- Only one side needs `--peer`; the link is bidirectional.
|
||||
- The default `--transport n0` uses iroh's public address lookup and relays, so
|
||||
two machines behind NAT find each other. `--transport local` keeps everything
|
||||
on the local network.
|
||||
on the local network. See *How peers find each other* below — it is worth
|
||||
understanding what gets published.
|
||||
- Without `CAP_NET_ADMIN`, add `--no-tun`: the mesh, the data links and the
|
||||
WireGuard handshakes all still run and are visible in the status output, only
|
||||
traffic does not reach the operating system. That is the quickest way to
|
||||
@@ -179,6 +179,34 @@ async fn main() -> Result<()> {
|
||||
reaches the internet by accident. Opt into `DirectOnly` or `N0Defaults`
|
||||
explicitly.
|
||||
|
||||
## How peers find each other
|
||||
|
||||
Two different lookups are involved, and only one of them is this project's:
|
||||
|
||||
**1. Resolving one endpoint's address — iroh's, and it works today.**
|
||||
With `--transport n0` or `--transport direct`, iroh publishes a signed record
|
||||
of this endpoint's addresses, keyed by its endpoint id, to Number 0's public
|
||||
service (`dns.iroh.link`, over pkarr and DNS) and resolves other endpoints the
|
||||
same way. That is why `--peer <endpoint-id>` works with no address attached:
|
||||
iroh looks it up. None of that code is ours.
|
||||
|
||||
**2. Finding who is in a network — ours, and it is still manual.**
|
||||
`NetworkDiscovery` maps a secret-derived `DiscoveryKey` to a set of *candidate*
|
||||
members. Two backends exist: `StaticBootstrap` (what `--peer` feeds) and an
|
||||
in-memory one for tests. The planned Mainline DHT backend, which would let
|
||||
members find each other from the network secret alone, is **not implemented**.
|
||||
So today you bootstrap by passing one peer's id; after that the mesh is
|
||||
whatever those agents reach.
|
||||
|
||||
What this means in practice:
|
||||
|
||||
- With `n0` or `direct`, **your endpoint id and IP addresses are published to a
|
||||
public third-party service.** They are not secret, and the network secret is
|
||||
never published, but an observer of that service learns that your endpoint
|
||||
exists and where it is. `--transport local` publishes nothing.
|
||||
- A relay, when one is needed, sees the volume and timing of your traffic — not
|
||||
its contents.
|
||||
|
||||
## Storage
|
||||
|
||||
Two physically separate SQLite files, placed wherever the library's
|
||||
|
||||
Reference in New Issue
Block a user