Skip to content
Snippets Groups Projects
Commit 154adda5 authored by Hugo Trentesaux's avatar Hugo Trentesaux Committed by Éloïs
Browse files

wip CBOR

parent 8e4eedc2
No related branches found
No related tags found
No related merge requests found
...@@ -89,7 +89,29 @@ The PEG grammars of raw formats are presented according to the [pest syntax] (a ...@@ -89,7 +89,29 @@ The PEG grammars of raw formats are presented according to the [pest syntax] (a
[PEG grammar]: https://en.wikipedia.org/wiki/Parsing_expression_grammar [PEG grammar]: https://en.wikipedia.org/wiki/Parsing_expression_grammar
[pest syntax]: https://pest.rs/book/grammars/syntax.html [pest syntax]: https://pest.rs/book/grammars/syntax.html
## Common structures
A certain number of structure like hash appear repeatedly in the messages. Here we describe it once and refer to it later.
### 32 byte number
A 32-bytes number is represented in JSON by an array of 32 8-bits numbers.
```json
[8, 56, 211, ..., 12] // array of 32 8-bits numbers
```
### 64 byte number
A 64-bytes number is represented in JSON by an array of 64 8-bits numbers.
```json
[8, 56, 211, ..., 12] // array of 64 8-bits numbers
```
### Hash, Pubkey, Signature
Hashes or pubkeys or signatures are just numbers, most often 32B or 64B one.
## Message encapsulation ## Message encapsulation
...@@ -108,7 +130,7 @@ All WS2Pv2 messages are structured as follows (CBOR format) : ...@@ -108,7 +130,7 @@ All WS2Pv2 messages are structured as follows (CBOR format) :
"issuer_node_id": 395, "issuer_node_id": 395,
"issuer_pubkey": { "issuer_pubkey": {
"algo": "Ed25519", "algo": "Ed25519",
"content": [52, 147, .., 93], // Array of 32 bytes "content": [52, 147, .., 93], // 32 bytes pubkey
}, },
"payload": { "payload": {
"type": "MESSAGE_TYPE_NAME", "type": "MESSAGE_TYPE_NAME",
...@@ -238,7 +260,7 @@ The signed key must be signed with the blockstamp corresponding to the date of s ...@@ -238,7 +260,7 @@ The signed key must be signed with the blockstamp corresponding to the date of s
"currency_name": "g1", "currency_name": "g1",
"issuer": { "issuer": {
"algo": "Ed25519", "algo": "Ed25519",
"content": [122, 11, .., 95] // Array of 32 bytes numbers "content": [122, 11, .., 95] // 32 bytes pubkey
}, },
"node_id": 10623, "node_id": 10623,
"created_on": 542, "created_on": 542,
...@@ -246,21 +268,21 @@ The signed key must be signed with the blockstamp corresponding to the date of s ...@@ -246,21 +268,21 @@ The signed key must be signed with the blockstamp corresponding to the date of s
"endpoints_str": [], // Array of Strings (endpoitn v2 in utf8 format) "endpoints_str": [], // Array of Strings (endpoitn v2 in utf8 format)
"sig": { "sig": {
"algo": "Ed25519", "algo": "Ed25519",
"content": [187, 7, .., 23] // Array of 64 bytes numbers "content": [187, 7, .., 23] // 64 bytes signature
}, },
"certifiers": [ "certifiers": [
{ {
"certifier": { "certifier": {
"algo": "Ed25519", "algo": "Ed25519",
"content": [122, 11, .., 95] // Array of 32 bytes numbers "content": [122, 11, .., 95] // 32 bytes pubkey
}, },
"blockstamp": { "blockstamp": {
"id": 327, "id": 327,
"hash": [85, 132, .., 27] // Array of 32 bytes numbers "hash": [85, 132, .., 27] // 32 bytes hash
}, },
"sig": { "sig": {
"algo": "Ed25519", "algo": "Ed25519",
"content": [187, 7, .., 23] // Array of 64 bytes numbers "content": [187, 7, .., 23] // 64 bytes signature
}, },
} }
] ]
...@@ -436,7 +458,12 @@ WARNING: independently of all these rules, each implementation must integrate it ...@@ -436,7 +458,12 @@ WARNING: independently of all these rules, each implementation must integrate it
### CONNECT message ### CONNECT message
```json ```json
{} // TODO {
"challenge": [...], // 32 bytes hash
"api_features": [...], // list of 4 integers corresponding to api_features (see in endpoint definition)
"connect_type": {...}, // see below
"peer_card": {...} // look at the peercard definition above
}
``` ```
challenge := random hash generated by the sending node of the CONNECT message, the receiving node will then have to sign this challenge and then send this signature in its ACK message to prove that it has the corresponding private key to the public key it indicates. challenge := random hash generated by the sending node of the CONNECT message, the receiving node will then have to sign this challenge and then send this signature in its ACK message to prove that it has the corresponding private key to the public key it indicates.
...@@ -449,12 +476,42 @@ peer_card := See PeerCard above ...@@ -449,12 +476,42 @@ peer_card := See PeerCard above
#### ConnectType type definition #### ConnectType type definition
TODO ConnectType represent the connection type. It can be:
- Incoming: *connect message sent when receiving an incoming websocket connection*
- Client: *connect message sent by a client*
- Server: *connect message sent between nodes for a normal connection*
- Sync: *connect message sent for a synchronization request*
- SyncAskChunk: *connect message sent for a chunk request*
Incoming, Client and Server are represented by a string.
Sync is represented by an object
```
{
"Sync": {
"from_blockstamp": "128310-000002A569DCEED62227CAC0ABDFE6B2647B21B3193A40398CD12BC2A95C24D9"
}
},
```
SyncAskChunk is reprensented by an object
```json
{
"SyncAskChunk": "128310-000002A569DCEED62227CAC0ABDFE6B2647B21B3193A40398CD12BC2A95C24D9",
}
```
### ACK message ### ACK message
```json ```json
{} // TODO {
"hash": [...] // 32 bytes hash
}
``` ```
Each node must sign the challenge of the other to prove that it's in possession of the private key corresponding to the public key under which it identifies. Each node must sign the challenge of the other to prove that it's in possession of the private key corresponding to the public key under which it identifies.
...@@ -465,7 +522,7 @@ The message is already signed at the container level, so there is no need to rep ...@@ -465,7 +522,7 @@ The message is already signed at the container level, so there is no need to rep
TODO TODO
If its valued, the `member_proof` field must contain a signature of the challenge* send by other node in their CONNECT message. If it is valued, the `member_proof` field must contain a signature of the challenge* send by other node in their CONNECT message.
_*It's the remote challenge for the signatory, and the local challenge for the verifier._ _*It's the remote challenge for the signatory, and the local challenge for the verifier._
...@@ -479,11 +536,13 @@ LOW_FLOW_DEMAND := The sender node of this message indicates that it's behind a ...@@ -479,11 +536,13 @@ LOW_FLOW_DEMAND := The sender node of this message indicates that it's behind a
### OK message ### OK message
In most cases, the OK message is empty (=3 zero-bytes), it simply indicates that the remote node accepts the connection establishment. If the local node has also sent an OK message, then it considers the connection as fully established. In most cases, the OK message is empty, it simply indicates that the remote node accepts the connection establishment. If the local node has also sent an OK message, then it considers the connection as fully established.
But sometimes the OK message can also transmit additional informations : But sometimes the OK message can also transmit additional informations :
```json ```json
{} // TODO {
"prefix": ... // null or non-zero integer
}
``` ```
prefix := In ws2p v2, member nodes have the option of not publicly communicating their prefix. It will only reveal their prefix to the node of their choice among those with which they establish a connection. For example, a member node may decide to share its prefix only with other member nodes of the same key. prefix := In ws2p v2, member nodes have the option of not publicly communicating their prefix. It will only reveal their prefix to the node of their choice among those with which they establish a connection. For example, a member node may decide to share its prefix only with other member nodes of the same key.
...@@ -492,7 +551,15 @@ If this field is zero, it means that the remote node does not want to reveal its ...@@ -492,7 +551,15 @@ If this field is zero, it means that the remote node does not want to reveal its
#### SYNC_INFO message #### SYNC_INFO message
```json ```json
{} // TODO {
"chunk_size": 500,
"target_blockstamp": {
"id": 0,
"hash": [...] // 32 bytes hash
},
"milestones": [...], // list of 32 bytes hashes
"peer_cards": [...] // list of peercards
}
``` ```
chunk_size := defines the size of the block used in milestones. A 1000-block chunk is a good compromise between efficiency of compression and duration of transfer chunk_size := defines the size of the block used in milestones. A 1000-block chunk is a good compromise between efficiency of compression and duration of transfer
...@@ -506,7 +573,7 @@ peer_cards := see [definition of binary peer card](#peer-card-binary-format) ...@@ -506,7 +573,7 @@ peer_cards := see [definition of binary peer card](#peer-card-binary-format)
### KO message ### KO message
```json ```json
{} // TODO 0 // number representing reason
``` ```
#### reason #### reason
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment