Skip to content

DHT#115

Draft
xBaank wants to merge 8 commits into
developfrom
dht
Draft

DHT#115
xBaank wants to merge 8 commits into
developfrom
dht

Conversation

@xBaank

@xBaank xBaank commented Apr 5, 2026

Copy link
Copy Markdown
Owner

No description provided.

- StunClient: RFC 5389 Binding Request builder and XOR-MAPPED-ADDRESS
  parser; detects STUN datagrams by magic cookie before KRPC parsing
- DhtHandler: routes STUN responses to a pending TCS in the receive
  loop; exposes DiscoverExternalEndPointAsync (3s timeout)
- DhtClient: discovers external endpoint via STUN on bootstrap, then
  sends announce_peer after every get_peers response that carries a
  token; uses implied_port=false + TCP listen port when STUN succeeds,
  implied_port=true as fallback when behind symmetric NAT
- DhtClientOptions: StunServers defaults to Google public STUN servers
- Torrent: passes TCP listen port into DhtClient for announce_peer

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@xBaank
xBaank marked this pull request as draft April 5, 2026 14:52
@xBaank xBaank linked an issue Apr 5, 2026 that may be closed by this pull request
xBaank and others added 3 commits April 8, 2026 00:07
…s, drop STUN

- TrackerClient now waits on the cancellation token when UsedTrackers is 0
  instead of returning immediately, which previously made
  RunUntilFirstCompletesAsync cancel the entire torrent (including DHT) before
  any peers could be discovered.
- Rewrote DhtClient.GetPeersAsync and IterativeFindNodeAsync as proper
  Kademlia iterative lookups: sorted shortlists by XOR distance, parallel
  alpha-rounds, MaxRounds cap so a single lookup yields the actor back to its
  mailbox in bounded time. Added ResolveIpv4Async to avoid AAAA DNS hangs on
  IPv6-less networks.
- Tuned DhtHandler retry timings (2s x 2) so unresponsive nodes don't block
  the actor for tens of seconds per query.
- Removed STUN-based NAT traversal: it discovers a UDP mapping that can't
  legitimately drive announce_peer for a separate TCP listen port, added
  startup latency, and contributed nothing to the read path. announce_peer
  now always sends ImpliedPort=false; the wire-level field is kept on
  KrpcMessage for parsing inbound queries from other clients.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@xBaank xBaank changed the title Add STUN-based NAT traversal and announce_peer to DHT client DHT Apr 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add DHT

1 participant