Skip to content

Commit a6bf57c

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 a6bf57c

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

src/routing/http-routing-v1.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,58 @@ 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`
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+
121+
#### Response Status Codes
122+
123+
- `200` (OK): the response body contains peer records.
124+
- `404` (Not Found): must be returned if no matching records are found.
125+
- `422` (Unprocessable Entity): request does not conform to schema or semantic constraints.
126+
127+
#### Response Headers
128+
129+
- `Content-Type`: the content type of this response, which MUST be `application/json` or `application/x-ndjson` (see [streaming](#streaming)).
130+
- `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`
131+
- `Cache-Control: public, max-age={ttl}, public, stale-while-revalidate={max-ttl}, stale-if-error={max-ttl}`: meaningful cache TTL returned with the response.
132+
- When present, `ttl` SHOULD be shorter for responses whose resolution ended in no results (e.g. 15 seconds),
133+
and longer for responses that have results (e.g. 5 minutes).
134+
- Implementations SHOULD include `max-ttl`, set to the maximum cache window of the underlying routing system.
135+
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).
136+
- `Vary: Accept`: allows intermediate caches to play nicely with the different possible content types.
137+
138+
#### Response Body
139+
140+
```json
141+
{
142+
"Peers": [
143+
{
144+
"Schema": "<schema>",
145+
"Protocols": ["<protocol-a>", "<protocol-b>", ...],
146+
"ID": "bafz...",
147+
"Addrs": ["/ip4/..."],
148+
...
149+
},
150+
...
151+
]
152+
}
153+
```
154+
155+
The `application/json` responses SHOULD be limited to 20 peers.
156+
157+
The client SHOULD be able to make a request with `Accept: application/x-ndjson` and get a [stream](#streaming) with more results.
158+
159+
Each object in the `Peers` list is a record conforming to the [Peer Schema](#peer-schema).
160+
109161
### `GET /routing/v1/peers/{peer-id}`
110162

111163
#### Path Parameters

0 commit comments

Comments
 (0)