Skip to content

Commit 512bc05

Browse files
authored
Merge pull request #370 from ipfs/masih/rm_put_deleg_routing_api
Reduce the scope of IPIP-337 by excluding write operations
2 parents acc397b + 9c47a31 commit 512bc05

1 file changed

Lines changed: 38 additions & 115 deletions

File tree

routing/DELEGATED_CONTENT_ROUTING_HTTP.md

Lines changed: 38 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
![wip](https://img.shields.io/badge/status-wip-orange.svg?style=flat-square) Delegated Content Routing HTTP API
44

55
**Author(s)**:
6+
67
- Gus Eggert
78

89
**Maintainer(s)**:
@@ -13,25 +14,28 @@
1314

1415
"Delegated content routing" is a mechanism for IPFS implementations to use for offloading content routing to another process/server. This spec describes an HTTP API for delegated content routing.
1516

16-
# API Specification
17-
The Delegated Content Routing Routing HTTP API uses the `application/json` content type by default.
17+
## API Specification
18+
19+
The Delegated Content Routing Routing HTTP API uses the `application/json` content type by default.
1820

1921
As such, human-readable encodings of types are preferred. This spec may be updated in the future with a compact `application/cbor` encoding, in which case compact encodings of the various types would be used.
2022

21-
## Common Data Types:
23+
## Common Data Types
2224

2325
- CIDs are always string-encoded using a [multibase](https://github.com/multiformats/multibase)-encoded [CIDv1](https://github.com/multiformats/cid#cidv1).
2426
- Multiaddrs are string-encoded according to the [human-readable multiaddr specification](https://github.com/multiformats/multiaddr#specification)
2527
- Peer IDs are string-encoded according [PeerID string representation specification](https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md#string-representation)
26-
- Multibase bytes are string-encoded according to [the Multibase spec](https://github.com/multiformats/multibase), and *should* use Base64.
28+
- Multibase bytes are string-encoded according to [the Multibase spec](https://github.com/multiformats/multibase), and *should* use base64.
2729
- Timestamps are Unix millisecond epoch timestamps
2830

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

3133
### Versioning
34+
3235
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.
3336

3437
### Provider Records
38+
3539
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.
3640

3741
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*).
@@ -48,7 +52,7 @@ Both read and write provider records have a minimal required schema as follows:
4852
}
4953
```
5054

51-
where:
55+
Where:
5256

5357
- `Protocol` is the multicodec name of the transfer protocol
5458
- `Schema` denotes the schema to use for encoding/decoding the record
@@ -58,26 +62,28 @@ where:
5862

5963
Specifications for some transfer protocols are provided in the "Transfer Protocols" section.
6064

61-
6265
## API
66+
6367
### `GET /routing/v1/providers/{CID}`
68+
6469
- Response codes
6570
- `200`: the response body contains 0 or more records
6671
- `404`: must be returned if no matching records are found
6772
- `422`: request does not conform to schema or semantic constraints
6873
- Response Body
69-
```json
70-
{
71-
"Providers": [
72-
{
73-
"Protocol": "<protocol_name>",
74-
"Schema": "<schema>",
75-
...
76-
}
77-
]
78-
}
79-
```
80-
74+
75+
```json
76+
{
77+
"Providers": [
78+
{
79+
"Protocol": "<protocol_name>",
80+
"Schema": "<schema>",
81+
...
82+
}
83+
]
84+
}
85+
```
86+
8187
- Default limit: 100 providers
8288
- Optional query parameters
8389
- `transfer` only return providers who support the passed transfer protocols, expressed as a comma-separated list of transfer protocol names such as `transfer=bitswap,filecoin-graphsync-v1`
@@ -86,52 +92,20 @@ Specifications for some transfer protocols are provided in the "Transfer Protoco
8692

8793
Each object in the `Providers` list is a *read provider record*.
8894

89-
### `PUT /routing/v1/providers`
90-
- Response Codes
91-
- `200`: the server processed the full list of provider records (possibly unsuccessfully, depending on the semantics of the particular records)
92-
- Request Body
93-
```json
94-
{
95-
"Providers": [
96-
{
97-
"Protocol": "<protocol_name>",
98-
"Schema": "bitswap",
99-
...
100-
}
101-
]
102-
}
103-
```
104-
105-
Each object in the `Providers` list is a *write provider record*.
106-
107-
- Response Body
108-
```json
109-
{
110-
"ProvideResults": [
111-
{ ... }
112-
]
113-
}
114-
```
115-
- `ProvideResults` is a list of results in the same order as the `Providers` in the request, and the schema of each object is determined by the `Protocol` of the corresponding write object (called "Write Provider Records Response" in the Known Transfer Protocols section)
116-
- This may contain output information such as TTLs, errors, etc.
117-
- It is undefined whether the server will allow partial results
118-
- The work for processing each provider record should be idempotent so that it can be retried without excessive cost in the case of full or partial failure of the request
119-
- Default limit of 100 keys per request
120-
- Implements pagination according to the Pagination section
121-
12295
## Pagination
12396

12497
APIs that return collections of results should support pagination as follows:
12598

12699
- If there are more results, then a `NextPageToken` field should include an opaque string value, otherwise it should be undefined
127100
- The value of `NextPageToken` can be specified as the value of a `pageToken` query parameter to fetch the next page
128-
- Character set is restricted to the regex `[a-zA-Z0-9-_.~]+`, since this is intended to be used in URLs
101+
- Character set is restricted to the regular expression `[a-zA-Z0-9-_.~]+`, since this is intended to be used in URLs
129102
- The client continues this process until `NextPageToken` is undefined or doesn't care to continue
130103
- A `pageLimit` query parameter specifies the maximum size of a single page
131104

132105
### Implementation Notes
133106

134-
Servers are required to return *at most* `pageLimit` results in a page. It is recommended for pages to be as dense as possible, but it is acceptable for them to return any number of items in the closed interval [0, pageLimit]. This is dependent on the capabilities of the backing database implementation. For example, a query specifying a `transfer` filter for a rare transfer protocol should not *require* the server to perform a very expensive database query for a single request. Instead, this is left to the server implementation to decide based on the constraints of the database.
107+
Servers are required to return *at most* `pageLimit` results in a page. It is recommended for pages to be as dense as possible, but it is acceptable for them to return any number of items in the closed interval [0, pageLimit]. This is dependent on the capabilities of the backing database implementation.
108+
For example, a query specifying a `transfer` filter for a rare transfer protocol should not *require* the server to perform a very expensive database query for a single request. Instead, this is left to the server implementation to decide based on the constraints of the database.
135109

136110
Implementations should encode into the token whatever information is necessary for fetching the next page. This could be a base32-encoded JSON object like `{"offset":3,"limit":10}`, an object ID of the last scanned item, etc.
137111

@@ -151,21 +125,23 @@ request to the endpoints defined in this specification, and read the received
151125
values. This means HTTP server implementing this API must (1) support
152126
[CORS preflight requests](https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request)
153127
sent as HTTP OPTIONS, and (2) always respond with headers that remove CORS
154-
limits, allowing every website to query the API for results:
128+
limits, allowing every site to query the API for results:
155129

156130
```plaintext
157131
Access-Control-Allow-Origin: *
158-
Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS
132+
Access-Control-Allow-Methods: GET, OPTIONS
159133
```
160134

161135
## Known Transfer Protocols
136+
162137
This section contains a non-exhaustive list of known transfer protocols (by name) that may be supported by clients and servers.
163138

164139
### Bitswap
140+
165141
Multicodec name: `transport-bitswap`
166142
Schema: `bitswap`
167143

168-
#### Read Provider Records
144+
#### Bitswap Read Provider Records
169145

170146
```json
171147
{
@@ -182,61 +158,12 @@ Schema: `bitswap`
182158

183159
The server should respect a passed `transport` query parameter by filtering against the `Addrs` list.
184160

185-
186-
#### Write Provider Records
187-
188-
```json
189-
{
190-
"Protocol": "transport-bitswap",
191-
"Schema": "bitswap",
192-
"Signature": "<signature>",
193-
"Payload": "<payload>"
194-
}
195-
```
196-
197-
- `Signature`: a multibase-encoded signature of the sha256 hash of the `Payload` field, signed using the private key of the Peer ID specified in the `Payload` JSON
198-
- Servers may ignore this field if they do not require signature verification
199-
- `Payload`: a string containing a serialized JSON object which conforms with the following schema:
200-
```json
201-
{
202-
"Keys": ["cid1", "cid2"],
203-
"Timestamp": 0,
204-
"AdvisoryTTL": 0,
205-
"ID": "12D3K...",
206-
"Addrs": ["/ip4/..."],
207-
}
208-
```
209-
- `Keys` is a list of the CIDs being provided
210-
- `Timestamp` is the current time
211-
- `AdvisoryTTL` is the time by which the caller expects the server to keep the record available
212-
- If this value is unknown, the caller may use a value of 0
213-
- `ID` is the peer ID that was used to sign the record
214-
- `Addrs` is a list of string-encoded multiaddrs
215-
216-
A 403 response code should be returned if the signature check fails.
217-
218-
Note that this only supports Peer IDs expressed as identity multihashes. Peer IDs with older key types that exceed 42 bytes are not verifiable since they only contain a hash of the key, not the key itself. Normally, if the Peer ID contains only a hash of the key, then the key is obtained out-of-band (e.g. by fetching the block via IPFS). If support for these Peer IDs is needed in the future, this spec can be updated to allow the client to provide the key and key type out-of-band by adding optional `PublicKey` and `PublicKeyType` fields, and if the Peer ID is a CID, then the server can verify the public key's authenticity against the CID, and then proceed with the rest of the verification scheme.
219-
220-
The `Payload` field is a string, not a proper JSON object, to prevent its contents from being accidentally parsed and re-encoded by intermediaries, which may change the order of JSON fields and thus cause the record to fail validation.
221-
222-
#### Write Provider Records Response
223-
```json
224-
{
225-
"AdvisoryTTL": 0
226-
}
227-
```
228-
229-
- `AdvisoryTTL` is the time at which the server expects itself to drop the record
230-
- If less than the `AdvisoryTTL` in the request, then the client should re-issue the request by that point
231-
- If greater than the `AdvisoryTTL` in the request, then the server expects the client to be responsible for the content for up to that amount of time (TODO: this is ambiguous)
232-
- If 0, the server makes no claims about the lifetime of the record
233-
234-
235161
### Filecoin Graphsync
162+
236163
Multicodec name: `transport-graphsync-filecoinv1`
237164
Schema: `graphsync-filecoinv1`
238165

239-
#### Read Provider Records
166+
#### Filecoin Graphsync Read Provider Records
240167

241168
```json
242169
{
@@ -251,11 +178,7 @@ Schema: `graphsync-filecoinv1`
251178
```
252179

253180
- `ID`: the peer ID of the provider
254-
- `Addrs`: a list of known multiaddrs for the peer
255-
- `PieceCID`:
256-
- `VerifiedDeal`:
257-
- `FastRetrieval`:
258-
259-
#### Write Provider Records
260-
261-
There is currently no specified schema.
181+
- `Addrs`: a list of known multiaddrs for the provider
182+
- `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
183+
- `VerifiedDeal`: whether the deal corresponding to the data is verified
184+
- `FastRetrieval`: whether the provider claims there is an unsealed copy of the data available for fast retrieval

0 commit comments

Comments
 (0)