Skip to content
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

add provide messages in reframe #285

Merged
merged 4 commits into from
Aug 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 59 additions & 3 deletions reframe/REFRAME_KNOWN_METHODS.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Request union {
| "FindProvidersRequest" FindProvidersRequest
| "GetIPNSRequest" GetIPNSRequest
| "PutIPNSRequest" PutIPNSRequest
| "ProvideRequest" ProvideRequest
}
```

Expand All @@ -50,6 +51,7 @@ type Response union {
| "FindProvidersResponse" FindProvidersResponse
| "GetIPNSResponse" GetIPNSResponse
| "PutIPNSResponse" PutIPNSResponse
| "ProvideResponse" ProvideResponse
| "Error" Error
}
```
Expand Down Expand Up @@ -131,9 +133,9 @@ Note: While the Key is a CID it is highly recommended that server implementation
}

type Provider struct {
Node Node
Proto optional [TransferProtocol]
}
Node Node
Proto optional [TransferProtocol]
}

# Note: This is not quite valid IPLD Schema because having fallbacks within unions is not yet implemented and codified https://github.com/ipld/ipld/issues/194. We will use this syntax within this spec though.

Expand Down Expand Up @@ -261,6 +263,60 @@ Response:
{"PutIPNSResponse : {}"}
```

### Provide

A message for indicating that the client is able to act as a provider for a given key.

```ipldsch
type ProvideRequest struct
Key &Any
Provider Provider
Timestamp Integer
AdvisoryTTL Integer
Signature Bytes
}

type ProvideResponse struct {
AdvisoryTTL Integer
}
```

Note: While the Key is a CID, it is highly recommended that server implementations treat these Requests as if they were for the multihash.

There are a a few semantics relevant to the construction of a ProvideRequest:

* The timestamp should be the current unix timestamp, encoded in an int64
* AdvistoryTTL may list the time for which the provider desires the content will remain available. If the provider cannot not anticipate how long the content will remain available, it may use a 0 value for this field.
* The AdvisoryTTL response may provide an expectation from the reframe endpoint of how long the content will remain available.
* If it is less than the requested TTL from the request, it indicates that the client should re-issue a ProvideRequest for the content by that point.
* If it is greater than the clients request, it indicates that the client may be perceived as responsible for the content for up to that amount of time.
* If it is 0, the endpoint is indicating it cannot make any claims about the lifetime of the request.
* Construction of the Signature is performed as follows:
1. Create the ProviderRequest struct, with empty bytes for Signature
2. Serialize the ProviderRequest as DagJSON
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fwiw In IPNS V2 we sign a DAG-CBOR document.

Not sure if this is a controversial take, but I expect people will ask us to allow more compact DAG-CBOR instead of DAG-JSON on the wire. In that future, requirement to use JSON here will work, but look really awkward.

Maybe it is a good idea to use CBOR from the beginning?
(as a side benefit, CBOR will be more efficient than JSON: less bytes to hash)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also second CBOR specifically for data compaction reasons - to reduce snapshot size of the larger nodes.

3. Hash the serialization with Sha256
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it feels off, hardcoding hash in provider request spec like this is not following the spirit of Multiformats.

Should we add an escape hatch for signaling function without having to rewrite all clients and all servers?

Sadly "multisig" it does not exist: multiformats/multiformats#23).

4. Sign the Hash using the keypair associated with the Provider.ID


#### Provide DAG-JSON Examples

Request:
```json
{"ProvideRequest" : {
"Key" : {"/":{"bytes":"AXIUBPnagss"}},
"Providers" : [
{"Node":{"Peer":{"ID":{
"/":{"bytes":"EncodedPeerID"}}
}}}
]
}}
```

Response:
```json
{"ProvideResponse : {}"}
```

## Method Upgrade Paths

It is acknowledged that the initial methods and mechanisms of this protocol will likely need to change over time and that we should prepare for how to do so without the need to wholesale replace this protocol with an alternative.
Expand Down