session-matrix: protocol.md 10.2 — handshake ids, Hi, cadence, matrix search quirks

This commit is contained in:
lucio committed 2026-09-16 00:39:45 -07:00
1 parent 8d61347218
commit 0e826d3b8f
1 file changed
+64
+64
View File
@@ -504,3 +504,67 @@ sees them. One subsection per lane, appended, never rewritten.
8. **The 48-byte clipboard chunk starts at offset 16**, i.e.
`PACKAGE_SIZE_EX - DATA_SIZE` (`Clipboard.cs:46, 274`), and the last chunk
is zero-filled by clearing the whole buffer first (`Clipboard.cs:281`).
### 10.2 session-matrix (2026-09-16)
1. **A `Handshake` packet's `Id`, `Src` and `Des` are random.** The whole
64-byte buffer starts as `RandomNumberGenerator.GetBytes(PACKAGE_SIZE_EX)`
(`SocketStuff.cs:1269-1270`) and only `Type` and `MachineName` are written
over it. `TcpSend` fills `Src` **only when it is `ID.NONE`**
(`SocketStuff.cs:666-669`) and never touches `Id` — only `SkSend` sequences
(`Common.cs:916`). A receiver must therefore not learn the peer's id from a
`Handshake`: it comes from the `HandshakeAck`, whose `Src` is explicitly
cleared to `NONE` before the reply is sent (`:1374`) so that `TcpSend` fills
in the real one.
2. **`Hi (2)` is never processed by the receiver.** `TestSend` builds a zeroed
`DATA` and sends it through `TcpSend`, so its `Id` stays 0
(`Common.cs:826-836`); the dedup ring is a zero-filled `int[50]`
(`Receiver.cs:31`), so id 0 matches on the very first comparison and
`PreProcess` drops the packet (`:66-73`). `Hi` is purely a *write* probe —
its value is the exception `TcpSend` throws when the socket is gone. It is
not a round trip, and nothing should be built on top of receiving one.
3. **The heartbeat cadence is a modulo on a 100 ms tick that starts at 21.**
`count` is initialised to 21 (`frmScreen.cs:299`) and the guard is
`count % 600 == 0 && (BlockScreenSaver || count % 3000 == 0)`
(`frmScreen.cs:565-570`) — 60 s with `BlockScreenSaverOnOtherMachines` on,
300 s off. `SendAwakeBeat` then picks `Awake` over `Heartbeat` only when the
setting is on *and* `RealInputEventCount` moved since the last beat
(`Common.cs:545-556`).
4. **`HEARTBEAT_TIMEOUT` is 25 minutes, not 30.** `1500000` ms
(`MachineStuff.cs:32`); the comment next to it says 30. A machine is also
alive regardless of the timeout while a socket to it is up
(`MachinePool.cs:304-307`), and `IsConnectedTo` answers yes for the local
machine's own id without looking at any socket (`Common.cs:852-855`) — which
is what keeps the local slot from being blanked out of `LiveMachineMatrix`.
5. **The two-row neighbour search stops at the first matching arm; the one-row
search does not.** Each two-row arm is an `else if` on
`current == mc[from] && mc[to] is non-empty` (`MachineStuff.cs:346-378`), so
an arm that matches but whose target has no id ends the search — no
fall-through. The one-row loops instead `break` only on success
(`:312-323`), so they step over a named-but-unresolvable slot. Both are
ported as they are.
6. **`MoveDown` is written as two if-chains, `MoveUp` as one.** `MoveUp`
(`:556-587`) is a single `else if` chain; `MoveDown` (`:625-657`) runs the
straight arms and then the wrap arms as a separate statement, so a wrap arm
can overwrite an answer a straight arm already gave. Observable only when one
name occupies two slots. Similarly, `MoveRight` scans slots ascending for the
current machine and `MoveLeft` descending (`:308, 448`).
7. **`ConvertToUniversalValue` does not convert (0, 0).** The guard is
`if (!p.IsEmpty)` (`MachineStuff.cs:183`) and `Point.IsEmpty` means exactly
`X == 0 && Y == 0`, so a point on the origin is passed through unscaled. The
same value is also the "no switch" sentinel returned by
`MoveToMyNeighbourIfNeeded`, so on Windows a jump that legitimately lands on
the origin is indistinguishable from "stay put". The port keeps the
conversion quirk (the bytes are what matters) but not the sentinel: it
returns an optional `Jump`.
8. **An empty `MachinePool` serialises to five fields, not four.**
`SerializedAsString` joins the machines it has and then appends `",:"` once
per empty slot (`MachinePool.cs:292-299`), so zero machines give
`",:,:,:,:"` while the documented default is `":,:,:,:"`. The parser splits
on commas and reads only the first four fields (`MachinePoolHelpers.cs:31`),
so both load identically.
9. **A disconnected machine is back-dated, not removed.**
`SetMachineDisconnected` clamps the timestamp to
`now - HEARTBEAT_TIMEOUT + 10 000 ms` (`MachinePool.cs:111-122`), so the
machine keeps its pool slot and its matrix position and comes back to life on
the next heartbeat without any renegotiation.