-
Notifications
You must be signed in to change notification settings - Fork 232
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
http-routing: add "get closest peers" operation #476
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,6 +106,60 @@ Each object in the `Providers` list is a record conforming to a schema, usually | |
|
||
## Peer Routing API | ||
|
||
### `GET /routing/v1/closest-peers/{peer-id}?[closerThan]&[count]` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this makes sense at the Having an HTTP API for this kind of thing makes sense though, perhaps as
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My hope was that we could have it be routing-agnostic but maybe that's not possible, since the actual results would very much depend on what was being queried and how. I'm happy with:
though if it's all amino, perhaps we should just have done with it and use the RPC names?
...then maybe later:
though the second is redundant given the existing HTTP endpoints and the first is only partially redundant since we could use it to search for more than just IPNS records. ...and even later |
||
|
||
#### Path Parameters | ||
|
||
- `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. | ||
|
||
#### Query Paramters | ||
|
||
- `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. | ||
- Returned peer records must be closer to `peer-id` than `closerThan`. | ||
- If omitted the routing implementation should use its own [Peer ID](https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md). | ||
- `count` is an optional number that specifies how many peer records the requester desires. | ||
- Minimum 1, maximum 100, default 20. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think my assumption here is that the peers would be sorted by closeness value before the limit was applied. Would this not be the case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Yes that is correct. My point is that both E.g If none of Also, when setting |
||
|
||
#### Response Status Codes | ||
|
||
- `200` (OK): the response body contains peer records. | ||
- `404` (Not Found): must be returned if no matching records are found. | ||
- `422` (Unprocessable Entity): request does not conform to schema or semantic constraints. | ||
|
||
#### Response Headers | ||
|
||
- `Content-Type`: the content type of this response, which MUST be `application/json` or `application/x-ndjson` (see [streaming](#streaming)). | ||
- `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` | ||
- `Cache-Control: public, max-age={ttl}, public, stale-while-revalidate={max-ttl}, stale-if-error={max-ttl}`: meaningful cache TTL returned with the response. | ||
- When present, `ttl` SHOULD be shorter for responses whose resolution ended in no results (e.g. 15 seconds), | ||
and longer for responses that have results (e.g. 5 minutes). | ||
- Implementations SHOULD include `max-ttl`, set to the maximum cache window of the underlying routing system. | ||
For example, if Amino DHT results are returned, `stale-while-revalidate` SHOULD be set to `79200` (22h, which at the time of writing this specification, is the [Provider Record Republish Interval](https://github.com/libp2p/specs/tree/master/kad-dht#content-provider-advertisement-and-discovery)). | ||
- `Vary: Accept`: allows intermediate caches to play nicely with the different possible content types. | ||
|
||
#### Response Body | ||
|
||
```json | ||
{ | ||
"Peers": [ | ||
{ | ||
"Schema": "<schema>", | ||
"Protocols": ["<protocol-a>", "<protocol-b>", ...], | ||
"ID": "bafz...", | ||
"Addrs": ["/ip4/..."], | ||
... | ||
}, | ||
... | ||
] | ||
} | ||
``` | ||
|
||
The number of peer records in the responses SHOULD be limited to the `count` query parameter, which defaults to 20 if unspecified. | ||
|
||
The client SHOULD be able to make a request with `Accept: application/x-ndjson` and get a [stream](#streaming) with more results. | ||
|
||
Each object in the `Peers` list is a record conforming to the [Peer Schema](#peer-schema). | ||
|
||
### `GET /routing/v1/peers/{peer-id}` | ||
|
||
#### Path Parameters | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@achingbrain I think we could prototype this in https://github.com/ipfs-shipyard/someguy and deploy to https://delegated-ipfs.dev.
Priority-wise, and for the purpose of IPIP we will write for this at some point, does the utility here stops at finding Circuit Relay servers viable in browsers without being a DHT client?
Would it be useful to have API where the entire hash space could be queried for closest value, not just PeerIDs?
I wonder if this could be generalized into delegated
/routing/v1/closest/{cid}?[than]&[count]
where behind the scenes we prefix and turn peerids and cids to amindht hashes.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, there are other uses - you may wish to use this to populate your routing tables, or to find peers that can host provider records. It would be useful to perform these operations from environments that have limited resources or cannot open many concurrent connections, for example.
Yes, plus here the PeerIDs are represented as CIDs, so the above is something that can be performed.
To make this clearer it might be better specced as
{cid}
rather than{peer-id}
I guess.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: In many cases you'd want relay servers you'd also want peer routing (i.e. finding your address based on your peerID) which in the case of Amino means having recently pinged the closest peers to your peerID in XOR space. Ideally one of those (20) nodes is also acting as your relay which means the number of connections and queries you'd need are even smaller. So we don't really want a random walk we want to talk to specific peers when possible and only broaden the search if we have to.