Skip to content
This repository was archived by the owner on Mar 16, 2021. It is now read-only.

Communication between Client and Name Server

Ilya Makarenko edited this page Oct 7, 2020 · 10 revisions

Overview

All communication will be made using the following schema:

Requests

Full list of possible requests to Name Server:

  1. Logout. Remove the given token from the Name Server's database. Response for this request is status.
  2. Register. For given login and password creates a record in the Name Server's database. Also creates a token for a session and initializes client storage for a given user. Response for this request is token.
  3. Login. Get an authorization token if given login and password are valid. Response for this request is a token.
  4. Initialize. Initialize the client storage in the system, removing any existing files root directory. Response for this request is status.
  5. File create. Creates a new empty file. Response for this request is status.
  6. File read. Reads a file from the system, providing a link for downloading. Response for this request is server.
  7. File write. Puts a file to the system, providing a link for uploading. Response for this request is server.
  8. File delete. Deletes a file from the system. Response for this request is status.
  9. File info. Provides information about the file in UTF-8 string. Response for this request is status.
  10. File copy. Creates a copy of the file with the given name. Response for this request is status.
  11. File move. Moves a file to the specified path. Response for this request is status.
  12. Read directory. Return a list of files in the directory as UTF-8 string. Response for this request is status.
  13. Make directory. Create a new directory in the system. Response for this request is status.
  14. Delete directory. Delete directory and all including files and folders in the system. Response for this request is status.

Expected format for every request type:

  1. Logout.

  1. Register.

  1. Login.

  1. Initialize.

  1. File create.

  1. File read.

  1. File write.

  1. File delete.

  1. File info.

  1. File copy.

  1. File move.

  1. Read directory.

  1. Make directory.

  1. Delete directory.

Responses

Full list of possible responses from Name Server:

  1. Token. Returns a 32-byte long token which will be used for authorization.
  2. Server. Returns information about the server, where we can upload/download the file.
  3. Status. Returns a custom message.

Format for every response:

  1. Token.

  1. Server.

  1. Status.

String format for read directory.

Example:

total 4
f file.txt
f file2.txt
f file2copy.txt
d folder

First string contains the word “total” followed by the “ ” (space) character followed by an amount of entities in the directory.

All following lines are following format: (“f”|”d”)<space><STRING>

Where:

  • (“f”|”d”) determines type of entity, file or directory
  • <space> is “ ” (space, ascii code is 0x20) symbol
  • <STRING> is name of the entity

Line endings must be windows-styled (\r\n)

String format for file info

2 4060 2020-10-06 17:29:55 file.txt

Where

  • 2 - Amount of replicas of this file
  • 4060 - Size of file
  • 2020-10-06 - Creation date
  • 17:29:55 - Creation time
  • file.txt - File name

Error codes

Status response supports custom error codes, instead of just 00. Here you can see the full list of error codes:

Code	Description
0x00	OK
0x1_	Authorization error
0x10	Unknown authorization error
0x11	Username already registered
0x12	Invalid username during registration
0x13	User does not exists
0x14	Incorrect password
0x15	Invalid token
0x2_	File error
0x20	Unknown file error
0x21	File does not exist
0x22	File already exists
0x23	Not enough space to create this file
0x24	Prohibited filename
0x3_	Directory error
0x30	Unknown directory error
0x31	Directory does not exist
0x32	Directory already exists
0x33	Prohibited directory name
0x8_	Other errors
0x80	Unknown server error
0x81	Wrong request id
Clone this wiki locally