Skip to content

Commit 970b81d

Browse files
authored
Merge pull request #417 from ipfs/ipip/schema-peer
IPIP-417: Delegated Peer Routing HTTP API
2 parents 9d9e50a + 95999ef commit 970b81d

File tree

2 files changed

+189
-55
lines changed

2 files changed

+189
-55
lines changed

src/ipips/ipip-0417.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
---
2+
title: "IPIP-0417: Delegated Peer Routing HTTP API"
3+
date: 2023-05-29
4+
ipip: proposal
5+
editors:
6+
- name: Henrique Dias
7+
github: hacdias
8+
url: https://hacdias.com/
9+
affiliation:
10+
name: Protocol Labs
11+
url: https://protocol.ai/
12+
relatedIssues:
13+
- https://github.com/ipfs/specs/pull/410
14+
- https://github.com/ipfs/kubo/pull/9877
15+
order: 417
16+
tags: ['ipips']
17+
---
18+
19+
## Summary
20+
21+
This IPIP specifies `/routing/v1/peers/{peer-id}` HTTP API to offload peer routing onto another server.
22+
23+
## Motivation
24+
25+
The motivation of this IPIP extends the one of :cite[ipip-0337] and :cite[ipip-0379],
26+
which introduced delegated content routing and delegated naming, respectively. Now,
27+
we expand upon those basis to introduce peer routing, reducing the barrier for interaction
28+
across different systems.
29+
30+
## Detailed design
31+
32+
Add `/routing/v1/peers/{peer-id}` to the existing :cite[http-routing-v1] specification,
33+
as well as the new Peer schema, that replaces the existing "known transfer protocols".
34+
35+
## Design rationale
36+
37+
In line with the remaining Routing V1 API, this IPIP introduces a new HTTP GET
38+
endpoint that is used to retrieve peer records for a certain peer.
39+
40+
### User benefit
41+
42+
The user benefit brought by this PR is similar to the one in :cite[ipip-0379],
43+
but instead of offloading the naming process, we offload the peer discovery and
44+
routing.
45+
46+
### Compatibility
47+
48+
The section "Known Transfer Protocols" has been removed and replaced by a "Known Schemas"
49+
section. Before, we used to have protocol specific schemas, such as `bitswap` and `graphsync-filecoinv1`.
50+
51+
The usage of these schemas is no longer encouraged. Instead, clients and
52+
servers SHOULD be updated to use the new, more generic, `peer` schema, which
53+
avoids returning the same peer multiple times, making results more efficient
54+
when a peer supports more than one protocol.
55+
56+
See more in the "Compatibility" section of :cite[ipip-0337].
57+
58+
### Security
59+
60+
See the "Security" section of :cite[ipip-0337].
61+
62+
### Alternatives
63+
64+
See the "Alternatives" section of :cite[ipip-0337].
65+
66+
### Copyright
67+
68+
Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).

src/routing/http-routing-v1.md

Lines changed: 121 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,31 @@ description: >
44
Delegated routing is a mechanism for IPFS implementations to use for offloading
55
content routing and naming to another process/server. This specification describes
66
an HTTP API for delegated content routing.
7-
date: 2023-03-22
7+
date: 2023-08-31
88
maturity: reliable
99
editors:
1010
- name: Gus Eggert
1111
github: guseggert
12+
affiliation:
13+
name: Protocol Labs
14+
url: https://protocol.ai/
1215
- name: Masih H. Derkani
1316
github: masih
17+
affiliation:
18+
name: Protocol Labs
19+
url: https://protocol.ai/
1420
- name: Henrique Dias
1521
url: https://hacdias.com/
1622
github: hacdias
23+
affiliation:
24+
name: Protocol Labs
25+
url: https://protocol.ai/
26+
- name: Marcin Rataj
27+
github: lidel
28+
url: https://lidel.org/
29+
affiliation:
30+
name: Protocol Labs
31+
url: https://protocol.ai/
1732
xref:
1833
- ipns-record
1934
order: 0
@@ -32,75 +47,89 @@ As such, human-readable encodings of types are preferred. This specification may
3247

3348
- CIDs are always string-encoded using a [multibase]-encoded [CIDv1].
3449
- Multiaddrs are string-encoded according to the [human-readable multiaddr specification][multiaddr].
35-
- Peer IDs are string-encoded according [PeerID string representation specification][peer-id-representation].
50+
- Peer IDs are string-encoded according [PeerID string representation specification][peer-id-representation]: either a Multihash in Base58btc, or a CIDv1 with libp2p-key (`0x72`) codec.
3651
- Multibase bytes are string-encoded according to [the Multibase spec][multibase], and SHOULD use base64.
3752
- Timestamps are Unix millisecond epoch timestamps.
3853

3954
Until required for business logic, servers should treat these types as opaque strings, and should preserve unknown JSON fields.
4055

41-
### Versioning
56+
## Versioning
4257

4358
This API uses a standard version prefix in the path, such as `/v1/...`. If a backwards-incompatible change must be made, then the version number should be increased.
4459

45-
### Provider Records
60+
## Content Routing API
4661

47-
A provider record contains information about a content provider, including the transfer protocol and any protocol-specific information useful for fetching the content from the provider.
62+
### `GET /routing/v1/providers/{cid}`
4863

49-
The information required to write a record to a router (*"write" provider records*) may be different than the information contained when reading provider records (*"read" provider records*).
64+
#### Path Parameters
5065

51-
For example, indexers may require a signature in `bitswap` write records for authentication of the peer contained in the record, but the read records may not include this authentication information.
66+
- `cid` is the [CID](https://github.com/multiformats/cid) to fetch provider records for.
5267

53-
Both read and write provider records have a minimal required schema as follows:
68+
#### Response Status Codes
69+
70+
- `200` (OK): the response body contains 0 or more records.
71+
- `404` (Not Found): must be returned if no matching records are found.
72+
- `422` (Unprocessable Entity): request does not conform to schema or semantic constraints.
73+
74+
#### Response Body
5475

5576
```json
5677
{
57-
"Protocol": "<transfer_protocol_name>",
58-
"Schema": "<transfer_protocol_schema>",
78+
"Providers": [
79+
{
80+
"Schema": "<schema>",
81+
"ID": "bafz...",
82+
"Addrs": ["/ip4/..."],
83+
...
84+
},
5985
...
86+
]
6087
}
6188
```
6289

63-
Where:
90+
The `application/json` responses SHOULD be limited to 100 providers.
6491

65-
- `Protocol` is the multicodec name of the transfer protocol or an opaque string (for experimenting with novel protocols without a multicodec)
66-
- `Schema` denotes the schema to use for encoding/decoding the record
67-
- This is separate from the `Protocol` to allow this HTTP API to evolve independently of the transfer protocol
68-
- Implementations should switch on this when parsing records, not on `Protocol`
69-
- `...` denotes opaque JSON, which may contain information specific to the transfer protocol
92+
The client SHOULD be able to make a request with `Accept: application/x-ndjson` and get a [stream](#streaming) with more results.
7093

71-
Specifications for some transfer protocols are provided in the "Transfer Protocols" section.
94+
Each object in the `Providers` list is a record conforming to a schema, usually the [Peer Schema](#peer-schema).
7295

73-
## Content Providers API
96+
## Peer Routing API
7497

75-
### `GET /routing/v1/providers/{cid}`
98+
### `GET /routing/v1/peers/{peer-id}`
7699

77100
#### Path Parameters
78101

79-
- `cid` is the [CID](https://github.com/multiformats/cid) to fetch provider records for.
102+
- `peer-id` is the [Peer ID](https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md) to fetch peer records for,
103+
represented as a CIDv1 encoded with `libp2p-key` codec.
80104

81105
#### Response Status Codes
82106

83-
- `200` (OK): the response body contains 0 or more records.
107+
- `200` (OK): the response body contains the peer record.
84108
- `404` (Not Found): must be returned if no matching records are found.
85109
- `422` (Unprocessable Entity): request does not conform to schema or semantic constraints.
86110

87111
#### Response Body
88112

89113
```json
90114
{
91-
"Providers": [
115+
"Peers": [
92116
{
93-
"Protocol": "<protocol_name>",
94117
"Schema": "<schema>",
118+
"Protocols": ["<protocol-a>", "<protocol-b>", ...],
119+
"ID": "bafz...",
120+
"Addrs": ["/ip4/..."],
95121
...
96-
}
122+
},
123+
...
97124
]
98125
}
99126
```
100127

101-
Response limit: 100 providers
128+
The `application/json` responses SHOULD be limited to 100 peers.
129+
130+
The client SHOULD be able to make a request with `Accept: application/x-ndjson` and get a [stream](#streaming) with more results.
102131

103-
Each object in the `Providers` list is a *read provider record*.
132+
Each object in the `Peers` list is a record conforming to the [Peer Schema](#peer-schema).
104133

105134
## IPNS API
106135

@@ -123,7 +152,7 @@ Each object in the `Providers` list is a *read provider record*.
123152

124153
#### Response Body
125154

126-
The response body contains a :ref[IPNS Record] serialized using the verifiable [`application/vnd.ipfs.ipns-record`](https://www.iana.org/assignments/media-types/application/vnd.ipfs.ipns-record) protobuf format.
155+
The response body contains a :ref[IPNS Record] serialized using the verifiable [`application/vnd.ipfs.ipns-record`](https://www.iana.org/assignments/media-types/application/vnd.ipfs.ipns-record) protobuf format.
127156

128157
### `PUT /routing/v1/ipns/{name}`
129158

@@ -163,7 +192,7 @@ with one result per line:
163192

164193
:::note
165194

166-
Streaming is opt-in and backwards-compatibile with clients and servers that do
195+
Streaming is opt-in and backwards-compatible with clients and servers that do
167196
not support streaming:
168197

169198
- Requests without the `Accept: application/x-ndjson` header MUST default to
@@ -199,59 +228,96 @@ Access-Control-Allow-Origin: *
199228
Access-Control-Allow-Methods: GET, OPTIONS
200229
```
201230

202-
## Known Transfer Protocols
231+
## Known Schemas
203232

204-
This section contains a non-exhaustive list of known transfer protocols (by name) that may be supported by clients and servers.
233+
This section contains a non-exhaustive list of known schemas that MAY be supported by clients and servers.
205234

206-
### Bitswap
235+
### Peer Schema
207236

208-
- Multicodec name: `transport-bitswap`
209-
- Schema: `bitswap`
210-
- Specification: [ipfs/specs/BITSWAP.md](https://github.com/ipfs/specs/blob/main/BITSWAP.md)
237+
The `peer` schema represents an arbitrary peer.
211238

212-
#### Bitswap Read Provider Records
239+
```json
240+
{
241+
"Schema": "peer",
242+
"ID": "bafz...",
243+
"Addrs": ["/ip4/..."],
244+
"Protocols": ["transport-bitswap", ...]
245+
...
246+
}
247+
```
248+
249+
- `ID`: the [Peer ID][peer-id] as Multihash in Base58btc or CIDv1 with libp2p-key codec.
250+
- `Addrs`: an optional list of known [multiaddrs][multiaddr] for this peer.
251+
- If missing or empty, it means the router server is missing that information, and the client should use `ID` to lookup updated peer information.
252+
- `Protocols`: an optional list of protocols known to be supported by this peer.
253+
- If missing or empty, it means the router server is missing that information, and the client should use `ID` and `Addrs` to lookup connect to the peer and use the [libp2p identify protocol](https://github.com/libp2p/specs/tree/master/identify) to learn about supported ones.
254+
255+
:::note
256+
257+
To allow for protocol-specific fields and future-proofing, the parser MUST
258+
allow for unknown fields, and the clients MUST ignore unknown ones.
259+
260+
Below is an example on how one could include `protocol-a` and `protocol-b`
261+
protocols that includes an additional fields `protocol-a` and `protocol-b`.
262+
263+
If the client knows the protocol, they are free to use the extra binary
264+
(base64) or JSON information contained in the additional field. If that is not
265+
the case, the field MUST be ignored.
213266

214267
```json
215268
{
216-
"Protocol": "transport-bitswap",
217-
"Schema": "bitswap",
218-
"ID": "12D3K...",
219-
"Addrs": ["/ip4/..."]
269+
"Schema": "peer",
270+
"ID": "bafz...",
271+
"Addrs": ["/ip4/..."],
272+
"Protocols": ["transport-bitswap", "protocol-a", "protocol-b", ...],
273+
"protocol-a": "[base64-blob]",
274+
"protocol-b": { "foo": "bar" }
220275
}
221276
```
222277

223-
- `ID`: the [Peer ID][peer-id] to contact
224-
- `Addrs`: a list of known multiaddrs for the peer
225-
- This list may be incomplete or incorrect and should only be treated as *hints* to improve performance by avoiding extra peer lookups
278+
:::
279+
280+
### Legacy Schemas
281+
282+
Legacy schemas include `ID` and optional `Addrs` list just like
283+
the [`peer` schema](#peer-schema) does.
284+
285+
These schemas are deprecated and SHOULD be replaced with `peer` over time, but
286+
MAY be returned by some legacy endpoints. In such case, a client MAY parse
287+
them the same way as the `peer` schema.
226288

227-
The server should respect a passed `transport` query parameter by filtering against the `Addrs` list.
289+
#### Bitswap Schema
228290

229-
### Filecoin Graphsync
291+
A legacy schema used by some routers to indicate a peer supports retrieval over
292+
the `/ipfs/bitswap[/*]` libp2p protocol.
293+
294+
```json
295+
{
296+
"Protocol": "transport-bitswap",
297+
"Schema": "bitswap",
298+
"ID": "bafz...",
299+
"Addrs": ["/ip4/..."]
300+
}
301+
```
230302

231-
- Multicodec name: `transport-graphsync-filecoinv1`
232-
- Schema: `graphsync-filecoinv1`
233-
- Specification: [ipfs/go-graphsync/blob/main/docs/architecture.md](https://github.com/ipfs/go-graphsync/blob/main/docs/architecture.md)
303+
#### Graphsync Schema
234304

235-
#### Filecoin Graphsync Read Provider Records
305+
A legacy schema used by some routers to indicate a peer supports retrieval over
306+
the [graphsync](https://github.com/ipfs/go-graphsync/blob/main/docs/architecture.md)
307+
libp2p protocol.
236308

237309
```json
238310
{
239311
"Protocol": "transport-graphsync-filecoinv1",
240312
"Schema": "graphsync-filecoinv1",
241-
"ID": "12D3K...",
313+
"ID": "bafz...",
242314
"Addrs": ["/ip4/..."],
243315
"PieceCID": "<cid>",
244316
"VerifiedDeal": true,
245317
"FastRetrieval": true
246318
}
247319
```
248320

249-
- `ID`: the [Peer ID][peer-id] of the provider
250-
- `Addrs`: a list of known multiaddrs for the provider
251-
- `PieceCID`: the CID of the [piece](https://spec.filecoin.io/systems/filecoin_files/piece/#section-systems.filecoin_files.piece) within which the data is stored
252-
- `VerifiedDeal`: whether the deal corresponding to the data is verified
253-
- `FastRetrieval`: whether the provider claims there is an unsealed copy of the data available for fast retrieval
254-
255321
[multibase]: https://github.com/multiformats/multibase
256322
[CIDv1]: https://github.com/multiformats/cid#cidv1
257323
[multiaddr]: https://github.com/multiformats/multiaddr#specification

0 commit comments

Comments
 (0)