refactor(server): extract framework-neutral protocol package#144
Open
anderslindho wants to merge 6 commits intomasterfrom
Open
refactor(server): extract framework-neutral protocol package#144anderslindho wants to merge 6 commits intomasterfrom
anderslindho wants to merge 6 commits intomasterfrom
Conversation
jacomago
approved these changes
May 4, 2026
simon-ess
reviewed
May 4, 2026
Contributor
simon-ess
left a comment
There was a problem hiding this comment.
Some bits of this seem a bit twisty IMO but I think this is generally an improvement.
697618f to
6825f36
Compare
6825f36 to
9a2e497
Compare
9a2e497 to
c58a236
Compare
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.
c58a236 to
3480f0f
Compare
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Lift RecSync wire encoding and decoding out of the Twisted adapter (
recast.py,announce.py) into a newrecceiver.protocolsubpackage 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.