session-matrix: Session cannot stamp an application packet (contracts C1)
Session.send(_:) is gone as a public entry point. Application traffic gets its Id once from the process-wide PacketSequencer and reaches each target connection through forward(_:), which never re-stamps; the per-connection stamp survives only as `private func originate(_:)` for the packets Windows also sends per connection — the handshake pair, heartbeats, Hi and ByeBye. Nothing outside the type can now sequence an application packet. README Assumptions and Handshakes say this is API-enforced rather than a convention. protocol.md gains §10.2 note 11: SkSend increments PackageID once before the socket loop (Common.cs:914) and hands the same DATA to every matching socket, which is exactly what makes the receiver's 50-entry replay ring collapse a peer pair's duplicate delivery. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
This commit is contained in:
1 parent
9252158bbc
commit
9980c685e2
3 files changed
+62
-27
No files matched your search
@@ -53,10 +53,15 @@ the Windows source again.
|
||||
`PackageID` setting and the app stores it back; this lane exposes
|
||||
`current` for that.
|
||||
- **Sequence once, distribute unchanged (contracts C1).** Application
|
||||
packets are stamped by the app and handed to each target session via
|
||||
`forward(_:)`; `Session` stamps only the packets it originates
|
||||
(handshake, heartbeats, `Hi`, `ByeBye`). There is no public API to
|
||||
send an unstamped application packet on one connection.
|
||||
packets are stamped by the app — one `Id` from the process-wide
|
||||
`PacketSequencer` — and the identical `Packet` is handed to each target
|
||||
session via `forward(_:)`, which never re-stamps. `Session` stamps ids
|
||||
itself only for the packets it originates (`Handshake`, `HandshakeAck`,
|
||||
heartbeats, `Hi`, `ByeBye`), which are per-connection on Windows too;
|
||||
that path is `private func originate(_:)`. This is enforced by the API,
|
||||
not by convention: as of 2026-09-16 there is **no** public
|
||||
`Session.send`-style entry point, so a caller cannot send an unstamped
|
||||
application packet on one connection even by mistake.
|
||||
- **Each `Session` beats for its own connection.** Windows broadcasts one
|
||||
heartbeat from a global timer to every socket, so a peer pair's two
|
||||
connections carry the *same* `Id` and the receiver's replay ring
|
||||
@@ -164,8 +169,7 @@ public final class Session { // not Sendable: one per connecti
|
||||
public func noteReceiveError(bytesReceived: Int) // a 0-byte / short read
|
||||
public func report(_ new: SocketStatus) // .resolving, .sendError, …
|
||||
public func tick(now: TimeInterval, userActive: Bool)
|
||||
public func send(_ packet: Packet) // stamps Id + Src, frames, queues
|
||||
public func forward(_ packet: Packet) // already sequenced: Src only
|
||||
public func forward(_ packet: Packet) // app-stamped: Src + framing only
|
||||
public func probe() // Hi
|
||||
public func sayGoodbye() // ByeBye
|
||||
public func drain() -> [Data] // write these through CipherWriter
|
||||
@@ -314,10 +318,15 @@ Rules the consuming lanes must honour:
|
||||
and `Switcher`. Everything in this lane lives on one queue.
|
||||
- **`Switcher` never does I/O.** It returns `[SwitchAction]`; the app
|
||||
performs them in order. A `.send` packet is already sequenced and
|
||||
addressed, so it goes to every connection through `Session.forward(_:)`,
|
||||
**not** `Session.send(_:)` — one broadcast must keep one `Id` across a
|
||||
peer's two connections or the receiver's replay ring will not collapse
|
||||
the duplicate.
|
||||
addressed, so it goes to every connection through `Session.forward(_:)`
|
||||
— the only application-traffic entry point there is. One broadcast must
|
||||
keep one `Id` across a peer's two connections or the receiver's replay
|
||||
ring will not collapse the duplicate (contracts C1).
|
||||
- **Anything else the app originates is stamped once, by the app.** Input,
|
||||
`HideMouse`, `MachineSwitched`, `NextMachine`, `Matrix` and clipboard
|
||||
chunks take an `Id` from the single `PacketSequencer` and are then
|
||||
`forward`ed to each target session unchanged. `Session` sequences only
|
||||
its own handshake, heartbeats, `Hi` and `ByeBye`.
|
||||
- **`.parkCursor` records a position; it moves the OS cursor only when
|
||||
`destinationIsRemote || byHideMouseMessage`.** `Switcher` pre-evaluates
|
||||
both halves of the `HideMouseCursor` gate (`Common.cs:1488`) so no
|
||||
|
||||
@@ -592,3 +592,19 @@ sees them. One subsection per lane, appended, never rewritten.
|
||||
- The trusted branch is guarded by `receivedCount > 0` (`:1531`), so a
|
||||
0-byte read never reaches `Receiver.ProcessPackage`; a short read does,
|
||||
and `PreProcess` drops it for being `Invalid` (`Receiver.cs:42-50`).
|
||||
11. **`SkSend` stamps one `Id` and writes the same `DATA` to every matching
|
||||
socket.** The increment happens once, before the loop
|
||||
(`Common.cs:914`), and the same struct is then handed to `TcpSend` for
|
||||
each socket whose `MachineId` matches `Des` — or, for `Des == ID.ALL`,
|
||||
every socket that is not `exceptDes` and whose machine is in the matrix
|
||||
(`:919-929`). `TcpSend` fills `Src` when it is `ID.NONE` and touches
|
||||
nothing else (`SocketStuff.cs:666-669`). So a peer reached over two
|
||||
connections receives the *same* `Id` twice and the receiver's 50-entry
|
||||
replay ring collapses the second delivery (`Receiver.cs:40-82`) — which
|
||||
is the mechanism, not an accident, and the reason contracts C1 requires
|
||||
the app to stamp an application packet once and distribute it unchanged.
|
||||
A per-connection stamp would give the duplicate a fresh `Id` and defeat
|
||||
the ring. Only the packets Windows itself sends per connection — the
|
||||
handshake pair, the heartbeat written on a fresh connection
|
||||
(`SocketStuff.cs:1451`), `Hi` and `ByeBye` — go out through `TcpSend`
|
||||
with no `SkSend` in front of them.
|
||||
Reference in new issue
Block a user