diff --git a/docs/features/control-channel/README.md b/docs/features/control-channel/README.md index cc2eaf5..6d92126 100644 --- a/docs/features/control-channel/README.md +++ b/docs/features/control-channel/README.md @@ -50,15 +50,15 @@ No packet is interpreted here. - **Name resolution filters each address group on its own** (`SocketStuff.cs:928-944, 950, 989-1044`): `Resolver.addresses` runs the same control flow `StartNewTcpClient` does, not a filter over the union. - The `Name2IP` mappings are checked against the same-subnet rule alone, and - when that check fails Windows returns from `StartNewTcpClient` **before** - `Dns.GetHostEntry` is called (`:934-937, 950`) — so the name is not dialled - at all that round and we return `[]`. The DNS group is filtered by the - reverse lookup and then gets its own same-subnet check (`:1037-1040`); - failing it drops the DNS addresses only, leaving the mapped ones, which - Windows has already handed to `StartNewTcpClientThread` by then. Reverse- - lookup validation never applies to a user-supplied mapping - (`docs/protocol.md` §10.3 note 6). + The `Name2IP` mappings are checked against the same-subnet rule alone, + and when that check fails Windows returns from `StartNewTcpClient` + **before** `Dns.GetHostEntry` is called (`:934-937, 950`) — so the name + is not dialled at all that round and we return `[]`. The DNS group is + filtered by the reverse lookup and then gets its own same-subnet check + (`:1037-1040`); failing it drops the DNS addresses only, leaving the + mapped ones, which Windows has already handed to + `StartNewTcpClientThread` by then. The reverse lookup never applies to a + user-supplied mapping (`docs/protocol.md` §10.3 note 6). - **Keep one client per peer** (`SocketStuff.cs:1980-2004`): when a second connection to the same peer name reaches `.connected`, the later *client* connection is closed; inbound (server-side) connections @@ -92,9 +92,10 @@ No packet is interpreted here. reports input via `noteUserActivity()`, which is our `Event.RealInputEventCount++`, `InputHook.cs:223, 345`; `userActive` is then "the counter moved since the previous heartbeat", the test - `SendAwakeBeat` makes and re-records every time it runs, - `Common.cs:545-558` — not a sliding window around `now`), drains outboxes and - events, and detects the C2 "30 s silence while we are sending input" + `SendAwakeBeat` makes and re-records every time it runs + (`Common.cs:545-558`) — not a sliding window around `now`), drains + outboxes and events, and detects the C2 "30 s silence while we are + sending input" stall: if the connection the sink marked as `controlled` receives nothing for 30 s while packets are being forwarded to it, close it. - **`ChannelConfig`** (contracts C4) carries everything: local name, @@ -386,6 +387,71 @@ input event or pasteboard was touched): one that does not, `shortName` of `127.0.0.1`, and `addresses(...)` with `sameSubnetOnly` and `validateRemoteIP` on. All as specified. +### 2026-09-16 — dev (Opus), rework after QA verdict REWORK + +One commit per finding, plus a compliance pass. `tools/gates.sh` green on +the last of them; `xcrun swift-format format -i --recursive Sources +Package.swift` is a no-op on all four files. + +1. **`Resolver.addresses` now runs `StartNewTcpClient`'s control flow + instead of filtering the union.** The mapped (`Name2IP`) group gets the + same-subnet check on its own and, when it fails, the function returns + `[]` **without calling `lookup`** — Windows's `return` at + `SocketStuff.cs:934-937`, which is reached before `Dns.GetHostEntry` + (`:950`), so nothing is dialled for that name that round. The DNS group + is then filtered by the reverse lookup (`:989-1032`) and gets its own + same-subnet check (`:1037-1040`); failing it drops only the DNS + addresses, because by that point Windows has already handed the mapped + ones to `StartNewTcpClientThread` (`:941`). Both QA scenarios now match + Windows: a mapped address out of subnet dials nothing even if DNS has an + in-subnet address, and an out-of-subnet DNS address is no longer dialled + just because a mapped address passed. Documented in Assumptions (new + bullet) and `docs/protocol.md` §10.3 note 6, which now spells out the + two different failure modes. +2. **The id-collision check moved inside the `isOutbound` gate.** + `UpdateTcpSockets` runs the collision branch and the + keep-the-first-client branch as the two halves of one block gated by + `status == SocketStatus.Connected && tcp.IsClient` + (`SocketStuff.cs:1980-1981`), so a server-accepted socket reaches + neither; the port had the gate on the dedup half only. An inbound peer + announcing our id is now tolerated silently, as there. §10.3 note 3 said + only that the collision force-closes everything; it now states the + client-only gate and points at note 4's observation about the same gate. + The Assumptions bullet and the `DisconnectReason.idCollision` / + `channelDetectedIDCollision` doc comments say the same. +3. **`userActive` is `SendAwakeBeat`'s test, not a sliding window.** The + channel keeps the pair of counters Windows keeps: `noteUserActivity()` + increments `inputEventCount` (our `Event.RealInputEventCount++`, + `InputHook.cs:223, 345`) and the tick reports `inputEventCount != + beatInputEventCount`, re-recording the counter on its own heartbeat + boundary exactly as `SendAwakeBeat` re-records on its way out + (`Common.cs:545-558`). The boundary is the channel's, which is the one + global beat Windows's 100 ms timer runs for every socket at once + (`frmScreen.cs:565-575`); tracking it per connection would need + `Session` to say when it beat, and `Session` is another lane's file. + Comparing by count also means a single click 59 s before the beat is + still an `Awake`, which the old window would have dropped. The stale + §3.3 citation (`Common.cs:499-513, 662-676` — `SendHeartBeat` and + screen-capture code) is replaced by `Common.cs:542-559` with the + `Event.cs:51-55` / `InputHook.cs:223, 345` counter and the + `IsMyDesktopActive`/desktop conditions named. +4. **CLAUDE.md re-read of the four files.** Sizes 191/235/356/535 lines, + every function inside 10–50 (the two longest are `PeerConnection.init` + at 30 lines and `updateClients` at 28), + layering, the one-sentence responsibility test, no force-unwrap / + `try!` / `fatalError` / `precondition`, no logging anywhere in `MWBNet`, + no packet interpreted, no line over 110 columns. Three citations were + wrong and are fixed: `Common.SendByeBye` is `Common.cs:611-615`, and + `SkSend`'s stamp-and-fan-out is `:916-930` with the `Des == ID.ALL` + matrix test at `:922-930`. + +No file outside the lane's list was touched: the four `Sources/MWBNet` +files, this README, `docs/protocol.md` §3.3 and §10.3. No `MWBCore` file +was edited — finding 3 was answered entirely on the channel side for that +reason — and `TODO.md` needed no change (its §3 items were already +ticked). No listener was opened, no input event posted and no pasteboard +touched during this rework. + ## QA log ### 2026-09-16 — QA (Sonnet)