Skip to content

query: ip diversity filter #1070

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 2, 2025
Merged

Conversation

guillaumemichel
Copy link
Contributor

@guillaumemichel guillaumemichel commented Mar 20, 2025

Summary

IP diversity checks have been added to the DHT implementation to enhance the DHT robustness (see implementation here and here). However, these checks are only effective for the routing table. These checks aren't helping clients to avoid malicious nodes during lookups.

Problem

When clients want to write content to the DHT (provider records, IPNS record), they will look for the k closest peers to the key they are trying to write. Since most DHT Servers implement the IP Diversity Filter, it means that these honest DHT Servers should never return more than 2 peers from the same IP block/ASN.

However, if the query hits a (malicious) peer not implementing the IP Diversity Filter, this peer may return plenty of closer peers sharing the same IP block/ASN, or even the same IP address. Since these peers are closer to the target, the client will continue the lookup by querying these potentially malicious peers, and the records will eventually be allocated to these peers.

Same for when clients want to read records from the DHT.

Solution

The query process on the client side can implement a check similar to the IP diversity filter check in the routing table. If a peer respond with more than e.g 3 closer peer sharing the same IP block/ASN, the client would drop all these addresses sharing the same address range, and only keep less represented IP addresses (if any).

Implications

This means that GetClosestPeers may not return the actual k closest peers in XOR distance to a key, if many of the actual closest peers share the same address range. GetClosestPeers may return a limited (e.g 3) number of peers sharing the same address range, but the other returned peers will be located in other IP blocks/ASNs.

Hence in the case of a many nodes on the same IP range in the same small keyspace region, the content is expected to be stored on some of the actual closest peers (in XOR distance) that are on the same IP range (potentially malicious), and on the closest peers (in XOR distance) to the key that are using other IP blocks/ASNs. Hence client should be able to retrieve the value from the nodes with more diverse IPs.

References

@guillaumemichel guillaumemichel requested a review from a team as a code owner March 20, 2025 13:31
@guillaumemichel guillaumemichel marked this pull request as draft March 20, 2025 17:00
@guillaumemichel guillaumemichel force-pushed the query/ip-diversity-filter branch from 17a95dc to 41715ff Compare March 21, 2025 10:09
@guillaumemichel guillaumemichel marked this pull request as ready for review March 21, 2025 12:06
@guillaumemichel guillaumemichel marked this pull request as draft March 25, 2025 15:42
@guillaumemichel guillaumemichel marked this pull request as ready for review March 26, 2025 12:49
@guillaumemichel guillaumemichel requested a review from a team as a code owner March 26, 2025 12:49
@guillaumemichel
Copy link
Contributor Author

Added the IP diversity filter to accelerated DHT client GetClosestPeers to get feature parity.

@guillaumemichel guillaumemichel requested a review from sukunrt March 26, 2025 12:51
@gammazero gammazero self-requested a review April 1, 2025 14:43
Copy link
Member

@sukunrt sukunrt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TBH, I am confused about how the diversity filter works or why the queries do actually converge. It's been there for a while now, so I guess it's okay.

Is there any reference for understanding how this works?

@guillaumemichel
Copy link
Contributor Author

Is there any reference for understanding how this works?

The best we have is the IPFS Kademlia DHT draft spec, see this section.

@libp2p libp2p deleted a comment from sukunrt Apr 2, 2025
@guillaumemichel guillaumemichel merged commit f0eac34 into master Apr 2, 2025
7 checks passed
@guillaumemichel guillaumemichel deleted the query/ip-diversity-filter branch April 2, 2025 11:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants