Repository navigation
Conversation
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: c6f4ddf992
ℹ️ 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".
| require(matchesV1 != matchesV2) { "Unknown or ambiguous incoming swarm tag" } | ||
| val mode = if (matchesV2 || allowUpgrade && remote.upgrade && v2 != null) Mode.V2 else Mode.V1 | ||
| val result = result(remote, mode, peerId, null) | ||
| connection.write(encode(mode, peerId, upgrade = false)) |
There was a problem hiding this comment.
Advertise acceptance in the hybrid-upgrade response
When allowUpgrade accepts a v1 hybrid offer, mode becomes V2, but the response unconditionally clears BEP 52's v2 reserved bit. The local initiator still succeeds because it infers acceptance solely from the changed tag, so the loopback test masks this; a standards-compliant peer that requires both sides to advertise v2 support will instead reject or continue as v1. Set the upgrade bit on responses that select Mode.V2 through this negotiation, and validate it on the initiating side.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Keeping the current negotiation behavior. BEP 52’s Upgrade Path assigns this bit to the initiating peer’s SHA-1 handshake; the responder accepts by returning the v2 infohash. It does not require a second acceptance bit: https://github.com/bittorrent/bittorrent.org/blob/master/beps/bep_0052.rst#L514-L517.
This also matches the independent libtorrent implementation: its encoder sets 0x10 only while the connection is still v1 (https://github.com/arvidn/libtorrent/blob/RC_2_0/src/bt_peer_connection.cpp#L770-L774), and its initiator recognizes the returned v2 hash without checking that bit (https://github.com/arvidn/libtorrent/blob/RC_2_0/src/bt_peer_connection.cpp#L3472-L3480). Requiring the flag in the response would reject this valid negotiation. The existing directAndOfferedUpgradeRoutesKeepTheFullIdentity test explicitly covers an offered upgrade accepted with the v2 tag and the response flag clear. Independent-client full v2 interoperability remains a roadmap gate; the local loopback alone is not claimed to prove it.
|
Superseded by #235 (V2 handshake, hash exchange and bounded transport) in the consolidated eight-PR stack for #162. The replacement preserves this PR's code and subsequent fixes; its description links the original head and review discussions. The only additional consolidation fix is the CI-discovered listener cancellation regression, documented on the replacement. All eight replacements have passed their required CI checks. Closing without merging. This branch and its discussions remain available for reference. Review index: #162 (comment) |
Adds direct v1/v2 and explicitly offered hybrid-upgrade handshakes while retaining the caller's full torrent identity separately from the 20-byte wire tag. Negotiation rejects unexpected upgrades/downgrades, ambiguous local aliases, invalid framing, self-connections and mismatched expected peer IDs. Scratch admission precedes I/O; timeout, cancellation and validation failures close the connection.
Stacked on #190; advances step 08 of #162. A loopback test negotiates v2 using a validated document, then issues a hash request through the admitted transport and verifies the reply. Wire tags remain routing hints, not full remote-content authentication. Multi-torrent listener routing, the complete payload actor, magnet integration and independent-client v2 interoperability remain pending. Extension/DHT advertisement defaults off.
Validation: five focused JVM handshake/connection tests pass with zero failures/errors/skips. All 399 iOS simulator torrent tests execute and pass with the simulator opt-in flag. The existing test-clock usage now declares its coroutine opt-in explicitly.