Skip to content

refactor: standardize peer actor ownership - #257

Merged
artrixdotdev merged 4 commits into
mainfrom
refactor/standardize-peer-actor
Jul 29, 2026
Merged

refactor: standardize peer actor ownership#257
artrixdotdev merged 4 commits into
mainfrom
refactor/standardize-peer-actor

Conversation

@artrixdotdev

@artrixdotdev artrixdotdev commented Jul 29, 2026

Copy link
Copy Markdown
Owner

Summary

  • replace the overloaded wire-level Peer with a minimal WirePeer containing only its address and optional peer ID
  • move bitfield, protocol support, metadata assembly, connection state, transfer accounting, and runtime behavior into PeerActor
  • keep PeerView as the consistent frontend live projection across handles, listeners, events, and facade exports
  • remove obsolete peer helpers and cover the wire/frontend model boundary

API boundary

Tracker, DHT, engine, and swarm plumbing now exchange WirePeer. Connected operational state is actor-owned. Frontend consumers continue to receive PeerView from the live API.

Validation

  • cargo nextest run --nocapture --no-fail-fast — 192 passed, 9 skipped
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo fmt --check
  • cargo doc --no-deps --document-private-items
  • cargo check -p libtortillas --no-default-features

@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@artrixdotdev, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 45 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ff1b8324-f855-48af-b258-ffcee3bd8545

📥 Commits

Reviewing files that changed from the base of the PR and between c7c53dd and e4a86b0.

📒 Files selected for processing (4)
  • crates/libtortillas/src/peer/actor.rs
  • crates/libtortillas/src/peer/info.rs
  • crates/libtortillas/src/peer/state.rs
  • crates/libtortillas/tests/peer_models.rs

Walkthrough

This PR separates wire-level peer identity from actor-owned runtime state, replaces PeerView with live Peer, and propagates WirePeer through trackers, DHT discovery, torrent routing, handshakes, and tests. Handshake reserved bytes are passed separately into peer actors.

Changes

Peer model and runtime state

Layer / File(s) Summary
Wire and runtime peer models
crates/libtortillas/src/peer/*
Introduces WirePeer for address and optional ID data, while runtime state, metadata, and capability storage become crate-private actor state.
PeerActor state ownership
crates/libtortillas/src/peer/actor.rs
Moves identity, pieces, choking, metadata, capabilities, metrics, and message timestamps from the stored peer object into PeerActor.
Live peer presentation surface
crates/libtortillas/src/live/*, crates/libtortillas/src/facade.rs
Replaces PeerView with the exported live Peer type across views, handles, hub scopes, listeners, and re-exports.

WirePeer routing and tracker contracts

Layer / File(s) Summary
Tracker, discovery, and torrent peer contracts
crates/libtortillas/src/tracker/*, crates/libtortillas/src/dht/messages.rs, crates/libtortillas/src/torrent/messages.rs
Tracker announce results, decoded peers, DHT results, and torrent messages now use WirePeer.
Handshake and swarm propagation
crates/libtortillas/src/engine/messages.rs, crates/libtortillas/src/torrent/swarm.rs
Handshake reserved bytes are carried separately through incoming-peer and peer-connected messages into PeerActorArgs.
Test and mock wiring
crates/libtortillas/src/lib.rs, crates/libtortillas/src/torrent/actor.rs, crates/libtortillas/tests/peer_models.rs
Mocks and tests construct WirePeer, validate address-based identity semantics, and verify live peer state fields.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Tracker
  participant TorrentActor
  participant PeerActor
  Tracker->>TorrentActor: announce WirePeer values
  TorrentActor->>TorrentActor: append or connect WirePeer
  TorrentActor->>PeerActor: PeerActorArgs with WirePeer and reserved bytes
  PeerActor->>TorrentActor: peer state, pieces, and metadata events
Loading

Possibly related PRs

Suggested labels: refactor

Suggested reviewers: kurealnum

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and clearly reflects the main refactor of moving peer ownership and behavior into PeerActor.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/standardize-peer-actor

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot added the refactor Neither fixes a bug nor adds a feature label Jul 29, 2026
@artrixdotdev
artrixdotdev force-pushed the refactor/standardize-peer-actor branch from c7c53dd to b78938b Compare July 29, 2026 06:03

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/libtortillas/src/peer/actor.rs`:
- Around line 216-226: Update the supervisor notification in the
`handle_extended_message` flow, specifically the
`self.supervisor.tell(torrent::events::InfoBytes { ... })` call, to handle the
awaited send error instead of using `unwrap()`. Log mailbox-closed or
full-mailbox failures with the same graceful `warn!`/`trace!` pattern used by
`notify_ready`, `reject_piece_request`, and `on_stop`, without panicking the
peer actor.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 84a14a1d-0872-4316-ad70-96309d397365

📥 Commits

Reviewing files that changed from the base of the PR and between 99fa6a5 and c7c53dd.

📒 Files selected for processing (20)
  • crates/libtortillas/src/dht/messages.rs
  • crates/libtortillas/src/engine/messages.rs
  • crates/libtortillas/src/facade.rs
  • crates/libtortillas/src/lib.rs
  • crates/libtortillas/src/live/handle.rs
  • crates/libtortillas/src/live/hub.rs
  • crates/libtortillas/src/live/mod.rs
  • crates/libtortillas/src/live/view.rs
  • crates/libtortillas/src/peer/actor.rs
  • crates/libtortillas/src/peer/info.rs
  • crates/libtortillas/src/peer/mod.rs
  • crates/libtortillas/src/peer/state.rs
  • crates/libtortillas/src/peer/supports.rs
  • crates/libtortillas/src/torrent/actor.rs
  • crates/libtortillas/src/torrent/messages.rs
  • crates/libtortillas/src/torrent/swarm.rs
  • crates/libtortillas/src/tracker/http.rs
  • crates/libtortillas/src/tracker/model.rs
  • crates/libtortillas/src/tracker/udp.rs
  • crates/libtortillas/tests/peer_models.rs

Comment thread crates/libtortillas/src/peer/actor.rs
@artrixdotdev
artrixdotdev merged commit ca568eb into main Jul 29, 2026
3 checks passed
@artrixdotdev
artrixdotdev deleted the refactor/standardize-peer-actor branch July 29, 2026 06:17
@coderabbitai coderabbitai Bot mentioned this pull request Jul 29, 2026
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

refactor Neither fixes a bug nor adds a feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant