CLAUDE.md gains a 'How this project is developed' section: strictly serial Dev (Opus 5) -> QA (Sonnet 5, code quality) -> lead inspection; commit along the way without requiring every commit to compile; the user is the tester. docs/loop.md, docs/topo.md and TODO.md are rewritten to a serial lane order with no test-writing items; the test targets are removed and tools/gates.sh is lint + layering grep + build. Co-Authored-By: Claude Fable 5.1 <[email protected]>
78 lines
3.2 KiB
Markdown
78 lines
3.2 KiB
Markdown
# packet-codec
|
||
|
||
## Goal
|
||
|
||
The `DATA` packet and its framing as Swift value types in `MWBCore`,
|
||
byte-exact with `docs/protocol.md` §1: the 32/64-byte layout, the
|
||
`PackageType` numbering and big/small rule, the ASCII machine name, and
|
||
the magic + checksum framing that overwrites bytes 1–3. This is the
|
||
foundation every other lane reads bytes through; it has no I/O and no
|
||
crypto.
|
||
|
||
## Assumptions
|
||
|
||
- **Little-endian, natural alignment, no padding**, because the Windows
|
||
side marshals an explicit-layout struct (`DATA.cs:135-149`). All
|
||
offsets are taken from `docs/protocol.md` §1.1, not recomputed.
|
||
- **`Type` is one byte on the wire.** The Swift type stores `PackageType`
|
||
as `UInt8` at offset 0; `Framing.open` zeroes bytes 1–3 exactly as
|
||
`ProcessReceivedDataEx` does, so a decoded packet's bytes 1–3 are
|
||
always 0 and re-sealing is deterministic.
|
||
- **The checksum covers bytes 2..31 only, even on 64-byte packets.** We
|
||
reproduce this; the encryption layer, not the checksum, is what
|
||
protects the name half. Say so in a comment at the checksum loop.
|
||
- **Unknown type values decode as `.unknown(UInt8)`** rather than
|
||
throwing, so a newer Windows build cannot desynchronise our framing.
|
||
Size for an unknown value follows the big/small rule (`0x80` bit ⇒ 64,
|
||
else 32), which is what Windows would do.
|
||
- **Machine names are ASCII, ≤ 32, space-padded.** Non-ASCII input is an
|
||
error at construction time; on decode, bytes are trimmed of trailing
|
||
spaces and NULs (Windows trims spaces; NUL tolerance costs nothing).
|
||
- The magic number is a parameter of `Framing`, not computed here
|
||
(that is cipher-stream's `magicNumber(for:)`).
|
||
|
||
## Handshakes
|
||
|
||
### Promised (topo.md handshake 1, to session and every later consumer)
|
||
|
||
```swift
|
||
public enum PackageType: RawRepresentable { case hi, hello, … , unknown(UInt8); var rawValue: UInt8; var isBig: Bool }
|
||
public struct Packet {
|
||
public var type: PackageType; public var id: Int32; public var src: UInt32; public var des: UInt32
|
||
public var mouse: MouseData // X, Y, wheelDelta, flags at 16..31
|
||
public var keyboard: KeyboardData// dateTime at 16, vk at 24, flags at 28
|
||
public var nonce: (UInt32, UInt32, UInt32, UInt32)
|
||
public var postAction: UInt32
|
||
public var machineName: String? // nil on small packets
|
||
public var payload48: Data // bytes 16..63 for clipboard chunks
|
||
public init(type:) // zeroed buffer of the right size
|
||
public init?(bytes: Data) // 32 or 64 bytes, no framing check
|
||
public var bytes: Data // 32 or 64
|
||
}
|
||
public enum Framing {
|
||
public static func seal(_ p: Packet, magic: UInt32) -> Data
|
||
public static func open(_ bytes: Data, magic: UInt32) -> Packet // type == .invalid on bad framing
|
||
}
|
||
```
|
||
|
||
Exact spelling may change during the lane; the README is updated in the
|
||
same change and session codes against the README.
|
||
|
||
### Consumed
|
||
|
||
- Nothing. Foundation only.
|
||
|
||
## Status / TODO
|
||
|
||
- [ ] `Sources/MWBCore/Packet.swift`: `PackageType` (every value in
|
||
protocol §1.2, cited), `isBig`, `Packet` with the union views.
|
||
- [ ] `Sources/MWBCore/Framing.swift`: `seal` / `open` per §1.3, each
|
||
constant cited to `SocketStuff.cs`.
|
||
- [ ] `docs/protocol.md`: add any offset or rule learned while porting.
|
||
|
||
## Work log
|
||
|
||
## QA log
|
||
|
||
## Review
|