Skip to content

Commit 53fc4a7

Browse files
diversity filter
1 parent 59b0ff1 commit 53fc4a7

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

src/routing/kad-dht.md

+30-3
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,28 @@ the most stable peers are eventually retained in the Routing Table.
177177

178178
#### IP Diversity Filter
179179

180-
`FIXME:` DHT Servers SHOULD implement an [IP Diversity Filter](https://github.com/libp2p/go-libp2p-kbucket/blob/ddb36fa029a18ea0fd5a2b61eeb7235913749615/peerdiversity/filter.go#L45).
180+
DHT servers SHOULD implement an IP Diversity Filter to ensure that nodes in
181+
their routing table originate from a diverse set of Autonomous System Numbers
182+
(ASNs). This measure helps mitigate Sybil attacks and enhances the network’s
183+
resilience.
184+
185+
A recommended approach is to impose the following limits:
186+
187+
* **Globally**, a maximum of `3` nodes sharing the same IP grouping should be
188+
allowed in the routing table.
189+
* **Per routing table bucket**, a maximum of `2` nodes from the same IP
190+
grouping should be permitted.
191+
192+
For IP grouping:
193+
194+
* **IPv6 addresses** are grouped by ASN.
195+
* **IPv4 addresses** are grouped by `/16` prefixes, except for [legacy Class A
196+
blocks](https://en.wikipedia.org/wiki/List_of_assigned_/8_IPv4_address_blocks),
197+
which are grouped by `/8` prefixes.
198+
199+
Since a single node can advertise multiple addresses, a peer MUST NOT be added
200+
to the routing table if any of its addresses already exceed the allowed
201+
representation within the table.
181202

182203
### Routing Table Refresh
183204

@@ -238,8 +259,14 @@ In public DHT swarms, DHT Servers MUST filter out private and loopback
238259
multiaddresses, and MUST NOT include peers whose only addresses are private or
239260
loopback.
240261

241-
`FIXME:` Define whether DHT Server should return information about itself and
242-
about requester.
262+
DHT Servers SHOULD NOT return their own Peer ID in responses to `FIND_NODE`
263+
queries. However, they MUST include information about the requester, if and
264+
only if the requester is a DHT Server in its routing table and it is among the
265+
`k` closest nodes to the target key.
266+
267+
A DHT Server SHOULD always return information about its known `k` closest
268+
peers, provided its routing table contains at least `k` peers, even if those
269+
peers are not closer to the target key than itself.
243270

244271
### Client behavior
245272

0 commit comments

Comments
 (0)