From 4410bfee99124a164b495d188e86276d5819b266 Mon Sep 17 00:00:00 2001 From: Louis Date: Sun, 26 Jan 2020 14:52:40 +0100 Subject: [PATCH] Edit protocol for step 2 --- doc/protocol.md | 42 ++++++++++++++++++------------------------ 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/doc/protocol.md b/doc/protocol.md index d5b9171..dae01e1 100644 --- a/doc/protocol.md +++ b/doc/protocol.md @@ -1,27 +1,14 @@ -# P2P-JAVA-PROJECT version 1 (Protocol for step 1) -All messages begins with `P2P-JAVA-PROJECT VERSION 1.0\n` (this version of the protocol). - -## Client messages -- `LIST\n`: ask the server to list files from server root directory -- `DOWNLOAD\n\n`: ask the server to download file from server root directory. Only one filename is allowed per request. - -## Server responses -- The response to `LIST` request is in the format `LIST\n\n\n[…]\n\n` -- The response to `DOWNLOAD` request is `LOAD\n\n\n` or `NOT FOUND\n` if the file doesn't exists. -- The server send a `PROTOCOL ERROR\n` message if it doesn't understands what the client sent. -- The server send a `INTERNAL ERROR\n` message if it encounters an internal error. - -# P2P-JAVA-PROJECT version 1.1 (Binary protocol for step 1) +# P2P-JAVA-PROJECT version 1.2 (Binary protocol for step 2) All strings in the datagram are utf-8 encoded. ```Datagram format -1 byte: [0-7: VERSION(0x11, first quartet is major version, second is minor)] -1 byte: [8-15: REQUEST/RESPONSE CODE] -2 bytes: [16-31: RESERVED FOR FUTURE USE] -4 bytes: [32-63: PAYLOAD SIZE IN BYTES] -x bytes: [64-xx: PAYLOAD] +1 byte: [0-7 (byte 0 ): VERSION(0x11, first quartet is major version, second is minor)] +1 byte: [8-15 (byte 1 ): REQUEST/RESPONSE CODE] +2 bytes: [16-31 (bytes 2-3): RESERVED FOR FUTURE USE] +4 bytes: [32-63 (bytes 4-7): PAYLOAD SIZE IN BYTES] +x bytes: [64-xx (bytes 8-?): PAYLOAD] ``` @@ -59,15 +46,22 @@ Payload size for Not found is zero. Payload contains ``` -8 bytes: [64-127: OFFSET OF FILE CONTENT IN BYTES] -8 bytes: [128-191: TOTAL FILESIZE] -4 bytes: [192-223: FILENAME SIZE] (cannot be > to PAYLOAD_SIZE - 20 or be zero) +8 bytes: [64-127 (bytes 8-16): OFFSET OF FILE CONTENT IN BYTES] +8 bytes: [128-191 (bytes 17-24): TOTAL FILESIZE] +4 bytes: [192-223 (bytes 25-28): FILENAME SIZE] (cannot be > to PAYLOAD_SIZE - 20 or be zero) y bytes: [] -z bytes: [FILE CONTENT] +z bytes: [PARTIAL CONTENT] ``` #### Load request -Payload contains only the name of the file to load. +Payload contains + +``` +8 bytes: [64-127 (bytes 8-16): OFFSET OF FILE CONTENT IN BYTES] +8 bytes: [128-191 (bytes 17-24): 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: [192-223 (bytes 25-28): FILENAME SIZE] (cannot be > to PAYLOAD_SIZE - 20 or be zero) +y bytes: [] +``` ### Other response code (errors) #### Version error