feat: Implement BEP 3-compatible choking algorithm#218
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughImplements BEP 3 choking behavior across peer stats sampling, peer selection, periodic rechoke scheduling, and architecture documentation. ChangesBEP 3 Choking Algorithm
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested labels
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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: 3
🤖 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 339-372: The sampled download rate is being based on all received
bytes, including unsolicited pieces. Update the `PeerMessages::Piece` handling
in `PeerActor` so `bytes_downloaded` is only incremented after the block is
confirmed against `pending_block_requests`, and keep `snapshot_stats()` /
`download_rate` ranking driven only by those validated transfers. Ensure the
request-removal and byte accounting stay in the fulfilled-request branch so
`set_download_rate` and rechoke ranking cannot be inflated by unrequested data.
In `@crates/libtortillas/src/torrent/actor.rs`:
- Around line 248-271: The rechoke scheduling path in schedule_next_rechoke is
treating a temporary scheduler failure as terminal, which leaves next_rechoke
unset and stops future rechoke cycles. Update the schedule_next_rechoke flow so
that when scheduler.ask(SetTimeout::new(...)) returns an error, it immediately
retries or falls back to re-arming a new timeout instead of only logging and
exiting. Keep the fix localized to schedule_next_rechoke and the next_rechoke
handling so rechoke() continues to have a valid path to schedule the next round.
- Around line 244-246: The initial rechoke is only being scheduled in the
torrent actor flow, so choking/unchoking decisions do not happen until the timer
fires. Update the `TorrentActor` rechoke path to apply the first rechoke
immediately when entering `Downloading` or `Seeding`, then keep using
`schedule_next_rechoke()` for subsequent intervals. Use the existing
rechoke-related methods in `actor.rs` (especially `schedule_next_rechoke` and
the code that transitions into those states) to place the immediate rechoke call
without changing the recurring timer behavior.
🪄 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
Run ID: 5ec4e1f1-5b8f-4409-b5e5-16628fbd3a0e
📒 Files selected for processing (7)
crates/libtortillas/src/ARCHITECTURE.mdcrates/libtortillas/src/peer/actor.rscrates/libtortillas/src/torrent/actor.rscrates/libtortillas/src/torrent/choking.rscrates/libtortillas/src/torrent/choking_flow.rscrates/libtortillas/src/torrent/messages.rscrates/libtortillas/src/torrent/mod.rs
Closes #206
Summary by CodeRabbit