Skip to content

Commit 48fe4cf

Browse files
committed
routing/http: simplify GetClosestPeers endpoint
changed path parameter from {peer-id} to {key} to accept both CIDs and Peer IDs, matching actual DHT usage where closest peers can be queried for arbitrary keys removed count and closer-than query parameters that were adding complexity without clear use cases in practice clarified response size should match DHT bucket size (20 for Amino DHT) added note that this optional endpoint helps light clients lower the cost of DHT walks in browser contexts
1 parent dd86eb3 commit 48fe4cf

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/routing/http-routing-v1.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -246,19 +246,16 @@ The content body must be a [`application/vnd.ipfs.ipns-record`][application/vnd.
246246

247247
## DHT Routing API
248248

249-
### `GET /routing/v1/dht/closest/peers/{peer-id}`
249+
### `GET /routing/v1/dht/closest/peers/{key}`
250250

251-
#### Path Parameters
252-
253-
- `peer-id` is a [Peer ID](https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md) represented as a CIDv1 encoded with `libp2p-key` codec.
251+
This optional endpoint allows light clients to lower the cost of DHT walks in browser contexts.
254252

255-
#### Query Parameters
253+
#### Path Parameters
256254

257-
- `closer-than` is an optional [Peer ID](https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md) represented as a CIDv1 encoded with `libp2p-key` codec.
258-
- Returned peer records must be closer to `peer-id` than `closer-than`.
259-
- If omitted the routing implementation should use its own [Peer ID](https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md).
260-
- `count` is an optional number that specifies how many peer records the requester desires.
261-
- Minimum 1, maximum 100, default 20.
255+
- `key` is a [CID] or [Peer ID][peer-id-representation] to find the closest peers to.
256+
- [CID] should be a CIDv1 in any encoding.
257+
- [Peer ID][peer-id-representation] can be represented as a Multihash in Base58btc, or a CIDv1 with `libp2p-key` (`0x72`) codec in Base36 or Base32.
258+
- Implementations SHOULD support both CID and Peer ID formats for maximum interoperability.
262259

263260
#### Response Status Codes
264261

@@ -294,7 +291,7 @@ The content body must be a [`application/vnd.ipfs.ipns-record`][application/vnd.
294291
}
295292
```
296293

297-
The number of peer records in the responses SHOULD be limited to the `count` query parameter, which defaults to 20 if unspecified.
294+
The number of peer records in the response SHOULD be limited to the DHT bucket size (20 for Amino DHT).
298295

299296
The client SHOULD be able to make a request with `Accept: application/x-ndjson` and get a [stream](#streaming) with more results.
300297

0 commit comments

Comments
 (0)