Repository navigation
feat(torrent): forward the port through every NAT layer and show whether peers can connect - #543
Conversation
…her peers can connect - Port mapping goes on through the NAT layers in front of the device, up to three: while a router's own external address is still private, Ketch asks the gateway outside it (guessed from that address) to forward the port the router got, by NAT-PMP, PCP (new, RFC 6887) or UPnP sent to it directly. Peers are told the outermost forwarded port. - The engine reports whether peers can connect (`TorrentController.reachability`, REST `GET /api/torrents/reachability`, the `reachability` capability): reachable once a peer connected over TCP, forwarded through every layer to a public address, blocked by a NAT outside the mapped routers, or not forwarded. RemoteKetch fails closed against older servers. - Settings → BitTorrent shows it for this device and remote ones, and whether hole punching still reaches peers behind routers.
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. |
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ea63a8f71a
ℹ️ 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".
- Only TCP peers from public addresses count as reachable; LAN peers found by local discovery no longer turn a blocked device reachable. - Forwarded waits for the DHT to see our address while DHT runs (unknown until then). - The Settings notice follows the device's current entry and features, so polling moves to the client a reconnect creates.
…download finds it RecordingKetchApi copied the engine's task list on Dispatchers.Default, so a DELETE sent right after POST could miss the new task and answer 404, which failed DownloadRoutesTest now and then.
What
Port mapping through every NAT layer. After mapping the listen port on the home router, if that router's own external address is still private (a second router, or a provider's carrier-grade NAT), Ketch asks the gateway outside it to forward the same port on to the router, up to three layers, until it reaches a public address.
PcpClient, RFC 6887 MAP), then UPnP. Outer layers' UPnP is a unicast SSDP search sent straight to the guessed gateway (UpnpClient.discoverAt), since multicast discovery can't cross a NAT.outerGatewayGuesses): the first and last host of its /24 and the first host of its range (10.0.0.1,100.64.0.1,172.x.0.1).Reachability status, on every device.
TorrentController.reachability()→TorrentReachability: statusreachable(a peer connected in over TCP),forwarded(every layer up to a public address forwards the port and the DHT agrees on that address),blocked(a NAT outside the mapped routers won't forward),not-forwarded, orunknown(engine not running); plus the port, forwarded layers, incoming TCP peers and whether hole punching is on.reachabilitycapability andGET /api/torrents/reachability;RemoteTorrentControllerfails closed against older servers without sending a request. Unknown wire statuses decode asunknown.Why
Hole punching (#541) gets peers behind NATs talking, but a forwarded port is still the best path, and routers behind a second NAT never got one. Users also had no way to tell whether their device was reachable at all.
Notes for reviewers
reachable, as they prove nothing about incoming reachability.20.0.113.xfor "public" addresses, sincepublicTorrentAddresstreats the documentation ranges as non-public.blockedthere.Tests
NatLayersTest: a router behind a second NAT forwarding through both (and removal order), nothing answering outside the router (not public), a PCP-only gateway, and the gateway guesses.TorrentReachabilityTest(engine before and after start),KetchTorrentControllerTest(capability gating),TorrentRoutesTest,RemoteTorrentControllerTest,TorrentContractsTest(wire names, unknown statuses) andTorrentReachabilityNoticeTest(text and tone per status).:library:torrent:jvmTest,:app:shared:jvmTest,:library:mcp:test,:app:desktop:test, plus the torrent-api, remote and server suites pass.