From a238b4f4a69188268b24261d385679b27aced95c Mon Sep 17 00:00:00 2001
From: librelois <elois@ifee.fr>
Date: Sun, 9 Sep 2018 18:34:45 +0200
Subject: [PATCH] [fix] ws2pv2 : Readjusting the REQUESTS_RESPONSES message

---
 rfc/0006_ws2p_v2.md | 65 +++++++++++++++++++++++++++++++--------------
 1 file changed, 45 insertions(+), 20 deletions(-)

diff --git a/rfc/0006_ws2p_v2.md b/rfc/0006_ws2p_v2.md
index f957623..210ca5c 100644
--- a/rfc/0006_ws2p_v2.md
+++ b/rfc/0006_ws2p_v2.md
@@ -605,12 +605,12 @@ WARNING : Exception with the ABF api feature : In a WS2P connection between two
 
 ### REQUESTS
 
-| data name    | size in bytes | data type |
-|:------------:|---------------|-----------|
-| request_id   | 4             | u32       |
-| request_type | 1             | u8        |
-| param_1      | ?             | ?         |
-| param_2      | ?             | ?         |
+| data name    | size in bytes | data type   |
+|:------------:|---------------|-------------|
+| request_id   | 4             | u32         |
+| request_type | 1             | u8          |
+| param_1      | ?             | ?           |
+| param_2      | ?             | ?           |
 
 #### request_type interpretation
 
@@ -634,39 +634,64 @@ _*This is part of the specificities of WS2P requests in binary format, which wil
 
 ### REQUESTS RESPONSES
 
+| data name        | size in bytes | data type  |
+|:----------------:|---------------|------------|
+| request_id       | 4             | u32        |
+| response_type    | 1             | u8         |
+| response_content | ?             | ?          |
+
+#### response_type interpretation
+
+| value | significance       |
+|:-----:|--------------------|
+| 0x00  | EMPTY_RESPONSE     |
+| 0xff  | BAD_REQUEST        |
+| 0x01  | CURRENT_BLOCKSTAMP |
+| 0x02  | BLOCKS_HASHS       |
+| 0x03  | CHUNK              |
+| 0x05  | WOT_POOL           |
+
+EMPTY_RESPONSE := `response_content` field is absent.
+
+BAD_REQUEST := Used only in debug mode. In production, bad requests are simply ignored (The server does not respond).
+
+#### BAD_REQUEST response
+
+| data name    | size in bytes | data type  |
+|:------------:|---------------|------------|
+| reason       | ?             | utf8       |
+
+_*The total payload size of any WS2P message is indicated in the metadata, field `reason` being the only one of unknown size, its size is deduced by calculation._
+
 #### CURRENT_BLOCKSTAMP response
 
 | data name    | size in bytes | data type  |
 |:------------:|---------------|------------|
-| request_id   | 4             | u32        |
 | blockstamp   | 36            | Blockstamp |
 
-#### SPECIFIC_BLOCK_HASH response
+#### BLOCKS_HASHS response
 
-| data name    | size in bytes | data type |
-|:------------:|---------------|-----------|
-| request_id   | 4             | u32       |
-| block_hash   | 32            | [u8; 32]  |
+| data name    | size in bytes  | data type     |
+|:------------:|----------------|---------------|
+| hashs        | 32*hashs_count | [[u8; 32]; ?] |
+
+_*The total payload size of any WS2P message is indicated in the metadata, field `hashs` being the only one of unknown size, its size is deduced by calculation._
 
-#### SYNC_CHUNK and CHUNK responses
+#### CHUNK response
 
 | data name    | size in bytes | data type            |
 |:------------:|---------------|----------------------|
-| request_id   | 4             | u32                  |
-| blocks_count | 2             | u16                  |
 | blocks       | ?             | (u16, BlockDocument) |
 
+_*The total payload size of any WS2P message is indicated in the metadata, field `blocks` being the only one of unknown size, its size is deduced by calculation._
 blocks := table of tuples (block_size, block_content)
 
-#### WOT_POOL responses
+#### WOT_POOL response
 
 | data name     | size in bytes | data type           |
 |:-------------:|---------------|---------------------|
-| request_id    | 4             | u32                 |
-| certs_count   | 2             | u16                 |
-| certs_size    | 2             | u16                 |
+| certs_size    | 4             | u32                 |
 | certs         | certs_size    | CompactPoolIntCert  |
-| folders_count | 4             | u32                 |
 | folders       | ?*            | PendingIdtyFolder   |
 
 _*The total payload size of any WS2P message is indicated in the metadata, field `folders` being the only one of unknown size, its size is deduced by calculation._
-- 
GitLab