Skip to content

Pair with IP: join.direct dials a computer name - #58

Merged
TheAnimatrix merged 6 commits into
mainfrom
direct-name-dial
Nov 30, 2026
Merged

TheAnimatrix merged 6 commits into
mainfrom
direct-name-dial

Conversation

@TheAnimatrix

@TheAnimatrix TheAnimatrix commented Nov 30, 2026 •

Copy link
Copy Markdown
Collaborator

Part of the Pair with IP rollout (mousse-agent/mousse#2079), second of three engine steps toward joining by computer name. Follows #52, which made addresses and pending records carry a name. join.direct now takes a name as well as an IP address. The joiner resolves the name, tries the addresses it gets in order, spends at most one code attempt per Connect, and keeps the address that answered as the owner route.

What changed

  • Dialling a name (mousse-net-io caller/direct.rs, wire.md 10.9 "Dialling a name").
    • A typed name goes through the caller's resolver: the existing SystemResolver, or a stub in tests via Caller::use_resolver.
    • Each distinct address it returns is tried in the operating system's order. The address policy is checked on every resolved socket address before that address is dialled, and forbidden ones are skipped. Skipped addresses don't count toward the DIRECT_NAME_ADDRESSES cap, so a reachable host listed after many refused addresses is still tried while the time budget lasts.
    • A name reaches exactly what a typed IP address reaches, because one policy decides both. IPv4 link-local (169.254/16) is dialled either way: that is how two computers on one cable with no DHCP reach each other. IPv6 link-local is refused either way.
    • A TCP failure, or a TLS failure before the host's HELLO, moves on to the next address. The first connection whose TLS succeeds becomes the flow's connection, and whatever happens on it ends that Connect. So a name with several addresses never runs more than one code attempt.
    • Resolving and all the tries share one time budget. Each try stays bounded by CONNECT_TIMEOUT_MS and HANDSHAKE_TIMEOUT_MS.
    • Between addresses the flow checks again for a stop, a cancel and a pause. A cancel while the name is still being resolved or tried ends the flow at once: the outstanding lookup or dial is dropped and the hold is released, so the same name and code can be tried again right away.
    • A far end showing the joiner's own key still ends the flow as "own device", as for a typed address; wire.md now says this explicitly.
    • A typed IP address is still a single try.
  • How a name dial can fail. DirectDialFailure::NotFound is new: the name did not resolve, or not within the budget. The helper reports it as not_found ("can't find that computer by name"), and the CLI says to try the IP address. A name whose addresses the policy all forbids is Forbidden, as for an IP address. In both cases nothing is sent and no attempt is spent. When the dial tried at least one allowed address, it reports what happened there ("not Mousse" over "unreachable"), never "forbidden" for an address it skipped.
  • Startup recovers records kept at a name. Pair with IP: typed addresses and pending records carry a name #52 left them on disk because that build could not dial a name; this removes that skip and its test.
  • Recovery of a record kept at a name:
    • resolves the name again, under the address policy as it is then;
    • stays pinned to the host key the code authenticated, so an address whose TLS shows another key is skipped like a failed one;
    • runs no code exchange.
  • What is kept after PAIRED. The I/O layer replaces DirectPaired::address with the socket address the verified connection reached (DirectAddress::from_socket, back from Pair with IP: typed addresses and pending records carry a name #52's cut, now with its caller; an IPv4-mapped address is kept as its IPv4 address), before the pin store and the Paired event see it. So the owner route the helper writes, through its existing fenced write path, is that IP address and port, never the name. For a typed IP address it is the same address as before.
  • Helper entry. typed_address now accepts <name>:<port> (lowercased; Pair with IP: typed addresses and pending records carry a name #52's rule still refuses a numeric spelling such as 0x7f000001). The policy is still checked at once for a typed IP address; for a name it is checked per resolved address when dialling. CLI help for join-direct shows the name form.
  • New limits (docs/limits.md):
    • MOUSSE_NET_DIRECT_NAME_DIAL_MS: default 20000, range 1000 to 120000. The whole name dial.
    • MOUSSE_NET_DIRECT_NAME_ADDRESSES: default 8, range 1 to 32. Allowed addresses dialled per name dial; refused ones don't count.
    • Like every other limit, an out-of-range value stops the helper at startup (docs/limits.md). Neither one is security-bound, so neither is clamped.
  • Docs: wire.md 10.9 (dialling a name; recovery resolves again; the reached address is kept), and docs/pair-with-ip-design.md §1.4 and the join.direct error list (not_found).

Tests

io direct_joiner.rs uses a stub resolver:

  • a_name_tries_its_addresses_in_order_and_spends_one_attempt: the name resolves to a closed port, a port that is not Mousse, the closed port again, the host, then the non-Mousse port again. The flow skips the failures, pairs with the host, keeps the record at the lowercased name, stores the host's socket address as the owner route, debits one attempt, resolves once, and connects to the non-Mousse port only once.
  • a_name_whose_first_host_refuses_the_code_tries_no_other: the first host's code doesn't match. The Connect ends there with one attempt spent, and a second host the name resolves to gets no connection.
  • refused_addresses_do_not_use_up_a_names_tries: more refused addresses than the cap come before the host, and the code still reaches it.
  • a_name_dial_reports_the_failure_of_an_address_it_tried: a closed port followed by a refused address reports "unreachable". A non-Mousse port, a closed port and a refused address report "not Mousse".
  • a_name_dials_what_a_typed_address_dials: 169.254.77.1 is dialled both typed and as a name's answer; fe80::1 and 192.0.2.1 are refused both ways.
  • a_cancel_during_a_slow_lookup_frees_the_lookup_at_once: with the lookup never answering, a cancel is confirmed, the flow ends at once, and the same name and code then reach the host.
  • a_cancel_landing_before_the_dial_starts_ends_the_flow_at_once: a debug-only pause point holds the driver after it read "connecting"; a cancel lands there, no lookup starts, and the same name and code then reach the host.
  • a_name_is_not_resolved_while_paused: while paused, the resolver is never asked.
  • a_name_that_resolves_to_nothing_dialable_sends_nothing: only forbidden addresses gives Forbidden; no answer gives NotFound. Neither debits an attempt.
  • a_recovery_at_a_name_resolves_again_and_takes_only_the_pinned_key: the code passes and PAIRED is lost. After a restart, the name resolves first to another Mousse host and then to the real one. The recovery resolves again, skips the other host at TLS (it never sees a request), pairs with the real host with no new attempt, and keeps the real host's address.

Helper app_pair_ip::a_typed_name_pairs_and_keeps_the_address_it_reached: join.direct with LocalHost:<port> pairs through the system resolver, and the peer's only owner address is the loopback address that answered.

Eight new must-fail controls in pair-with-ip.joiner-io:

  • direct-name-first-only: only the first resolved address is tried.
  • direct-name-kept-as-route: the typed name is kept as the owner route.
  • direct-name-cap-counts-forbidden: refused addresses count toward the cap.
  • direct-name-forbidden-wins: a refusal replaces the failure of an address tried before it.
  • direct-cancel-waits-for-dial: a cancel waits for the lookup to end.
  • direct-cancel-before-seen: a cancel published before the driver marks "connecting" seen is missed.
  • direct-name-resolved-while-paused: a name is resolved while paused.
  • direct-name-dial-duplicates: a repeated address is dialled again.

The existing direct-dial-unchecked also breaks the forbidden-name test.

Review fixes (round 1, reviews of 8eaafe5)

  • R1 (both), the cap hid a reachable host: addresses the policy refuses are now skipped as the answers are read and don't count toward MOUSSE_NET_DIRECT_NAME_ADDRESSES, so the cap only limits how many allowed addresses are dialled, and the shared time budget still bounds the whole dial. Test refused_addresses_do_not_use_up_a_names_tries (more refused answers than the cap, then the host); control direct-name-cap-counts-forbidden. Both reviewers suggested cutting the cap; it stays as a bound on how many hosts one name dial can touch, with refused answers no longer counting.
  • R2 (both), IPv4 link-local: a name reaches exactly what a typed IP address reaches, because one address policy decides both. Typed 169.254/16 is allowed today (two computers on one cable with no DHCP), so a name's 169.254 answer is dialled too; IPv6 link-local and documentation addresses are refused both ways. wire.md 10.9 now says so. Test a_name_dials_what_a_typed_address_dials pins it: it fails if names and typed addresses ever get different rules, and the existing direct-dial-unchecked control breaks its refused half.
  • R3 (both), busy after a cancel during a slow lookup: a cancel now ends the flow at once: the outstanding lookup or dial is dropped and the hold released, so the same name and code can Connect again right away. Test a_cancel_during_a_slow_lookup_frees_the_lookup_at_once (the resolver never answers); control direct-cancel-waits-for-dial.
  • R4 (both), a refusal overwrote a real failure: Forbidden is reported only when no allowed address was tried. Otherwise the failure of an address actually tried is kept, "not Mousse" over "unreachable". Test a_name_dial_reports_the_failure_of_an_address_it_tried; control direct-name-forbidden-wins.
  • Astra R5, own key: wire.md 10.9 now states the exception: a far end showing the joiner's own key ends the Connect as "own device", as for a typed address, rather than moving to the next answer.
  • Sol R5 / Astra R6, clamping: kept as range validation, the rule for every limit in docs/limits.md: an out-of-range value stops the helper at startup. Neither new limit is security-bound, so neither is clamped.
  • Sol R6 / Astra R7, weak fallback test: the in-order test now counts connections to the non-Mousse listener (dialled once although listed twice), and a_name_whose_first_host_refuses_the_code_tries_no_other covers a code refused on the first host: one attempt spent, the second host gets no connection.
  • Pause checks (found while fixing): a typed IP is again checked for a pause right before its dial and once TLS is up, and a name is also checked before it is resolved. The direct-contact-checked-once control still fails its test.

Review fixes (round 2, re-checks of 10cb1a3)

  • R3, a cancel in the window before the dial: the driver's wait for the flow to leave "connecting" now reads the flow's own state first, then after every change. A cancel published after the driver read "connecting" but before it marked that state seen ends the flow at once: no lookup starts, and the hold goes. A debug-only pause point (Caller::pause_direct_dials, compiled only outside the release profile) lets the new test a_cancel_landing_before_the_dial_starts_ends_the_flow_at_once land the cancel in exactly that window; it then checks that no lookup was made and that the same name and code reach the host right away. Control direct-cancel-before-seen.
  • Duplicate dial test: both copies of the non-Mousse address now come before the host, so dialling a repeated address again would be counted. Control direct-name-dial-duplicates.
  • Notes taken:
    • The rejected-proof test no longer holds the host's state lock while formatting a failure.
    • A name dial that runs out of time stops reading the answer, refused addresses included.
    • The link-local test checks the exact outcome: 169.254.x ends "unreachable" (dialled), fe80::1 and 192.0.2.1 "forbidden", for a typed IP and a name alike.
    • New test a_name_is_not_resolved_while_paused: while paused, a typed name is never looked up. Control direct-name-resolved-while-paused.

Checks run (Windows x64)

Head 5bda28a (on main at d5b17f0):

  • cargo fmt --all --check, cargo clippy --workspace --all-targets --all-features -- -D warnings: clean.
  • cargo test --workspace --no-fail-fast: all 69 test binaries pass. The known flake Flaky test: a stalled older keys exchange waits 20 s for peer.manifest under load #23 did not fail in this run (it failed in the run on 75904f8, and 1 of 3 times run alone there; this PR does not touch it).
  • wasm32 core build and vectors, second implementation (npm run check, npm test): pass.
  • mousse-check, every control failing as required:
    • phase0.core-vectors: 320 tests (wasm32: 291), 3 controls.
    • phase0.second-implementation: pass, 1 control.
    • pair-with-ip.joiner-io: 33 tests, 13 controls, including the eight new ones above.
    • pair-with-ip.sim (the pairing-direct sim drill): pass, 6 controls.
    • pair-with-ip.helper-units: 123 tests, 5 controls.
    • pair-with-ip.helper: 26 tests, 20 controls.
    • pair-with-ip.host-io: 26 tests, 9 controls.

…sses in order with one attempt, keep the address reached
… dial and once its TLS is up, as before; a name also before it is resolved
…d failure beats a refusal, and a cancel abandons a slow lookup at once

A name dials exactly what a typed IP address dials (IPv4 link-local included, IPv6 link-local refused), now pinned by a test. Tests also show each address is dialled once and that a host refusing the code ends the Connect with no other host dialled.
…s not missed; a paused name is not resolved; out of time ends the answer scan

The driver's wait for the flow to leave connecting reads the flow's own state first, so a cancel published before borrow_and_update ends the flow at once. A debug-only pause point lets a test land a cancel in exactly that window. Tests also pin that a repeated answer is dialled once, that IPv4 link-local ends unreachable (dialled), and that a paused name is never resolved.
@TheAnimatrix
TheAnimatrix merged commit d823b1e into main Nov 30, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant