nerazzurri
nerazzurri

Reputation: 1

Implementing DHT got find_node responses but never got get_peers or announce_peers requests

I'm implementing the DHT protocol, and I have received many find_node responses from which I got new nodes. I put the nodes in the queue, send a find_node request to them too. I'm running my java program on Linux.

So I think my decoding is right, I can parse IP and port from find_node responses.

But strangely I never received get_peers or announce_peers requests. What mistake caused my situation?

One thing I can't explain is that in find_node responses, I got a key IP which is my own IP and port after parsing. But the port is different every time. Why is the port different?

Upvotes: 0

Views: 305

Answers (1)

the8472
the8472

Reputation: 43125

But strangely I never received get_peers or announce_peers requests. What mistake caused my situation?

DHT node A will only send requests if you have been added to some routing table of another node B along the path to their destination. You only get added to routing tables if your node is well-behaved, i.e. has a good uptime, has a stable IP, port, ID and correctly responds to various query types such as pings.

One thing I can't explain is that in find_node responses, I got a key IP which is my own IP and port after parsing. But the port is different every time. Why is the port different?

  • You should be using a single UDP socket bound to a specific port and IP address on your local machine for all DHT communication. This is doubly important for an IPv6 implementation since hosts often have multiple IPv6 addresses.
  • You need to ensure that if you're behind a local NAT that there is a stable port mapping from your public address to your local machine. This can be achieved via manual port forwarding in your router or via the PCP, UPnP-IGD or NAT-PMP protocols if supported by the router.
  • If you're behind CGNAT then you may not have much control over it, but in some deployments your local router may be able to forward its port mappings to the CGNAT via PCP. You'll have to check whether your router has a public IP or your ISP's documentation/help forums to figure this out.

The bittorrent DHT doesn't work if your publicly visible IP:port tuple is not stable.

Upvotes: 0

Related Questions