Skip to content

Commit 0a3d8e3

Browse files
committed
http-routing: add "get closest peers" operation
Adds a new HTTP endpoint that can be used to request records for the closest peers to a given key that the routing implementation knows about. The use-case for this is browser nodes performing random walks to find peers that they can make a circuit relay reservation on, without having to be DHT clients to perform the walk which can be undesirable given all the connection/processing overhead that entails.
1 parent 27a9aaa commit 0a3d8e3

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

src/routing/http-routing-v1.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,60 @@ Each object in the `Providers` list is a record conforming to a schema, usually
106106

107107
## Peer Routing API
108108

109+
### `GET /routing/v1/closest-peers/{peer-id}?[closerThan]&[count]`
110+
111+
#### Path Parameters
112+
113+
- `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.
114+
115+
#### Query Paramters
116+
117+
- `closerThan` 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.
118+
- Returned peer records must be closer to `peer-id` than `closerThan`.
119+
- If omitted the routing implementation should use it's own [Peer ID](https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md).
120+
- `count` is an optional number that specifies how many peer records the requester desires.
121+
- Minimum 1, maximum 100, default 20.
122+
123+
#### Response Status Codes
124+
125+
- `200` (OK): the response body contains peer records.
126+
- `404` (Not Found): must be returned if no matching records are found.
127+
- `422` (Unprocessable Entity): request does not conform to schema or semantic constraints.
128+
129+
#### Response Headers
130+
131+
- `Content-Type`: the content type of this response, which MUST be `application/json` or `application/x-ndjson` (see [streaming](#streaming)).
132+
- `Last-Modified`: an HTTP-date timestamp ([RFC9110, Section 5.6.7](https://www.rfc-editor.org/rfc/rfc9110#section-5.6.7)) of the resolution, allowing HTTP proxies and CDNs to support inexpensive update checks via `If-Modified-Since`
133+
- `Cache-Control: public, max-age={ttl}, public, stale-while-revalidate={max-ttl}, stale-if-error={max-ttl}`: meaningful cache TTL returned with the response.
134+
- When present, `ttl` SHOULD be shorter for responses whose resolution ended in no results (e.g. 15 seconds),
135+
and longer for responses that have results (e.g. 5 minutes).
136+
- Implementations SHOULD include `max-ttl`, set to the maximum cache window of the underlying routing system.
137+
For example, if Amino DHT results are returned, `stale-while-revalidate` SHOULD be set to `172800` (48h, which at the time of writing this specification, is the provider record expiration window).
138+
- `Vary: Accept`: allows intermediate caches to play nicely with the different possible content types.
139+
140+
#### Response Body
141+
142+
```json
143+
{
144+
"Peers": [
145+
{
146+
"Schema": "<schema>",
147+
"Protocols": ["<protocol-a>", "<protocol-b>", ...],
148+
"ID": "bafz...",
149+
"Addrs": ["/ip4/..."],
150+
...
151+
},
152+
...
153+
]
154+
}
155+
```
156+
157+
The number of peer records in the responses SHOULD be limited to the `count` query parameter, which defaults to 20 if unspecified.
158+
159+
The client SHOULD be able to make a request with `Accept: application/x-ndjson` and get a [stream](#streaming) with more results.
160+
161+
Each object in the `Peers` list is a record conforming to the [Peer Schema](#peer-schema).
162+
109163
### `GET /routing/v1/peers/{peer-id}`
110164

111165
#### Path Parameters

0 commit comments

Comments
 (0)