Conversation
WalkthroughPeerId default generation now extracts only ASCII digits from the core VERSION (before '-' or '+'), pads to 4 digits, and inserts those four digits into the Azureus-format ID slot (maintaining 20 bytes). Display and Debug formatting for PeerId were adjusted and tests updated. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant C as Caller (PeerId::default)
participant V as VERSION (env/const)
participant P as PeerId builder
C->>P: request default PeerId
P->>V: read VERSION string
Note over P: Take substring before '-' or '+'\nCollect only ASCII digits
alt digits < 4
P->>P: pad digits with '0' to length 4
end
P->>P: insert 4-digit segment into Azureus-format positions\n(enforce hyphens at expected bytes)
P-->>C: return constructed PeerId
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related issues
Possibly related PRs
Suggested labels
Pre-merge checks and finishing touches❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✨ Finishing touches
🧪 Generate unit tests
Tip 👮 Agentic pre-merge checks are now available in preview!Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.
Please see the documentation for more information. Example: reviews:
pre_merge_checks:
custom_checks:
- name: "Undocumented Breaking Changes"
mode: "warning"
instructions: |
Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).Please share your feedback with us on this Discord post. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
crates/libtortillas/src/peer/id.rs(3 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-28T06:33:16.003Z
Learnt from: artrixdotdev
PR: artrixdotdev/tortillas#125
File: crates/libtortillas/src/torrent/actor.rs:151-171
Timestamp: 2025-08-28T06:33:16.003Z
Learning: In the torrent actor's append_peer function in crates/libtortillas/src/torrent/actor.rs, when a PeerStream is provided, the peer has already been pre-handshaked by the engine. The engine handles the initial handshake validation, info hash verification, and peer ID extraction before passing the stream to the torrent actor. Therefore, the peer.id should already be populated when a stream is provided.
Applied to files:
crates/libtortillas/src/peer/id.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build_and_test
🔇 Additional comments (1)
crates/libtortillas/src/peer/id.rs (1)
359-359: Doc punctuation change — LGTM.
PeerId::default to strip prerelease tags from version
PeerId::default to strip prerelease tags from versionPeerId
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
crates/libtortillas/src/peer/id.rs (2)
419-428: Prefer hex for Debug instead of lossy UTF-8.Lossy UTF-8 can show � and is hard to grep. Hex is standard for peer IDs.
Apply:
impl fmt::Debug for PeerId { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!( - f, - "{} ({})", - self.client_name(), - String::from_utf8_lossy(self.id()) - ) + write!(f, "{} (", self.client_name())?; + for (i, b) in self.id().iter().enumerate() { + if i > 0 { /* optional: group */ } + write!(f, "{:02x}", b)?; + } + write!(f, ")") } }
472-474: Add an assertion that version bytes are digits.Small safety net against regressions that might introduce non-digits into [3..7].
Apply:
assert_eq!(peer.as_bytes()[0], b'-'); assert_eq!(&peer.as_bytes()[1..3], b"TO"); assert_eq!(peer.as_bytes()[7], b'-'); + assert!(peer.as_bytes()[3..7].iter().all(|b| b.is_ascii_digit()));
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
crates/libtortillas/src/peer/id.rs(5 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-28T06:33:16.003Z
Learnt from: artrixdotdev
PR: artrixdotdev/tortillas#125
File: crates/libtortillas/src/torrent/actor.rs:151-171
Timestamp: 2025-08-28T06:33:16.003Z
Learning: In the torrent actor's append_peer function in crates/libtortillas/src/torrent/actor.rs, when a PeerStream is provided, the peer has already been pre-handshaked by the engine. The engine handles the initial handshake validation, info hash verification, and peer ID extraction before passing the stream to the torrent actor. Therefore, the peer.id should already be populated when a stream is provided.
Applied to files:
crates/libtortillas/src/peer/id.rs
🧬 Code graph analysis (1)
crates/libtortillas/src/peer/id.rs (2)
crates/libtortillas/src/protocol/messages.rs (1)
fmt(129-161)crates/libtortillas/src/peer/mod.rs (2)
fmt(46-55)fmt(72-74)
🔇 Additional comments (5)
crates/libtortillas/src/peer/id.rs (5)
359-359: Doc tweak LGTM.
373-386: Azureus version slot fix is correct and robust.Digits-only, pad/truncate to 4, and fixed placement at [3..7] with id[7] = b'-' solves the prior OOB and format drift.
412-415: Display no longer includes the raw ID; update call sites that expect it.Handshake logging currently uses Display (see PeerMessages::Handshake). If you still want the ID in logs, switch those sites to {:?} (uses your new Debug).
Proposed change (in messages.rs):
- PeerMessages::Handshake(handshake) => write!(f, "Handshake({})", handshake.peer_id), + PeerMessages::Handshake(handshake) => write!(f, "Handshake({:?})", handshake.peer_id),
454-467: Test now mirrors production derivation—good.
63-67: Confirm PeerId Debug formatting unchangedYou replaced #[derive(Debug)] on PeerId with a manual Debug impl — confirm the manual impl preserves the derived Debug output because tests, snapshots, logs or downstream crates may depend on the exact formatting.
- Changed location: crates/libtortillas/src/peer/id.rs:63-67.
- Verify formatting/usage sites: crates/libtortillas/src/torrent/messages.rs:63-69 (uses "{peer_id:?}" / KillPeer/AddPeer), crates/libtortillas/src/errors.rs:315-328 (error formatting), crates/libtortillas/src/tracker/http.rs:149-151 and 190-197 (debug!/URI encoding), crates/libtortillas/src/protocol/messages.rs:131 (Handshake display).
Allows for pre-released tag stripping and fixes up some
DisplayandDebugimplementations.Fixes: #145
Summary by CodeRabbit
Bug Fixes
Tests
Documentation