]> jxnshi.xyz Git - mesange.git/commitdiff
Working on server side
authorjxnshi <jxnshi@cock.li>
Sun, 19 Jan 2025 21:48:40 +0000 (22:48 +0100)
committerjxnshi <jxnshi@cock.li>
Sun, 19 Jan 2025 21:48:40 +0000 (22:48 +0100)
common/request.odin
ncurses/ncurses.odin
server/server

index 3a16e2084114744f1b592c58a653d90a462f0954..bd141bfd2ec6474436c3bb5f5ac7652ad2a65a5c 100644 (file)
@@ -1,16 +1,26 @@
 package common
 
+import "core:bytes"
 import "core:crypto/ed25519"
+import "core:crypto/sha3"
+import "core:io"
+import "core:net"
+import "core:mem"
 
-Public_Key_Bytes :: [32]u8
+ROOM_KEY_SIZE :: 32
 
-Message :: struct {
-    room_id: string,
-    content: string,
+From_Bytes_Error {
+    Not_Enough_Bytes,
+    Invalid_Public_Key,
+}
+
+Write :: struct {
+    room_key: [ROOM_KEY_SIZE]u8,
+    message: string,
 }
 
 Client_Request_Content :: union {
-    Message,
+    Write,
 }
 
 Client_Request :: struct {
@@ -20,18 +30,49 @@ Client_Request :: struct {
     signature: [32]u8,
 }
 
-client_request_parse :: proc(source: []u8) -> (Client_Request, bool) {
-    panic("TODO")
+client_request_from_bytes :: proc(bytes: []u8) -> (Client_Request, From_Bytes_Error) {
+    bytes := bytes
+    bytes_buffer := bytes.Buffer{ buf = mem.buffer_from_slice(bytes) }
+    stream := bytes.buffer_to_stream(&bytes_buffer)
+
+    public_key_bytes: [ed25519.PUBLIC_KEY_SIZE]u8
+
+    err1 := io.read_at_least(stream, public_key_bytes, len(public_key_bytes))
+
+    if err1 != nil {
+        return {}, .Not_Enough_Bytes
+    }
+
+    public_key: ed25519.Public_Key
+    ok := ed25519.public_key_set_bytes(&public_key, public_key_bytes[:])
+
+    if !ok {
+        return {}, .Invalid_Public_Key
+    }
+
+    return {
+        public_key = public_key,
+        content = content,
+        timestamp = timestamp,
+        signature = signature,
+    },
+        nil
+}
+
+client_request_to_bytes :: proc(stream: io.Stream, request: Client_Request) {
+    
 }
 
 client_request_verify :: proc(request: Client_Request, expiration: Maybe(i64)) -> bool {
     panic("TODO")
 }
 
-Server_Request :: union {    
-    Message,
+send_client_request :: proc(server: net.TCP_Socket, request: Client_Request) {
+    panic("TODO")
 }
 
+Server_Request :: union {}
+
 send_server_request :: proc(request: Server_Request) {
     panic("TODO")
 }
index 412510849a49f430f73ad8793332ecd2113c13c0..1959a136d227084c305ef3f542f846cace27a88d 100644 (file)
@@ -65,4 +65,8 @@ foreign ncurses {
        // Success: Returns previous cursor state
        // Error: Returns ERR
        curs_set :: proc(visibility: c.int) -> c.int ---
+
+       notimeout :: proc(win: ^Window, bf: bool) -> c.int ---
+       wtimeout :: proc(win: ^Window, delay: c.int) --- 
+       timeout :: proc(delay: c.int) --- 
 }
index ac1e78db54c3bf271c589833534b40bf50ef3f75..0043fa61fdf70c0663dfcf0f74aa658982e0d023 100755 (executable)
Binary files a/server/server and b/server/server differ