You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
82 lines
2.5 KiB
Markdown
82 lines
2.5 KiB
Markdown
# 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<FILENAME>\n`: ask the server to download file <FILENAME> from server root directory. Only one filename is allowed per request.
|
|
|
|
## 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<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)
|
|
|
|
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]
|
|
|
|
```
|
|
|
|
## Requests and responses codes
|
|
- REQUESTS (msb is 0):
|
|
- `LIST` (0x00)
|
|
- `LOAD` (0x01)
|
|
|
|
- RESPONSES (msb is 1):
|
|
- `LIST` (0x80)
|
|
- `LOAD` (0x81)
|
|
- `VERSION ERROR` (0xC0)
|
|
- `PROTOCOL ERROR` (0xC1)
|
|
- `INTERNAL ERROR` (0xC2)
|
|
- `EMPTY DIRECTORY` (0xC3)
|
|
- `NOT FOUND` (0xC4)
|
|
|
|
### List
|
|
Payload size for list request is always zero.
|
|
Payload for list response is filenames separated by `\n`. Payload size for list response is never zero.
|
|
|
|
#### Empty directory
|
|
When directory is empty.
|
|
Payload size for empty directory is always zero.
|
|
|
|
|
|
### Load
|
|
#### Not found
|
|
Response when the file requested is not found on the server.
|
|
Payload size for Not found is zero.
|
|
|
|
|
|
#### Load response
|
|
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)
|
|
y bytes: [<FILENAME>]
|
|
z bytes: [FILE CONTENT]
|
|
```
|
|
|
|
#### Load request
|
|
Payload contains only the name of the file to load.
|
|
|
|
### Other response code (errors)
|
|
#### Version error
|
|
Response when datagram received use wrong version code.
|
|
|
|
#### Protocol error
|
|
Response when the request cannot be interpreted (but version is correct).
|
|
Payload size for Protocol error is zero
|
|
|
|
#### Internal error
|
|
Response in internal failure case.
|
|
Payload size for Internal error is zero.
|