Question

I am thinking about how to implement a P2P protocol with only two nodes.

At first I read about different DHT implementations in the hope that this scenario would be feasible. Turns out most intrinsically expect more than a few nodes to be effective.

Thinking about this naively gives me the following challenges:

  • Where would the nodes look to find each other during bootstrapping?
  • What about NAT traversal and other network nasties?

Has anyone succeeded with this?

Was it helpful?

Solution

Basically, it can't be done efficiently.

Most P2P networks rely on seeding information (lists of existing nodes it can try to connect to). I take it from your question that you want to a solution that doesn't require seeding information to be given to the nodes.

Without seeding information, nodes in P2P networks are limited to trying random addresses. This can work successfully if (A) the number of P2P nodes in the network is large and (B) many/most nodes have the ability to accept incoming connections (i.e., are not behind NAT).

For 2 nodes on IPv4, this will mean billions of packets sent before they discover each other, if one of them can accept inbound connections.

If neither can accept inbound connections, they must attempt to connect to each other simultaneously to achieve nat traversal. The chance of success is only about one in 2^64 per attempt. This is since they each have to guess the other's address correctly. This is simply not going to work.

Obviously, everything gets harder with IPv6.

Licensed under: CC-BY-SA with attribution
scroll top