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?

closed as too broad by user22815, user53019, user40980, Kilian Foth, gnat Apr 3 '15 at 21:49

Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.