Repository navigation
Description
It's probably time to investigate decentralizing discovery. Doing so would reduce our infrastructure burden and reduce centralized knowledge of the network. In a DHT we want to be able to look up the contact details for a given device ID. We want to publish our own contact details into the DHT. We don't necessarily want to make it simple for a passive observer to map the entire network, so it would be nice if the contact details were encrypted.
I suggest that we could use a key-value database laid out like:
Key: SHA256(device ID)
Value: The contact details, in protobuf format, encrypted using the device ID as a shared secret.
Given that I know the device ID I'm looking for, I can then hash it and look it up, and decrypt the answer. For other nodes in the network, the data is mostly gibberish as you need to know the device ID it represents to be able to interpret it and reversing the SHA256(device ID) to an actual device ID is not feasible.
As far as an actual implementation goes I've surveyed the Go ecosystem to try to find a suitable DHT package. So far I've not really succeeded. Here are the ones I've looked at and some notes on them; it would be lovely if someone did find or develop a good package for this.
- https://github.com/nictuku/dht seems to be the best candidate, but a partial implementation - only supports looking up nodes for an "info hash", not storing or retrieving actual values? maybe could be built upon
- https://github.com/fastfn/dendrite looks like a full implementation and may be usable, though annoying dependencies (0MQ transport), may require some rewriting
- https://github.com/distributed/malus toy project, last commit 6 years ago
- https://github.com/cfromknecht/kademlia partial implementation, uses TCP?
- https://github.com/worldveil/peerchat student project, abandoned?, no license
- https://github.com/zhujun1980/dhtrobot looks sort of promising, need to get past the chinese docs
- https://github.com/gr0gmint/godht incomplete, abandoned
- https://github.com/chuckha/dht partial implementation, TCP based
- https://github.com/Hermes/ghord bare bones, maybe usable as a base for something
- https://github.com/benjojo/NorthStar the authors themselves hate this code
- https://godoc.org/github.com/r-medina/gmaj partial, lots of TODOs
If anyone wants to pick this up and run with it, please do so, and announce yourself in the comments below :)
Activity
AudriusButkevicius commentedon Jul 5, 2016
Ipfs people are using kademila afaik.
Anyways, you still need infrastructure to bootstrap, and how do we perform authentication against other peers being non-malicious, prevent malicious peers from overwriting keys, or even bootstrap server from being malicious?
calmh commentedon Jul 5, 2016
https://godoc.org/github.com/ipfs/go-ipfs/routing/dht looks quite good, yes, thanks!
Certainly we'll need a couple of bootstrap nodes. But I don't think they need to be as beefy as our current discovery servers, and more importantly they shouldn't need to scale much in the future.
As for the maliciousness I'm not sure. Decentralizing things makes that difficult. The worst case scenario is then being tricked to connect to the wrong place when looking for a certain device ID, blocking discovery of a given device... Certainly the stored value could be signed by the device certificate, and the certificate attached, but that doesn't stop anyone from just uploading a blob of garbage for a given lookup key.
Gnnh: https://github.com/ipfs/go-ipfs/blob/master/routing/dht/dht.go#L19
raichu commentedon Jul 5, 2016
Also relevant:
http://blog.notdot.net/2009/11/Implementing-a-DHT-in-Go-part-1
http://blog.notdot.net/2009/11/Implementing-a-DHT-in-Go-part-2
A note about Kademlia's DoS resistance:
https://github.com/ethereum/wiki/wiki/Kademlia-Peer-Selection#backwards-compatibility-mode-and-dos-safety
A security-enchanced variant of Kademlia resistant against various types of DoS attacks (described in section 3.2): http://www.tm.uka.de/doc/SKademlia_2007.pdf
http://www.sciencedirect.com/science/article/pii/S1389128615004168
cdhowie commentedon Jul 7, 2016
I don't think that's a feasible attack, since the value would be encrypted by the device ID. Such an attack would have to be targeted against a specific, known device ID -- and for that to even work, your DHT node needs to be the one responsible for SHA256(device ID). And even if you successfully pull that off, the traffic is end-to-end encrypted. All you'd really be able to see (assuming you proxy the data) are the IPs on both sides and the amount of data being transferred. You can kinda do this already by running a public relay server, right?
The "store garbage" attack is much more worrying to me. To my knowledge, the way other DHT networks (torrents for example) combat this problem is by having the key be a hash of the value -- not something we can realistically do here.
cdhowie commentedon Jul 7, 2016
A realization I just had is that any kind of verification mechanism put in place to avoid a garbage attack would have to incorporate a timestamp, or it would be susceptible to a replay attack, where a previous (valid) value is stored under the same key. For mobile clients that are constantly changing IPs, this could prevent any nodes from connecting to them.
calmh commentedon Jul 7, 2016
I think this will necessarily be some sort of security trade off. We'll gain some security (no need for a trusted middle man who has all the data, harder to DoS, etc) and lose some (harder to prevent false information). But as long as the feasible attack is mostly to prevent lookup against a specific device ID I think it may be worth it. It's just one discovery method among many after all.
AudriusButkevicius commentedon Jul 7, 2016
Or just DDoS the bootstrapping node...
calmh commentedon Jul 7, 2016
That could still be fine though, if you could still reach some other device to bootstrap, say via local discovery, or if you're already connected to the network. But sure, agree we need the three geographically diverse bootstrap nodes and it's certainly not bulletproof. But honestly the bigger threat at the moment is probably me screwing up the discovery servers by fatfingering something. :)
aviau commentedon Jul 14, 2016
One other method around DDoS-ing the bootstrap node is that clients should save all nodes that they know to the disk. Whenever they restart they can try to bootstrap with all of these nodes if the master bootstrap node is down. The bootstrap node is only critical for the fist time the client is started.
Ferroin commentedon Jul 15, 2016
That becomes problematic when dealing with clients with dynamic addresses, you'd need a system with a static address in the network for such a scheme to work reliably, because there's the possibility that all the other systems change address.
canton7 commentedon Jul 15, 2016
I think @aviau meant all other DHT nodes which that device had discovered, and not all configured Syncthing devices.
There will probably be enough DHT nodes which either have static IPs, or whose IP hasn't changed (most dynamic IPs rarely change in practice) for a node to find one which is still contactable, and so reconnect itself to the network.
Ferroin commentedon Jul 15, 2016
To retain feature parity though, there would need to be an option to run independently of the default bootstrap servers and DHT network. Otherwise, this is functionally a regression for anyone using a custom global discovery server. This becomes even more important if all nodes are expected to participate, especially considering people like me who have to pay for bandwidth and data transfer for our nodes which do have static addresses. Such a situation of paying for bandwidth is a lot more common than you think, an will be the case for almost anyone using cloud hosting or running over a mobile broadband connection, and in fact is much better served by a centralized discovery mechanism like what Syncthing has now.
aviau commentedon Jul 15, 2016
Exactly. We use this method for Ring.
100 remaining items
sjehuda commentedon May 10, 2024
DHT is one of the technologies that bad governments and bad corporations hate the most.
DHT is an important technology. I operate several machines world wide to share over 5 million files via DHT over the BitTorrent system and I use not even a single BitTorrent Tracker to discover peers.
@AudriusButkevicius
@SoniEx2
Gentlemen, these are good notes you have made.
The VoIP client Jami (previously GNU Ring, and SFLphone), from @savoirfairelinux, which has started as a SIP/IAX VoIP client has later added support to a completely decentralized system which uses DHT to discover peers of its decentralized VoIP system.
See OpenDHT and this article (Tar archive) which probably has been censored either by a bad intelligence agency or by a bad corporation.
Also, to increase identity verification you can make DHT possible at the condition of using PGP keys, similarly to the cjdns system from @cjdelisle.
You might also want to add support to cjdns and I2P systems.
You can refer to Seth who gracefully explains the I2P system.
Another important comment about the importance DHT
The so called entertainment industry (i.e. inteligence controlled cultural subversion industry) has ceased to discuss about P2P for over a decade, and instead of publicly fighting BitTorrent, the industry has increased the prevalence of so called "streaming services" and have limped the internet with the help of the Net Neutrality propaganda which was designed to harm systems like Syncthing and non-corporate online services.
The reason for this is because DHT has made BitTorrent unstoppable and the best resort to fight against BitTorrent is to stop talking about it and hope people would forget about it.
Another important comment about the issue with intermediating resources
Centralized resources are more often subjected to compromisation than decentralized resources.
The Syncthing Relay Nodes, and also BitTorrent Trackers, are centralized in nature and have an identity which can be tracked and potentially hijacked by a bad entity.
Many domains and IP addresses of BitTorrent Tracker that went offline are now owned by DOOBLE (the so called we are not so evil corrporation), and these domain still do not function as BitTorrent Trackers, yet BitTorrent clients with these domains assigned are being exploited by turning them into a mean of identification, as long as the people who use BitTorrent did not remove the outdated BitTorrent Trackers.
So it might be for Syncthing Relay Nodes.
Let us not be subjected to this scenario.
cjdelisle commentedon May 10, 2024
It's not quite like that, all DHTs are inherently susceptible to poison and sybil attacks. For example if I don't like entry XXXX I can generate a ton of fake entries and keep the ones with keys which are numerically closest to XXXX, then I insert them into the DHT to clog up the nodes which hold them. Likewise, I can generate fake nodes, using the same collision attack to get node IDs that are numerically closest to XXXX such that most nodes will drop XXXX because it appears that it is already handled by my (fake) nodes.
Yes and no. The Bittorrent DHT does make Bittorrent a lot more robust against attacks, but not for the reasons you might think. The DHT is attackable, as stated, but the nodes in the DHT are not all what they appear to be. The major DHT nodes are not some uTorrent install running on someone's laptop, they're on servers operated by the Good Ol' Boys, so if you start trying to attack the DHT, you may find your IP addresses suddenly getting blocked and then you're unreachable to most of the DHT network. The DHT bootstraps off of DNS seed servers and if the seed operators only point people to the "known good guy" DHT nodes, it's easy for an attacker to just end up isolated from the whole network.
When this is combined with the proliferation of Trackers, it creates a platform which is very frustrating to attack. You can go after the DHT and it will degrade somewhat but you don't get to pull out a clear win, and in any case the trackers will carry the network so basically no one will notice that anything happened. You can also go after the trackers, but there are a lot of them, in a lot of countries, and even if you manage to take down a large subset of trackers, the network will be carried by the DHT, so attacks on Bittorrent are just miserably frustrating to carry out.
For cjdns, all you need is IPv6 support and to not forbid communication with addresses in the
fc00::/8block.calmh commentedon May 10, 2024
There's a whole lot of handwaving in this thread. We have a fairly simple set of requirements:
All the "get an immutable piece of data by hash" or "get an ip:port for a node with a random 160 bit ID" solutions don't move anything forward, because they solve a different problem than the one we have.
bt90 commentedon May 10, 2024
The biggest obstacle, IMHO, is that while there are DHTs that offer some sort of protected/signed payload, they rely on public key cryptography. The thing is that the initial pairing is done without the full public key. So we end up with a bootstrapping problem.
EternityForest commentedon May 10, 2024
jadsongmatos commentedon Jun 28, 2024
One of the ways to reduce server waste would be to leverage existing Torrent Tracker servers, similar to the P2PT project, which uses WebTorrent Trackers as signaling servers for P2P connections.
P2PT is a library that connects P2P very differently. P2PT works by using WebTorrent Trackers as signaling servers, converting an application's unique identifier into a valid Info Hash, which is sent to the trackers to obtain a list of web peers using the application.
By taking a similar approach, Syncthing could use WebTorrent Trackers for P2P discovery, reducing reliance on dedicated servers and improving scalability. This method uses existing infrastructure to reduce costs and make communication more efficient.
References:
aydencook03 commentedon Apr 29, 2026
A possible alternative to DHT that still keeps discovery decentralized would be to use Nostr relays. There are many p2p projects that utilize nostr ephemeral events for peer discovery. Hashtree is an example. This would be simpler and more lightweight than a DHT.
sjehuda commentedon May 1, 2026
@aydencook03 This might be a good idea. Do you have code references?
Nevertheless, DHT is probably preferable, as it is utilized with BitTorrent, eDonkey2000, Gnutella, and other networks; and, most implementations are lean.
Of course, implementing a mechanism to query consequent IP addresses (so called "brute force") be a good addition to software which support DHT.
Perhaps implementing all three (DHT, Nostr, Query) be a good idea.
sjehuda commentedon May 1, 2026
@aydencook03 This might be a good idea. Do you have code references?
aydencook03 commentedon May 1, 2026
@sjehuda I don't. But if people think it's a good idea then I could find some or put something together myself. I've made a post in the forums so that this idea can be discussed.
sjehuda commentedon May 1, 2026
While I prefer and biased towards DHT, as I have experience with DHT, your idea might be even better.
The fact that maybe it was not tried yet, does not mean that it is not better.
I am not an authority; yet,, I am infavour of considering your idea.
feat: Peer-to-peer discovery (fixes syncthing#3388)
feat: Peer-to-peer discovery (fixes syncthing#3388)
feat: Peer-to-peer discovery (fixes syncthing#3388)