From 5364d29bb198ecdee6f3c150ff34d4b5bafa5700 Mon Sep 17 00:00:00 2001 From: Leo dev Date: Sat, 30 Aug 2025 16:16:16 +0200 Subject: [PATCH] Protocol --- README.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib.rs | 6 +++--- 2 files changed, 55 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 90b895b..36df25e 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,54 @@ # voxa-server + Self host your voxa community server with customizable plugins + +# Protocol + +The protocol involves mixing simple principles with complex principles. + +1. If the client is online then the client will connect to all the servers, not just the "current server". +2. If a server sends a `Message` the client processes it as a notification. +3. A `Message` should only be sent to the client if the server knows that the user that the client is wrapping has been on this server before the messages were present, otherwise it will send a `InitialMessage`. + +## Handshake + +Client -> Connect -> Server + +Server -> Public RSA -> Client + +Client -> RSA encrypted AES key -> Server + +Client -> (AES) `{ session_id: }` -> Server + +Server -> Validate Session-Id via HTTP -> Voxa cloud + +Server -> (AES) `{ id: 0, result: "ok", session_id: }` -> Client + +## Sending a message + +Client -> (AES) `{ id: 10, SendMessage: { content: "This is a test", channel: } }` -> Server + +Server -> (AES) `{ id: 10, result: "ok" }` -> Client + +## Receiving a message + +Server -> (AES) `{ id: 23, Message: { content: "This is a test", author: , channel: } }` -> Client + +Client -> (AES) `{ id: 23, result: "ok" }` -> Server + +## Sending and receiving voice chat + +Client -> (AES) `{ ConnectVoice: { channel: } }` -> Server + +Client -> (AES) `{ VoiceData: [ ] }` -> Server + +Server -> (AES) `{ : [ ] }` -> Client + +Client -> (AES) `{ DisconnectVoice: [] }` -> Server + +## Edge cases + +- **Client closes TCP prematurely on voice chat**: Server should handle the voice disconnecting on it's own. +- **Server disconnects Client from voice chat**: In the case that a Server needs to disconnect a Client, the server will send the `DisconnectVoice` method to the Client to notify that any further `VoiceData` won't be processed. +- **Invalid or outdated protocol**: Both Server and Client should check for a update and update if `auto_update` is enabled, it's important to keep the server always updated. +- **`Message` cannot be sent at the moment**: The server will sent after the next [Handshake](#handshake) \ No newline at end of file diff --git a/src/lib.rs b/src/lib.rs index 838378f..75ac982 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -69,11 +69,11 @@ impl Server { } // Start server - let listener = TcpListener::bind(format!("0.0.0.0:{}", self.config.port)); + let listener = TcpListener::bind(format!("0.0.0.0:{}", self.config.port))?; self.logger - .info(format!("Server listening 0.0.0.0:{}", self.config.port)); + .info(format!("Server listening at 0.0.0.0:{}", self.config.port)); - for stream in listener?.incoming() { + for stream in listener.incoming() { match stream { Ok(stream) => { self.logger