Repository navigation
fix(torrent): answer a new LAN peer's announce so it finds us at once - #630
Merged
Merged
Conversation
A device that joined the LAN found a seeder next to it only at the seeder's next BEP 14 round, up to five minutes later: a complete swarm never dials the peers it hears, so the newcomer learns of it only from its announce. A peer heard for one of our torrents for the first time in a minute now brings that torrent's next announce forward to the first moment BEP 14's one a minute allows. A magnet on the LAN found its seeder in 4 s, where it waited 100 s before.
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 95995cdc5b
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Answering every peer not heard in a minute let two instances echo each other: each one's answer reached the other just as the minute ran out, and was answered in turn, every minute. Only a peer not heard for a torrent in two announce rounds (10 minutes) is answered now, so peers that announce every round never answer each other, while a device that joins the LAN still gets its answer at once.
Contributor
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.
Found while testing Local Service Discovery (BEP 14) between two Ketch instances on one machine: a seeder (
ketch server) and a downloader (ketch <magnet>) with no trackers, DHT or web seed to help.Problem
The downloader found the seeder only when the seeder next announced the torrent. That's every 5 minutes, so two runs of 90 s and 180 s found nothing, and a third waited about 100 s. Sniffing the group showed both sides' announces going out on the LAN. The seeder heard the newcomer's announce, but a complete swarm never dials the peers it hears, so the newcomer only learns of the seeder from the seeder's own announce.
Picture a phone joining the Wi-Fi while the desktop seeds: it waits up to 5 minutes for a peer on the same LAN.
What changes
TorrentLocalDiscovery.accept: when an announce brings a peer we haven't heard from this minute, for a torrent we take part in, that torrent's next announce moves up to the first moment BEP 14 allows (max(now, last announce + 1 min)), and the announce loop is woken. Many newcomers within a minute still produce at most one announce per torrent, so the per-torrent limit holds and there's no storm.Verification
LAN peer 192.168.31.11:16999) and downloaded the 16 MB file in 4 s, with the seeder answering within the same second. Before: about 100 s, up to 5 minutes. SHA-256 matches.TorrentLocalDiscoveryTestcases:accept_newPeer_isAnsweredAsSoonAsAMinuteAllows(an immediate answer two minutes in; peers within the next minute get a single answer at the minute mark) andaccept_peerOfAnotherTorrent_isNotAnswered../gradlew :library:torrent:jvmTestpasses.