Browse Source

added gui-cli protocol 0.2

Cyamond 4 years ago
parent
commit
055b81ff51
1 changed files with 213 additions and 0 deletions
  1. 213 0
      GUI-CLI Protocol.md

+ 213 - 0
GUI-CLI Protocol.md

@@ -0,0 +1,213 @@
+# Client-Server Protocol
+
+Protocol version: <b>"0.2"</b>
+
+Every json message must be minimized and be followed by a newline. This rule makes receiving and parsing the messages easier because you can read until a newline comes and you will parse every json message seperately because you won't read multiple json messages from the buffer at a time.
+
+## 0. Connect to the server
+
+The GUI creates a new instance of the CLI with the entered IP Address as a paramater. The CLI then tries to establish a connection to the given server and tells the GUI if the connection was successful.
+
+CLI:
+```
+{
+	"command": "connect",
+	"accept": bool,
+	"error": string
+}
+```
+
+## 1. Start a connection
+
+To connect to a server, the CLI has to do a version check. Once that is successful, the GUI will pass the username and password to establish a connection.
+
+### 1.1 Version check
+CLI:
+```
+{
+	"command": "version",
+	"serverversion": string,
+	"clientversion": string,
+	"accept": bool
+}
+```
+
+If `accept` is `true` the connection is valid. Else the connection will be terminated after the server answered.
+
+
+## 1.2 Login / Signup
+
+The GUI will send the username and password right after another into the pipe. If the response contains a "true" for accept, the login was successful.
+
+### 1.2.1 Login
+GUI:
+```
+	write: username
+	write: password
+```
+
+CLI:
+```
+{
+	"command": "login",
+	"accept": bool,
+	"error": string
+}
+```
+
+If `accept` is `true` the connection is valid and the user is logged in. Else `error` has an error string and the connection will be terminated after the server answered.
+
+### 1.2.2 Signup
+GUI:
+```
+	write: #ToBeAdded
+```
+
+Server:
+```
+{
+	"command": "signup",
+	#ToBeAdded
+}
+```
+
+If `accept` is `true` the connection is valid and the user is logged in and signed up. Else `error` has an error string and the connection will be terminated after the server answered.
+
+
+## 2. Sending commands
+
+Commands can be sent by the client after a connection has been negotiated (See 1).
+Commands can be used unrelated to each other.
+
+### 2.1 Status command
+GUI:
+```
+write: "status"
+```
+
+CLI:
+```
+{
+	"command": "status",
+	"response": string
+}
+```
+
+### 2.2 List command
+`list` to request a list download.
+
+#### 2.2.1 list - request file list download
+GUI:
+```
+{
+	write: "list"
+}
+```
+CLI:
+```
+{
+	"command": "list",
+  "accept": bool,
+	"names": string[],
+	"error": string
+}
+```
+
+
+### 2.3 Put command
+
+Put is split in two commands. `put` to request a file upload and `putdata` to get the information about an ongoing upload.
+
+#### 2.3.1 put - request upload
+GUI:
+```
+write: "put" file_path
+```
+
+CLI:
+```
+{
+	"command": "put",
+	"accept": bool,
+	"file": string,
+	"error": string
+}
+```
+If `accept` is `true` the connection is valid and the client can start sending the file. Else the put request was rejected and is hereby canceled. `error` should contain an error string if the request was rejected.
+
+
+#### 2.3.2 putdata - upload data
+CLI:
+```
+{
+	"command": "putdata",
+	"file": string,
+	"speed": float,
+	"cancel": bool,
+	"error": string
+}
+```
+If `cancel` is `true` then the upload of the file is canceled and an error message should be in `error`.
+`speed` shall contain a float describing the upload speed in kB/s.
+
+
+### 2.4 Get command
+
+Get is split in two commands. `get` to request a file download and `getdata` to get the information about an ongoing download.
+
+#### 2.4.1 get - request download
+
+GUI:
+```
+write: "get" file_name
+```
+
+CLI:
+```
+{
+	"command": "get",
+	"accept": bool,
+	"file": string,
+	"error": string
+}
+```
+If `accept` is `true` the connection is valid and the server can start sending the file. Else the get request was rejected and is hereby canceled. `error` should contain an error string if the request was rejected.
+
+#### 2.4.2 getdata - download data
+
+CLI:
+```
+{
+	"command": "putdata",
+	"file": string,
+	"speed": float,
+	"cancel": bool,
+	"error": string
+}
+```
+
+If `cancel` is `true` then the download of the file is canceled and an error message should be in `error`.
+`speed` shall contain a float describing the download speed in kB/s.
+
+
+### TODO
+
+
+## 3. Disconnect
+
+GUI:
+```
+{
+	write: "disconnect"
+}
+```
+
+CLI:
+```
+{
+	"command": "disconnect",
+	"accept": bool
+}
+```
+
+If `accept` is true, the connection is closed and the program can exit.