Repository navigation
refactor(client): split the peer session into cohesive modules - #118
Conversation
`crates/client/src/peer.rs` becomes `crates/client/src/peer/mod.rs` with no content change. The split that follows needs somewhere to put its files, and a rename on its own is a diff with nothing to read.
`mod.rs` keeps the `PeerSession` struct and the module wiring; one concern per file around it: invite §5.1's link, its two keys and the connection address options what a session is opened with, and the host producer half report §13.11's decisions, the two counts and the four endings plaintext the y-protocols side of a `kind = 0` frame clocks the caller's tick: the lease, the two presence windows, the census roles §13.4's attribution and §13.6's eligibility deliver one frame in: the verdict, §13's decision, the messages it carried publish everything that leaves: the seal, the gates, the announcement holds §13.7's paths, the lease and its expiry events what a driver hands in that is not a frame read what a caller reads off a session speculation §13.9's held edits and the clean baseline Every item moves unchanged: no logic, no signature, and no visibility beyond the extraction itself.
…over The inline `mod tests` becomes `peer/tests.rs`, and the imports it was getting from `use super::*` -- which reached whatever `peer.rs` imported -- are restated from the modules that now hold them. The tests themselves are unchanged.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
There was a problem hiding this comment.
Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.
An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.
|
@coderabbitai review A note on the review round, so the state is read from here rather than inferred from silence. CI is green. Copilot could not review. Both of its rounds carry the same message:
So there is nothing to answer from it. CodeRabbit has not posted a round since it was added as a reviewer. This is a large diff that The branch is left unmerged for the owner to land. |
|
crates/client/src/peer.rswas 5633 lines — about half the client crate — of which 2180 arethe state machine and 3453 its tests. It is now a directory:
mod.rskeeps thePeerSessionstruct and the module wiring, and one concern lives per file. Nothing is broken and no
fail-first test exists or was invented; this is a move, verified as one below.
Module map
mod.rsmod,pub use, the shared imports), and thePeerSessionstruct with its fieldsinvite.rsPROTOCOL.md§5.1's invite: the link, its two keys, the connection address, andPeerInvite's redactingDebugoptions.rsPeerOptions,FRAME_BUDGET, and the host producer half built from them (§7.1)report.rsOutcome,Published,Counted,Applied,Dropped,Ending— §13.11's decisions and the four endingsplaintext.rskind = 0frame: the session document, one message's bytes, and whether a plaintext is content or a handshakeclocks.rsroles.rsdeliver.rsCANONICAL.md§6.1's verdict, §13's decision, and the y-protocols messages a content frame carriespublish.rsholds.rsevents.rspeer.joined,peer.left, and a host's listing changing under itread.rsspeculation.rstests.rs5760 lines in total against the original 5633: the 127 are the thirteen module headers, their
uselines and themoddeclarations inmod.rs.Each module's doc comment is the paragraph above, so the map reads from the files as well as
from here.
Verified as a pure move
The work is three commits, each a move on its own:
peer.rsbecomespeer/mod.rswith no content change —git show --stat -Mreportsrename crates/client/src/{peer.rs => peer/mod.rs} (100%).mod.rskeeps the struct, the wiring, and the tests still inline.mod testsbecomespeer/tests.rs.The extraction was then compared against
origin/main'speer.rsmechanically, with attributes,usetrees and///blocks compared as well as code (an editorial move is verified by what itcarries, not by a green suite):
What it does: tokenise both sides; drop comments,
useandmoddeclarations,#[..]attributesand
pubqualifiers; unwrap eachimpl PeerSession { .. }wrapper on both sides, since one ofthose per module is the extraction itself; compare the resulting multisets. Separately compare the
#[..]attribute multiset, the set of names theusetrees import (each module now imports itsown
use super::..header, so the counts cannot match and only a lost name can), and the///line multiset. It is 291 lines of Python, reading
git show <rev>:crates/client/src/peer.rsand the workingtree; it is below so a reviewer can re-run it: see the fold-out.
Two differences are expected and are why the numbers are folded rather than equal:
pub(super)it needs pushes it past the 80-columnwidth, so
rustfmtlays the parameter list out vertically and a trailing comma appears that theone-line form did not have. Four signatures break this way (
host_producer,publish_state,renew_lease,publish); one comma disappears intests.rswhere removing themod tests {wrapper shortens a line enough to join it.
#[cfg(test)]moves from the inlinemod teststo the declaration of the out-of-line one.It is excluded from both sides.
Two items a draft of this extraction had dropped are restored, and the check above is what caught
them:
impl fmt::Debug for PeerInvite, which is what keeps §5.1's two keys out of a log, and thePeerSessiondoc line. Both are in thedoc linesandcode tokenscounts above.No visibility beyond the extraction: a moved item is
pub(super)where a sibling module calls it,and private where it already was. No item moved from
pubto anything narrower, so the crate'spublic surface (
PeerSession,PeerInvite,PeerOptions,FRAME_BUDGET,wire_address,Outcome,Published,Applied,Dropped,Ending, re-exported fromcrate::peer) isunchanged.
Gate
nix build .#checks.x86_64-linux.{fmt,clippy,nextest}, before and after.Before —
origin/main(5a83020) in a worktree:After — this branch,
EXIT=0for both invocations:The test inventory is asserted independently of the runner: the tree carries 190
#[test]itemsbefore and after, 84 of them in
peer.Reviewer risks
move are the thirteen module headers in
mod.rs's wiring, thepub(super)on items a siblingcalls, and the fifteen lines of
tests.rs's import block.tests.rsis 3407 lines and still the largest file in the crate. It is onemod tests, leftwhole on purpose: splitting tests between modules is a different change with a different review.
The two visibility neighbours (
MAX_REPLIES_PER_FRAMEindeliver,ReadState) are stillprivate to their modules because nothing outside them reads them.
mod.rsis 149 lines of struct fields. The struct is where it was; only the impl blocksmoved out. A follow-up could group the fields, but that is a different change.
byte-identical to
mainby construction.The check, in full