C# – How to bootstrap a P2P service so that users can locate each other

Architecturecp2p

My P2P app needs to locate peers, but I don't want to hard-code a DNS address…

One example I've seen is bootstrapping via IRC, but I'd like to do this over HTTP/s if possible.

What are my options and techniques for bootstrapping a P2P app?

Best Answer

It's the easiest if you have a "mothership". Nowadays it doesn't have to be a single server, a SPOF, there are tons of cheap CDN (content delivery network) and cloud solutions.

Otherwise, borrow an idea from a software that is the most successful: bittorrent. Distributed hash tables (DHT) are simply beautiful. And if I'm not mistaken, you can piggyback your own software on the DHT network. DHT doesn't have to be bittorrent-specific, but there are millions of hosts in the bittorrent DHT network already, so why not use it for anything that you like? It's a huge free resource, the protocol is trivial, but there are already lots of libraries for it, it's like a gold mine.

Of course, DHT needs to be bootstrapped as well, but it's an already solved problem. You can collect a big list of known DHT hosts, or just probe randombly, it is so huge that either can work.

Bittorrent's DHT is simple: every torrent has a hash, and the DHT network stores a peer list for each hash. All you have to do is make up a fake, fixed hash for your needs and store that in the DHT. You can help bootstrapping if you create a few DHT nodes yourself that are close to your fixed hash, but it won't be necessary.

Well, it's actually not a completely free resource, if you participate in the DHT network, then you should also participate in the storage of other hashes, and other peers will use your peers as a service.