You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/routing/kad-dht.md
+80-13Lines changed: 80 additions & 13 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,12 +27,18 @@ requirements.
27
27
28
28
## Introduction
29
29
30
-
FIXME:
30
+
`FIXME:`
31
31
32
32
Distributed Key-Value Store
33
33
34
34
Goal of DHT is to find the closest peers to some key (in a specific geometry). Once this routing to the closest nodes is possible, nodes can interact with these nodes in various ways, including in asking them to store and serve data.
35
35
36
+
### DHT Operations
37
+
38
+
* Peer Routing
39
+
* Value storage and retrieval
40
+
* Content provider advertisement and dsicovery
41
+
36
42
### Relation to [libp2p kad-dht](https://github.com/libp2p/specs/tree/master/kad-dht)
37
43
38
44
The IPFS Kademlia DHT specification is a specialization of the libp2p Kademlia DHT.
@@ -170,9 +176,7 @@ the most stable peers are eventually retained in the Routing Table.
170
176
171
177
#### IP Diversity Filter
172
178
173
-
SHOULD implement
174
-
175
-
FIXME:
179
+
`FIXME:` DHT Servers SHOULD implement an [IP Diversity Filter](https://github.com/libp2p/go-libp2p-kbucket/blob/ddb36fa029a18ea0fd5a2b61eeb7235913749615/peerdiversity/filter.go#L45).
176
180
177
181
### Routing Table Refresh
178
182
@@ -198,32 +202,91 @@ information on its closest peers.
198
202
199
203
## Lookup Process
200
204
201
-
Iterative vs Recursive
205
+
When performing a lookup for a Kademlia Identifier in the DHT, a node begins by
206
+
sending requests to known DHT servers whose identifiers are close to the
207
+
target. Each response provides information on peers that are even closer to the
208
+
target identifier, and the process continues iteratively until the absolute
209
+
closest peers are discovered.
210
+
211
+
### Iterative vs Recursive Lookup
212
+
213
+
In an iterative lookup, the querying node sends requests to several known DHT
214
+
servers. Each server returns a list of peers that are closer to the target
215
+
Kademlia Identifier, but does not continue the lookup process. The querying
216
+
node then directly contacts these closer peers, repeating the process until the
217
+
closest nodes are found.
218
+
219
+
In a recursive lookup, the querying node delegates the task to a peer that is
220
+
closer to the target. That peer then queries its own closer peers on behalf of
221
+
the original node, and this delegation continues recursively until the target
222
+
is reached.
223
+
224
+
The IPFS Kademlia DHT uses an iterative lookup approach because recursive
In public DHT swarms, DHT Servers MUST never respond with private or loopback multiaddresses.
231
+
Upon receiving a lookup request for a Kademlia Identifier, a DHT Server MUST
232
+
return the Peer ID and multiaddresses of the `k` closest nodes to the requested
233
+
Kademlia Identifier that are stored in its Routing Table. DHT Servers SHOULD
234
+
NOT return any information about unresponsive nodes.
235
+
236
+
In public DHT swarms, DHT Servers MUST filter out private and loopback
237
+
multiaddresses, and MUST NOT include peers whose only addresses are private or
238
+
loopback.
206
239
207
-
Should Server tell Client about Server? And about Client?
240
+
`FIXME:` Define whether DHT Server should return information about itself and
241
+
about requester.
208
242
209
-
### Concurrency
243
+
### Client behavior
210
244
211
-
Implementation specific. Recommendation is `10`
245
+
When a client initiates a lookup for a Kademlia Identifier `kid` (DHT Servers
246
+
can initiate lookups as clients), it starts by selecting the closest nodes to
247
+
`kid` in XOR distance, and put them in a list/set. Then it sends requests for
248
+
`kid` to the closest nodes (see [concurrency](#concurrency)) to `kid` from the
249
+
list.
212
250
213
-
### Lookup termination
251
+
Upon receiving a response, the client adds freshly received peers to the list
252
+
of closest peers. It sends a request to the closest peer to `kid` that hasn't
253
+
been queried yet. The client ignores timeouts and invalid responses.
214
254
215
-
This is hard
255
+
When a client (or a DHT server acting as a client) initiates a lookup for a
256
+
Kademlia Identifier `kid`, it begins by selecting the known nodes closest to
257
+
`kid` in terms of XOR distance, and adds them to a candidate list. It then
258
+
sends lookup requests to the closest nodes from that list.
216
259
217
-
#### Resiliency
260
+
As responses are received, any newly discovered peers are added to the
261
+
candidate list. The client proceeds by sending a request to the nearest peer to
262
+
`kid` that has not yet been queried. Invalid responses and timeouts are simply
263
+
discarded.
218
264
219
-
Implementation specific. Recommendation is `3`
265
+
#### Termination
266
+
267
+
The lookup process continues until the `k` closest reachable peers to `kid`
268
+
have been successfully queried. The process may also be terminated early if the
269
+
request-specific success criteria are met. Additionally, if every candidate
270
+
peer has been queried without discovering any new ones, the lookup will
271
+
terminate.
272
+
273
+
#### Concurrency
274
+
275
+
A client MAY have multiple concurrent in-flight queries to distinct nodes for
276
+
the same lookup. This behavior is specific to the client and does not affect
277
+
how DHT servers operate.
278
+
279
+
It is recommended that the maximum number of in-flight requests (denoted by
280
+
`α`) be set to `10`.
220
281
221
282
## Peer Routing
222
283
223
284
DHT Clients that want to be routable must make sure they are in the peerstore of the closest DHT servers to their own PeerID.
224
285
225
286
When performing a `FIND_NODE` lookup, the client will converge to the closest nodes in XOR distance to the requested PeerID. These nodes are expected to know the multiaddrs of the target peer. The
226
287
288
+
### `FIND_NODE` Termination
289
+
227
290
### Routing to non-DHT Servers
228
291
229
292
### Signed Peer Records
@@ -234,6 +297,10 @@ When performing a `FIND_NODE` lookup, the client will converge to the closest no
234
297
235
298
sha256
236
299
300
+
### Lookup Termination and Resiliency
301
+
302
+
Resiliency: Implementation specific. Recommendation is `3`
0 commit comments