Skip to content

refactor(server): extract framework-neutral protocol package#144

Open
anderslindho wants to merge 6 commits intomasterfrom
refactor-protocol
Open

refactor(server): extract framework-neutral protocol package#144
anderslindho wants to merge 6 commits intomasterfrom
refactor-protocol

Conversation

@anderslindho
Copy link
Copy Markdown
Contributor

@anderslindho anderslindho commented Apr 30, 2026

Lift RecSync wire encoding and decoding out of the Twisted adapter (recast.py, announce.py) into a new recceiver.protocol subpackage so the parsing logic can be reused if we move from Twisted to asyncio (or any other transport) in the future. The Twisted adapter now operates on typed dataclasses with named fields rather than struct slices and integer offsets.

This is preparation work - no functional change except for the standalone bugfix commit.

Comment thread server/recceiver/protocol/messages.py Outdated
Comment thread server/recceiver/recast.py Outdated
Copy link
Copy Markdown
Contributor

@simon-ess simon-ess left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some bits of this seem a bit twisty IMO but I think this is generally an improvement.

Comment thread server/recceiver/recast.py Outdated
Comment thread server/recceiver/protocol/messages.py
Comment thread server/recceiver/protocol/messages.py
Comment thread server/recceiver/protocol/messages.py
Comment thread server/recceiver/protocol/messages.py
Comment thread server/recceiver/protocol/messages.py
Comment thread server/recceiver/recast.py
@anderslindho anderslindho requested a review from jacomago May 4, 2026 10:26
@anderslindho anderslindho requested a review from simon-ess May 4, 2026 13:09
@anderslindho anderslindho requested a review from mdavidsaver May 5, 2026 08:33
Extract the RecSync wire protocol into `recceiver.protocol`, a package
that owns all byte-level encoding and decoding for both TCP messages
and the UDP announce packet.
Replace the inline struct definitions and ad-hoc byte slicing in the
Twisted protocol adapter with calls into `recceiver.protocol.messages`.
Each receive handler now decodes a typed dataclass and works with named
fields, which keeps the adapter focused on connection state, flow
control, and session dispatch rather than wire layout.

Behavior changes worth noting:

- A frame with a zero-length body is now logged and skipped at the
  header layer instead of being dispatched to a handler with empty
  bytes. The reference C client never sends an empty frame, so this
  affects only malformed peers.
- `UploadDone` now requires an exact 4-byte payload, matching what the
  C client actually sends (`/* dummy 4 byte payload */` in
  `client/castApp/src/caster.h`). Previously the body was ignored.
- `AddRecord` and `AddInfo` now require the trailing text to match the
  declared lengths exactly, and reject records-with-empty-type or
  aliases-with-non-empty-type up front. The previous chain silently
  dropped some malformed cases.
- The unused `writeMsg` helper is gone; `ServerGreeting` and `Ping` now
  use `Message.frame()` directly.
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 7, 2026

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.

3 participants