From 230092ab2ad9bab86fd9002a71e5ba46066bdaf7 Mon Sep 17 00:00:00 2001 From: Louis Royer Date: Wed, 25 Mar 2020 14:05:48 +0100 Subject: [PATCH] Update protocol.md Fix #42 --- doc/protocol.md | 71 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 59 insertions(+), 12 deletions(-) diff --git a/doc/protocol.md b/doc/protocol.md index 64dae57..3bc45b1 100644 --- a/doc/protocol.md +++ b/doc/protocol.md @@ -2,7 +2,7 @@ All strings in the datagram are utf-8 encoded. -```Datagram format +```text 1 byte: [(byte 0 ): VERSION(0x11, first quartet is major version, second is minor)] 1 byte: [(byte 1 ): REQUEST/RESPONSE CODE] @@ -20,12 +20,15 @@ x bytes: [(bytes 8-?): PAYLOAD] - `DISCOVER` (0x03) - `REGISTER` (0x04) - `UNREGISTER` (0x05) + - `RATIO` (0x06) + - `UPDATE RATIO` (0x07) - RESPONSES (msb is 1): - `LIST` (0x80) - `LOAD` (0x81) - `HASH` (0x82) - `DISCOVER` (0x83) + - `RATIO` (0x86) - `VERSION ERROR` (0xC0) - `PROTOCOL ERROR` (0xC1) - `INTERNAL ERROR` (0xC2) @@ -33,6 +36,8 @@ x bytes: [(bytes 8-?): PAYLOAD] - `NOT FOUND` (0xC4) - `EMPTY FILE` (0xC5) - `NOT A TRACKER` (0xC6) + - `UNKNOWN HOST` (0xC7) + - `DENIED` (0xC8) ### List Payload size for list request is always zero. @@ -52,7 +57,7 @@ Payload size for Not found is zero. #### Load response Payload contains -``` +```text 8 bytes: [(bytes 8-15): OFFSET OF FILE CONTENT IN BYTES] 8 bytes: [(bytes 16-23): TOTAL FILESIZE] 4 bytes: [(bytes 24-27): FILENAME SIZE] (cannot be > to PAYLOAD_SIZE - 20 or be zero) @@ -63,18 +68,21 @@ z bytes: [PARTIAL CONTENT] #### Load request Payload contains -``` +```text 8 bytes: [(bytes 8-15): OFFSET OF FILE CONTENT IN BYTES] 8 bytes: [(bytes 16-23): MAX SIZE OF PARTIAL CONTENT (partial content in response should not excess this size, but this can be less (by example if endoffile is reached or server doesn't have the full block requested) 4 bytes: [(bytes 24-27): FILENAME SIZE] (cannot be > to PAYLOAD_SIZE - 20 or be zero) y bytes: [] +2 bytes: port used to register on tracker +? bytes: hostname used to register on tracker followed by \n ``` +Possible responses: Load Response, or Denied -### Hash +### Hash #### Hash request Get hash of a file. Payload contains -``` +```text 4 bytes: [(bytes 8-11): FILENAME SIZE] y bytes: [] z bytes: [ALGO_NAMES requested separated by \n] (ex.: SHA-256, MD5) @@ -86,7 +94,7 @@ If file does not exists, a NotFound can be responded. Payload contains: -``` +```text 4 bytes: [(bytes 8-11): FILENAME SIZE] y bytes: [] [[ multiple algo hashes bloc]] @@ -94,7 +102,7 @@ y bytes: [] A algo hash bloc contains: -``` +```text 4 bytes [ALGO_NAME size] ? [ALGO_NAME] 4 bytes: [HASH SIZE (bytes)] / or 0 if this hash algorithm is unsupported. @@ -108,7 +116,7 @@ Used by a server to register itself on a tracker. Server may want to do a free `DISCOVER` to check if they have been registered. Payload contains: -``` +```text 2 bytes: [] ``` @@ -118,7 +126,7 @@ No error is raised if the server was not registered. Server may want to do a free `DISCOVER` to check if they have been unregistered. Payload contains: -``` +```text 2 bytes: [] ? bytes: [] ``` @@ -127,14 +135,14 @@ Payload contains: If payload size is null, lists all servers registered. If payload contains a filename, list all servers having this file in their list. -``` +```text ? bytes: [] ? bytes: [] ``` #### Discover response Contains: -``` +```text 4 bytes: [(bytes 8-11): FILENAME SIZE] y bytes: [] ? bytes [multiple server blocks] @@ -142,7 +150,7 @@ y bytes: [] Server block is composed with: -``` +```text 2 bytes: [port] ? bytes: hostname \n @@ -152,6 +160,45 @@ Server block is composed with: This error is raised when receiving a DISCOVER, a REGISTER, or an UNREGISTER request, but this application is not a tracker. +#### Ratio Request +Contains: +```text +2 bytes: port +? bytes: hostname +``` +Possible responses: Ratio Response, or Unknown Host + +#### Ratio Response +Contains: +```text +2 bytes: port +? bytes: hostname followed by \n +8 bytes: total sent bytes +8 bytes: total received bytes +``` + +#### Update Ratio +Contains: +```text +2 bytes: server port +2 bytes: client* port +? bytes: server hostname followed by \n +? bytes: client* hostname +* note: used by client to register on tracker +``` +Possible responses: No response, or Unknown Host (if client is not registered or server is not registered) + +Note: client must have verified hash before sending Update Ratio to tracker for each server which participated. + +#### Unknown Host +Payload size is zero. + +#### Denied +Contains +```text +?bytes: filename +``` + ### Other response code (errors) #### Version error Response when datagram received use wrong version code.