Repository navigation
Conversation
Bootstrap routers may reply to get_peers with useful nodes but no announce token. Preserve these replies for lookup traversal instead of discarding all returned contacts. Keep non-string tokens invalid. Only retain nonempty tokens for announce candidates, and look up tokens without inserting missing entries when the lookup finishes. Add CppUnit coverage for IPv4 and IPv6 tokenless replies, malformed IDs and compact nodes, wrong token types, continued lookup, and the announce token boundary.
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.
Summary
Use tokenless
get_peersreplies for DHT traversal without treating the replying node as an announce target.Problem
Some bootstrap-router replies observed through a single local network contain a valid 20-byte
idand compactnodes, but notoken. aria2 currently extracts the nodes and then throwsMalformed DHT message. Missing token.DHTMessageTrackerhandles the rejected reply as a timeout, so the useful contacts never reach the lookup. With an initially empty routing table this can prevent DHT discovery from progressing. Tracker-discovered peers may sometimes mask the problem.Protocol rationale and interoperability
BEP 5 specifies a token in both forms of
get_peersresponse; it does not declare the field optional. This change is a deliberate interoperability tolerance for nonconforming router replies, not a claim that those replies comply with BEP 5.The token protects the subsequent write operation:
announce_peermust return a token previously issued by the same node. Read-only traversal can still use the returned contacts without performing that write.This follows the same separation as libtorrent's
find_data_observer::reply: record a write token if present, but continue traversal independently. Its write-candidate selection skips nodes without a recorded token. aria2 remains stricter about a token key that is present with a non-string value.Changes and boundaries
get_peersreply, preserving its otherwise usable nodes/peers.findrather than inserting missing map entries when finishing lookup.announce_peer.nodesand IPv6nodes6. Existing peer-value entry filtering is unchanged; this is not a broad malformed-packet validation rewrite.Automated tests
Added five CppUnit test methods using the existing test infrastructure:
Local macOS arm64 results (Apple clang 21.0.0, CppUnit 1.15.1, OpenSSL 3):
make -j4 checkwith the new tests: exactly threeMissing tokenerrors among 1,130 tests, identifying both tokenless parser cases and continued traversal. No unrelated failures.make -j4 check: 1,130 passed, zero failures.security-regressions,task-cookies,http-retry,select-dns,legacy-checkpoint-import,http-redirect-policy): 87 passed, 0 failed, 3 conditionally skipped. The skips are the two Windows-only legacy-import cases and the previous-schema-binary compatibility case whose optional baseline binary was not supplied.The local build was not sanitizer-instrumented. Linux/Windows and the other compiler/TLS configurations remain for CI.
Metadata-only network experiment
Completed 40 trials, 5 per arm per hash. All 35 successful metadata files were independently hash-verified; all failures reached the 120-second deadline. No trials were discarded or replaced.
Missing tokenlog total08ada5a7a6183aae1e09d831df6748d566095a10dd8255ecdc7ca55fb0bbf81323d87062db1f6d1cc4d64a8b2b944fbb546253f144791dc367980eff70eb735e4cc90b6849d9f2e2373f89db465aa94bThe reported
c4d6case improved in this sample; the two healthy controls stayed successful.70ebdid not improve in success rate: one patched trial still timed out despite saving six IPv4 good nodes and recording no missing-token error. This patch fixes one interoperability failure, not all peer-connectivity problems. Successful-only times should not be interpreted as a general speedup. The mean wait with failed trials capped at 120 seconds was 76.181 → 23.979 seconds forc4d6, and 29.531 → 30.718 seconds for70eb.All results are from one machine and one network environment, on November 2, 2026. Compare a pristine build of current default
main(96b49bb471c82d414c760bb67dd6085607174d7e) with the same build plus this patch. No dependency, compiler, discovery-option or network-configuration changes between arms.Four bare-infohash magnets, five trials per arm per hash, cold DHT state and a fresh private directory/process per trial. Strictly alternating arms per hash, opposite starting order for alternating hashes, at most 120 seconds per trial, at least 180 seconds after native process exit before the same hash is retried. The same nine UDP trackers and
dht.transmissionbt.com:6881bootstrap were used in all trials. DHT/PEX enabled; local discovery disabled. Only metadata was requested (--bt-metadata-only=true); successful saved metadata must hash to the requested infohash. No HTTPxs, torrent-file injection or webseed fallback was used for the trials.The two public Creative Commons controls, Sintel and Big Buck Bunny, come from the official WebTorrent free-torrents list; their advertised infohashes were independently checked against the official torrent metadata before the trial. The additional hashes reproduce the originally reported discovery cases.
Exit DHT counts are serialized good nodes at shutdown, not runtime peak/total nodes. A trial stops once metadata is saved, so durations differ and node counts are not equal-time measurements. Missing measurements are not treated as zero. Payload byte counters were unavailable; the metadata-only setting and directory audit are separate from a measured zero-payload claim.
This is a small, nonrandomized sample with shared remote caches, changing peers and one network route (including its existing proxy/fake-IP path). Early trials overlapped local automated checks, adding a timing-load limitation. It is not a general success-rate or speed estimate, and does not prove every successful peer was discovered through DHT. IPv6 is covered deterministically in CppUnit, not established as a successful live IPv6 deployment by this experiment.