Proposition version 1.1 en mode binaire

Ça sera plus facile à parser et plus facile de découper en blocs
de 4KB plus tard.
This commit is contained in:
Louis Royer 2020-01-21 12:43:02 +01:00
parent 3a27d84690
commit 8f239e23f5

View File

@ -7,6 +7,57 @@ All messages begins with `P2P-JAVA-PROJECT VERSION 1.0\n` (this version of the p
## Server responses
- The response to `LIST` request is in the format `LIST\n<FILENAME 1>\n<FILENAME 2>\n[…]<LAST FILENAME>\n\n`
- The response to `DOWNLOAD` request is `LOAD\n<FILESIZE (BYTES)>\n<CONTENT OF FILE>` or `NOT FOUND\n` if the file doesn't exists.
- The response to `DOWNLOAD` request is `LOAD\n<FILESIZE (BYTES)>\n<POSITION>\n<CONTENT OF FILE>` 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)
```Datagram format
[0-7: VERSION(0x11, first quartet is major version, second is minor)]
[8-15: REQUEST/RESPONSE CODE]
[16-31: RESERVED FOR FUTURE USE]
[32-63: PAYLOAD SIZE IN BYTES]
[64-xx: PAYLOAD]
```
## Requests and responses codes
- REQUESTS (msb is 0):
- `LIST` (0x00)
- `DOWNLOAD` (0x01)
- RESPONSES (msb is 1):
- `LIST` (0x80)
- `LOAD` (0x81)
- `NOT FOUND` (0x82)
- `PROTOCOL ERROR` (0x83)
- `INTERNAL ERROR` (0x84)
### List
Payload size for list request is always zero.
Payload for list response is filenames separated by `\n`.
### Download
#### Not found
Response when the file requested is not found on the server.
Payload size for Not found is zero
#### Protocol error
Response when the request cannot be interpreted.
Payload size for Protocol error is zero
#### Internal error
Response in internal failure case.
Payload size for Internal error is zero
#### Load response
Payload contains
```
[64-127: OFFSET OF FILE CONTENT IN BYTES]
[128-159: TOTAL FILESIZE]
[<FILENAME>\n]
[FILE CONTENT]
```