Skip to content

Commit 9a19add

Browse files
committed
IPIP-379 Delegated Naming HTTP API
Propose HTTP APIs for delegated naming system that enables offloading of naming system to other processes or servers. Relates to: - #377 Fixes #343
1 parent 55c6a67 commit 9a19add

3 files changed

Lines changed: 257 additions & 2 deletions

File tree

IPIP/0337-delegated-routing-http-api.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ To understand the design rationale, it is important to consider the concrete Ref
6060
So this API proposal makes the following changes:
6161

6262
- The Delegated Content Routing API is defined using HTTP semantics, and can be implemented without introducing Reframe concepts nor IPLD
63-
- There is a clear distinction between the RPC protocol (HTTP) and the API (Deleged Content Routing)
63+
- There is a clear distinction between the RPC protocol (HTTP) and the API (Delegated Content Routing)
6464
- "Method names" and cache-relevant parameters are pushed into the URL path
6565
- Streaming support is removed, and default response size limits are added.
6666
- We will add streaming support in a subsequent IPIP, but we are trying to minimize the scope of this IPIP to what is immediately useful
@@ -70,7 +70,7 @@ So this API proposal makes the following changes:
7070
- Multiaddrs use the [human-readable format](https://github.com/multiformats/multiaddr#specification) that is used in existing tools and Kubo CLI commands such as `ipfs id` or `ipfs swarm peers`
7171
- Byte array values, such as signatures, are multibase-encoded strings (with an `m` prefix indicating Base64)
7272
- The "Identify" method and "message groups" are not included
73-
- The "GetIPNS" and "PutIPNS" methods are not included
73+
- The "GetIPNS" and "PutIPNS" methods are not included. Instead, a separate Delegated Naming HTTP API aims to firstly facilitate naming system delegation, and secondly, pave the way for future iterations of IPNS with less interdependency with content routing. For more information, see [Delegated Naming HTTP API](0337-delegated-naming-http-api.md).
7474

7575
### User benefit
7676

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# IPIP-379: Delegated Naming HTTP API
2+
3+
- Start Date: 2023-02-13
4+
- Related Issues:
5+
- https://github.com/ipfs/specs/issues/343
6+
- https://github.com/ipfs/specs/pull/337
7+
- https://github.com/ipfs/specs/pull/377
8+
9+
## Summary
10+
11+
This IPIP specifies a set of HTTP APIs to offload naming system onto aother process or server.
12+
13+
## Motivation
14+
15+
Expanding on the motivations of [IPIP-337 HTTP Delegated Routing](0337-delegated-routing-http-api.md), the work here concentrates on delegation of _naming system_ over HTTP APIs. Naming is part of the core IPFS DHT functionality.
16+
The performance of naming system over the IPFS DHT can suffer from long delays due to churn of records and quorum requirements.
17+
18+
## HTTP API Specification
19+
20+
See [Delegated Naming HTTP API](../routing/DELEGATED_NAMING_HTTP.md) specification.
21+
22+
## Design rationale
23+
24+
The rationale for delegated naming over HTTP APIs closely follows the reasoning listed in [IPIP-337](0337-delegated-routing-http-api.md#design-rationale).
25+
26+
The document proposes the following:
27+
- Use of HTTP semantics for publication and resolution of naming records.
28+
- Preference for human-readable request and response encoding, such as JSON format
29+
- Optional backward compatibility support for the existing ProtocolBuffer format using `Content-Type: application/x-protobuf; messageType="IpnsEntry"`
30+
- Use of extra headers in `OPTIONS` response to communicate the supported cpabilities and limitations, namely:
31+
- `X-Ipns-Allow-Max-Size` -- to signal maximum supported IPNS record size
32+
- `X-Ipns-Allow-Protobuf` -- to signal whether the server supports ProtocolBuffer formatted records.
33+
- Streaming interaction is not supported.
34+
35+
### User benefit
36+
37+
The ability of offload naming onto another process or server via an idiomatic and simple HTTP API opens up an opportunity to not only reduce the burden of naming system management, but also introduce alternative naming systems across other routing systems, namely IPNI.
38+
39+
### Compatibility
40+
41+
#### Backwards Compatibility
42+
43+
##### Serialization Format
44+
45+
IPNS records use [ProtocolBuffer serialisation format](../ipns/IPNS.md#record-serialization-format).
46+
This format is widely in use in IPNS over PubSub and DHT routing systems.
47+
One of the motivations of this document is to introduce simple to use HTTP APIs and ultimately reduce barrier for interaction across alternative systems.
48+
Further, interoperability across the existing and HTTP APIs is also desirable in order to reduce the barrier for adoption of the delegated HTTP APIs.
49+
50+
The specification here maintains backwards compatibility in terms of record serialisation, with preference for human-readable formats such as JSON.
51+
To maintain backwards compatibility, the implementers of the HTTP API should accept requests with following `Content-Type` header:
52+
- `application/x-protobuf; messageType="IpnsEntry"`
53+
54+
##### Reframe
55+
56+
See [IPIP-337/Backwards Compatibility](0337-delegated-routing-http-api.md#backwards-compatibility).
57+
58+
#### Forwards Compatibility
59+
60+
See [IPIP-337/Forwards Compatibility](0337-delegated-routing-http-api.md#forwards-compatibility).
61+
62+
### Security
63+
64+
All interaction over the APIs should use TLS to protect against third-party observation and tampering.
65+
Additionally, the IPNS records are signed by the publisher's identity and contain sequence number to avoid replay attacks.
66+
67+
To avoid Denial of Service attack, maximum IPNS record size of `10 KiB` applies.
68+
Implements are permitted to set a lower limit. If lower than the default maximum, the limit should be discoverable via `OPTIONS` request with header key `X-Ipns-Allow-Max-Size` with value specified as the number of bytes.
69+
70+
Similarly, a client may check if a server supports ProtocolBuffer formatted records by checking the `X-Ipns-Allow-Protobuf` header key in response to `OPTIONS` request. If present the header value must be either `true` or `false` the absence of the header indicates that ProtocolBuffer formatted records are not supported.
71+
72+
Privacy in delegated naming system is out of scope for this work.
73+
- The usual JSON parsing rules apply. To prevent potential Denial of Service (DoS) attack, clients should ignore responses larger than 100 providers and introduce a byte size limit that is applicable to their use case.
74+
75+
### Alternatives
76+
77+
See:
78+
- [Libp2p-based IPNS](https://github.com/ipfs/go-ipns).
79+
- Reframe; find out more on [IPIP-337 Design Rationale](0337-delegated-routing-http-api.md#design-rationale).
80+
81+
### Copyright
82+
83+
Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).

routing/DELEGATED_NAMING_HTTP.md

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
# Delegated Naming HTTP API
2+
3+
![wip](https://img.shields.io/badge/status-wip-orange.svg?style=flat-square)
4+
5+
**Author(s)**:
6+
7+
- [Masih H. Derkani](https://github.com/masih)
8+
9+
**Maintainer(s)**:
10+
11+
* * *
12+
13+
**Abstract**
14+
15+
Delegated naming is a mechanism for IPFS implementations to offload naming system to another process
16+
or server. This includes naming resolution as well as publication of new naming records. This
17+
document describes an HTTP API through which such functionality is facilitated.
18+
19+
## API Specification
20+
21+
The Delegated Naming System HTTP API uses the `application/json` content type by default.
22+
23+
As such, human-readable encodings of types are preferred. This spec may be updated in the future
24+
with a compact `application/cbor` encoding, in which case compact encodings of the various types
25+
would be used.
26+
27+
## Common Data Types
28+
29+
### IPNS Record
30+
31+
The following snippet outlines the JSON schema of IPNS records:
32+
33+
```json
34+
{
35+
"Signature": "<signature>",
36+
"Payload": {
37+
"Value": "<value>",
38+
"Sequence": 0,
39+
"Validity": {
40+
"EOL": {
41+
"Timestamp": 0,
42+
"AdvisoryTTL": 0
43+
}
44+
},
45+
"PublicKey": "<optional-public-key>",
46+
"ExtendedData": {}
47+
}
48+
}
49+
```
50+
51+
Where:
52+
53+
- `Signature` is the multibase-encoded signature of the sha256 hash of the `Payload` field, signed
54+
using the private key that corresponds to the `PublicKey` in the `Payload` if present. And
55+
Otherwise, the private key associcated to the IPNS record key. Signing details for specific key
56+
types should
57+
follow [libp2p/peerid specs](https://github.com/libp2p/specs/blob/master/peer-ids/peer-ids.md#key-types),
58+
unless stated otherwise.
59+
- `Payload` is the content of the IPNS record as specified
60+
by [IPNS Record](../ipns/IPNS.md#ipns-record) specification:
61+
- `Value` is the string representation of the IPNS path,
62+
e.g. `ipns/{ipns-key}`, `/ipns/example.com`, `/ipfs/baf...`, etc.
63+
- `Sequence` represents the current version of the record starting from `0`.
64+
- `Validity` captures the mechanism by which the record is validated. Each validity type reserves a
65+
field key under this object.
66+
- `EOL` donates that the validity type is EOL, containing:
67+
- `Timestamp` represents the time in the future at which the record expires with nanoseconds
68+
precision represented as an ASCII string that follows notation
69+
from [RFC3339](https://www.ietf.org/rfc/rfc3339.txt).
70+
- `AdvisoryTTL` represents an optional field that hints at how long the record should be
71+
cached.
72+
- `PublicKey` represents the optional public key used to sign the record. This field is only
73+
required if it cannot be extracted from the IPNS name, e.g. in the case of legacy RSA keys.
74+
- `ExtendedData` represents the extensible data as arbitrary JSON object.
75+
76+
## Versioning
77+
78+
The path predix `/v1` donates the version number of the HTTP API. Backwards-incompatible change must
79+
increment the version number.
80+
81+
## API
82+
83+
### `GET /naming/v1/records/{ipns-name}`
84+
85+
**Path Parameters**
86+
87+
- `ipns-name` the IPNS name to resolve.
88+
89+
**Response Status Codes**
90+
91+
- `200` (OK): indicates that the response body containing the IPNS record that corresponds to the
92+
IPNS name.
93+
- `404` (Not Found): indicates that no matching records are found.
94+
- `400` (Bad Request): indicates that the given IPNS name is not valid.
95+
- `429` (Too Many Requests): indicates that the caller is issuing requests too many request and may
96+
retry after the time specified
97+
at [Retry-After](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) response
98+
header has elapsed.
99+
- `501` (Not Implemented): indicates that the server does not support resolution of IPNS records
100+
101+
**Response Body**
102+
103+
The response body contains the [IPNS record](#ipns-record).
104+
105+
```json
106+
{
107+
"Signature": "<signature>",
108+
"Payload": {
109+
"Value": "<value>",
110+
"Sequence": 0,
111+
"Validity": {
112+
"EOL": {
113+
"Timestamp": 0,
114+
"AdvisoryTTL": 0
115+
}
116+
},
117+
"PublicKey": "<optional-public-key>",
118+
"ExtendedData": {}
119+
}
120+
}
121+
```
122+
123+
### `PUT /naming/v1/records`
124+
125+
**Request Body**
126+
127+
```json
128+
{
129+
"Signature": "<signature>",
130+
"Payload": {
131+
"Value": "<value>",
132+
"Sequence": 0,
133+
"Validity": {
134+
"EOL": {
135+
"Timestamp": 0,
136+
"AdvisoryTTL": 0
137+
}
138+
},
139+
"PublicKey": "<optional-public-key>",
140+
"ExtendedData": {}
141+
}
142+
}
143+
```
144+
145+
**Response Status Codes**
146+
147+
- `200` (OK): indicates that the response body containing the IPNS record that corresponds to the
148+
IPNS name.
149+
- `404` (Not Found): indicates that no matching records are found.
150+
- `400` (Bad Request): indicates that the given IPNS record is not valid.
151+
- `429` (Too Many Requests): indicates that the caller is issuing requests too many request and may
152+
retry after the time specified
153+
at [Retry-After](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Retry-After) response
154+
header has elapsed.
155+
- `501` (Not Implemented): indicates that the server does not support publication of IPNS records
156+
157+
## CORS and Web Browsers
158+
159+
Browser interoperability requires implementations to support
160+
[CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS).
161+
162+
JavaScript client running on a third-party Origin must be able to send HTTP request to the endpoints
163+
defined in this specification, and read the received values. This means HTTP server implementing
164+
this API must:
165+
166+
1. support [CORS preflight requests](https://developer.mozilla.org/en-US/docs/Glossary/Preflight_request) sent as HTTP OPTIONS, and
167+
2. always respond with headers that remove CORS limits, allowing every site to query the API for results:
168+
169+
```plaintext
170+
Access-Control-Allow-Origin: *
171+
Access-Control-Allow-Methods: GET, PUT, OPTIONS
172+
```

0 commit comments

Comments
 (0)