You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: src/routing/http-routing-v1.md
+124-65
Original file line number
Diff line number
Diff line change
@@ -106,17 +106,27 @@ Each object in the `Providers` list is a record conforming to a schema, usually
106
106
107
107
```json
108
108
{
109
-
"Providers": [
110
-
{
111
-
"Protocol": "<protocol_name>",
112
-
"Schema": "bitswap",
113
-
...
114
-
}
115
-
]
109
+
"Providers": [
110
+
{
111
+
"Schema": "announcement",
112
+
...
113
+
}
114
+
]
116
115
}
117
116
```
118
117
119
-
Each object in the `Providers` list is a *write provider record*.
118
+
119
+
Each object in the `Providers` list is a *write provider record* entry.
120
+
121
+
Server SHOULD accept representing writes is [Announcement Schema](#announcement-schema).
122
+
123
+
:::warn
124
+
125
+
TODO: is below a sensible limit?
126
+
127
+
There SHOULD be no more than 100 `Providers` per request.
128
+
129
+
:::
120
130
121
131
#### `PUT` Response Body
122
132
@@ -130,9 +140,8 @@ Each object in the `Providers` list is a *write provider record*.
130
140
131
141
-`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
132
142
- This may contain output information such as TTLs, errors, etc.
133
-
- It is undefined whether the server will allow partial results
143
+
- It is undefined whether the server will allow partial results<!-- TODO: maybe add Error field to `announcement` schema and use it in responses ? -->
134
144
- 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
135
-
- Default limit of 100 keys per request
136
145
137
146
## Peer Routing API
138
147
@@ -155,10 +164,10 @@ represented as a CIDv1 encoded with `libp2p-key` codec.
@@ -172,6 +181,34 @@ The client SHOULD be able to make a request with `Accept: application/x-ndjson`
172
181
173
182
Each object in the `Peers` list is a record conforming to the [Peer Schema](#peer-schema).
174
183
184
+
### `PUT /routing/v1/peers`
185
+
186
+
#### `PUT` Response codes
187
+
188
+
-`200` (OK): the server processed the full list of provider records (possibly unsuccessfully, depending on the semantics of the particular records)
189
+
-`400` (Bad Request): the server deems the request to be invalid and cannot process it
190
+
-`422` (Unprocessable Entity): request does not conform to schema or semantic constraints
191
+
-`501` (Not Implemented): the server does not support providing records
192
+
193
+
#### `PUT` Request Body
194
+
195
+
```json
196
+
{
197
+
"Providers": [
198
+
{
199
+
"Schema": "announcement",
200
+
...
201
+
}
202
+
]
203
+
}
204
+
```
205
+
206
+
207
+
Each object in the `Providers` list is a *write provider record* entry.
208
+
209
+
Server SHOULD accept writes represented with [Announcement Schema](#announcement-schema)
210
+
objects with `CID` list.
211
+
175
212
## IPNS API
176
213
177
214
### `GET /routing/v1/ipns/{name}`
@@ -318,82 +355,104 @@ the case, the field MUST be ignored.
318
355
319
356
:::
320
357
321
-
### Legacy Schemas
358
+
### Announcement Schema
322
359
323
-
Legacy schemas include `ID` and optional `Addrs` list just like
324
-
the [`peer` schema](#peer-schema) does.
360
+
The `announcement` schema can be used in `PUT` operations to announce content providers or peer routing information.
325
361
326
-
These schemas are deprecated and SHOULD be replaced with `peer` over time, but
327
-
MAY be returned by some legacy endpoints. In such case, a client MAY parse
328
-
them the same way as the `peer` schema.
329
-
330
-
#### Bitswap Schema
331
-
332
-
A legacy schema used by some routers to indicate a peer supports retrieval over
333
-
the `/ipfs/bitswap[/*]` libp2p protocol.
334
362
335
363
```json
336
-
{
337
-
"Protocol": "transport-bitswap",
338
-
"Schema": "bitswap",
339
-
"ID": "bafz...",
340
-
"Addrs": ["/ip4/..."]
341
-
}
364
+
{
365
+
"Schema": "announcement",
366
+
"Payload": {
367
+
"CID": ["cid1", "cid2", ...],
368
+
"Scope": "block",
369
+
"Timestamp": "YYYY-MM-DDT23:59:59Z",
370
+
"TTL": 0,
371
+
"ID": "12D3K...",
372
+
"Addrs": ["/ip4/...", ...],
373
+
"Protocols": ["foo", ...],
374
+
"Metadata": "mbase64-blob",
375
+
},
376
+
"Signature": "mbase64-signature"
377
+
}
342
378
```
343
379
344
-
#### Bitswap Write Provider Records
380
+
-`Schema`: tells the server to interpret the JSON object as announce provider
381
+
-`Payload`: is a DAG-JSON-compatible object with a subset of the below fields
382
+
-`CID` is a list of the CIDs being provided.
383
+
- Skipped when used for `PUT /routing/v1/peers`
384
+
-`Scope` is an optional hint that provides semantic meaning about announced identifies:
385
+
-`block` announces only the individual blocks (implicit default if `Scope` is missing).
386
+
-`entity` announces enumerable entities behind the CIDs (e.g.: all blocks for UnixFS file or a minimum set of blocks to enumerate HAMT-sharded UnixFS directory).
387
+
-`recursive` announces entire DAGs behind the CIDs (e.g.: entire DAG-CBOR DAG, or everything in UnixFS directory, including all files in all subdirectories).
388
+
-`Timetamp` is the current time, formatted as an ASCII string that follows notation from [rfc3339](https://specs.ipfs.tech/ipns/ipns-record/#ref-rfc3339).
389
+
-`TTL` is caching and expiration hint informing the server how long to keep the record available, specified in milliseconds.
390
+
- If this value is unknown, the caller may skip this field, or use a value of 0. The server's default will be used.
391
+
-`ID` is Peer ID of the node that provides the content and also indicates the `libp2p-key` that SHOULD be used for verifying `Signature` field.
392
+
-`Addrs` is an a list of string-encoded multiaddrs without `/p2p/peerID` suffix.
393
+
-`Protocols` is a list of protocols supported by `ID` and/or `Addrs`, if known upfront.
394
+
-`Metadata` is a string with multibase-encoded binary metadata that should be passed as-is
395
+
-`Signature` is a string with multibase-encoded binary signature that provides integrity and authenticity of the `Payload` field.
396
+
- Signature is created by following below steps:
397
+
1. Convert `Payload` to deterministic, ordered [DAG-JSON](https://ipld.io/specs/codecs/dag-json/spec/) map notation
398
+
2. Prefix the DAG-JSON bytes with ASCII string `PUT /routing/v1 announcement:`
399
+
3. Sign the bytes with the private key of the Peer ID specified in the `Payload.ID`.
400
+
- Signing details for specific key types should follow [libp2p/peerid specs](https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md#key-types), unless stated otherwise.
401
+
- Client SHOULD sign every announcement.
402
+
- Servers SHOULD verify signature before accepting a record, unless running in a trusted environment.
403
+
- ED25519 and other small public keys MUST be inlined inside of the `ID` field with the identity multihash type.
404
+
- Key types that exceed 42 bytes (e.g. RSA) SHOULD NOT be inlined, the `ID` field should only include the multihash of the key. The key itself SHOULD be obtained out-of-band (e.g. by fetching the block via IPFS) and cached.
405
+
If support for big keys 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` 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.
406
+
- A [400 Bad Request](https://httpwg.org/specs/rfc9110.html#status.400) response code SHOULD be returned if the `Signature` check fails.
407
+
408
+
:::warn
409
+
410
+
TODO: what should be the limits? Max number of CIDs per `announcement` ?
411
+
412
+
:::
413
+
414
+
#### Use in PUT responses
415
+
416
+
Server MAY return additional TTL information if the TTL is not provided in the request,
417
+
or if server policy is to provide TTL different than the requested one.
345
418
346
419
```json
347
420
{
348
-
"Protocol": "transport-bitswap",
349
-
"Schema": "bitswap",
350
-
"Signature": "<signature>",
351
-
"Payload": "<payload>"
421
+
"Schema": "announcement",
422
+
"Payload": {
423
+
"TTL": 17280000
424
+
}
352
425
}
353
426
```
354
427
355
-
-`Signature`: a multibase-encoded signature of the sha256 multihash of the `Payload` field, signed using the private key of the Peer ID specified in the `Payload` DAG-JSON. Signing details for specific key types should follow [libp2p/peerid specs](https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md#key-types), unless stated otherwise.
356
-
- Servers may ignore this field if they do not require signature verification.
357
-
-`Payload`: a string containing a serialized JSON object which conforms with the following schema:
358
-
359
-
```json
360
-
{
361
-
"Keys": ["cid1", "cid2"],
362
-
"Timestamp": 0,
363
-
"AdvisoryTTL": 0,
364
-
"ID": "12D3K...",
365
-
"Addrs": ["/ip4/..."]
366
-
}
367
-
```
428
+
-`TTL` in response is the time at which the server expects itself to drop the record
429
+
- If less than the `TTL` in the request, then the client SHOULD repeat announcement earlier, before the announcement TTL expires and is forgotten by the routing system
430
+
- If greater than the `TTL` in the request, then the server client SHOULD save resources and not repeat announcement until the announcement TTL expires and is forgotten by the routing system
431
+
- If `0`, the server makes no claims about the lifetime of the record
368
432
369
-
-`Keys` is a list of the CIDs being provided
370
-
-`Timestamp` is the current time, formatted as an ASCII string that follows notation from [rfc3339](https://specs.ipfs.tech/ipns/ipns-record/#ref-rfc3339)
371
-
-`AdvisoryTTL` is the time by which the caller expects the server to keep the record available, specified in milliseconds.
372
-
- If this value is unknown, the caller may use a value of 0
373
-
-`ID` is the peer ID that was used to sign the record
374
-
-`Addrs` is a list of string-encoded multiaddrs
433
+
### Legacy Schemas
375
434
376
-
A [400 Bad Request](https://httpwg.org/specs/rfc9110.html#status.400) response code should be returned if the signature check fails.
435
+
Legacy schemas include `ID` and optional `Addrs` list just like
436
+
the [`peer` schema](#peer-schema) does.
377
437
378
-
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.
379
-
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).
380
-
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.
438
+
These schemas are deprecated and SHOULD be replaced with `peer` over time, but
439
+
MAY be returned by some legacy endpoints. In such case, a client MAY parse
440
+
them the same way as the `peer` schema.
381
441
382
-
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.
442
+
#### Bitswap Schema
383
443
384
-
#### Write Provider Records Response
444
+
A legacy schema used by some routers to indicate a peer supports retrieval over
445
+
the `/ipfs/bitswap[/*]` libp2p protocol.
385
446
386
447
```json
387
448
{
388
-
"AdvisoryTTL": 0
449
+
"Protocol": "transport-bitswap",
450
+
"Schema": "bitswap",
451
+
"ID": "bafz...",
452
+
"Addrs": ["/ip4/..."]
389
453
}
390
454
```
391
455
392
-
-`AdvisoryTTL` is the time at which the server expects itself to drop the record
393
-
- If less than the `AdvisoryTTL` in the request, then the client should re-issue the request by that point
394
-
- 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)
395
-
- If 0, the server makes no claims about the lifetime of the record
396
-
397
456
#### Graphsync Schema
398
457
399
458
A legacy schema used by some routers to indicate a peer supports retrieval over
0 commit comments