Skip to content

query: ip diversity filter#1070

Merged
guillaumemichel merged 7 commits into
masterfrom
query/ip-diversity-filter
Apr 2, 2025
Merged

query: ip diversity filter#1070
guillaumemichel merged 7 commits into
masterfrom
query/ip-diversity-filter

Conversation

@guillaumemichel

@guillaumemichel guillaumemichel commented Mar 20, 2025

Copy link
Copy Markdown
Member

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
Comment thread rt_diversity_filter.go Outdated
Comment thread rt_diversity_filter.go
Comment thread query.go Outdated
@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
Copy Markdown
Member 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

@sukunrt sukunrt left a comment

Copy link
Copy Markdown
Member

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?

Comment thread amino/defaults.go Outdated
Comment thread amino/defaults.go
Comment thread fullrt/dht.go Outdated
Comment thread rt_diversity_filter.go Outdated
Comment thread fullrt/dht.go
Comment thread query.go
@guillaumemichel

Copy link
Copy Markdown
Member 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
@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