]> jxnshi.xyz Git - mesange.git/commitdiff
Trying to fix requests
authorjxnshi <jxnshi@proton.me>
Thu, 6 Feb 2025 15:07:11 +0000 (16:07 +0100)
committerjxnshi <jxnshi@proton.me>
Thu, 6 Feb 2025 15:07:11 +0000 (16:07 +0100)
client-cli/client-cli
client-cli/config.odin
client-cli/host.odin
client-cli/main.odin
client-cli/state.odin
common/request.odin
server/client.odin
server/server

index b68c1dcbffc5d4d4605afc4b379e891a1e415099..1910a97ea8bbc025248607ea87f0b6269dfc666d 100755 (executable)
Binary files a/client-cli/client-cli and b/client-cli/client-cli differ
index ac7e6699a92552bc650ad03a4236e15075198b8a..0552629e2478c6eb4fb1324da81d3a226837103c 100644 (file)
@@ -40,7 +40,7 @@ config_to_parsed :: proc(config: Config) -> Config_Parsed {
 
 config_load :: proc(app: ^App) -> (Config, Maybe(Config_Load_Error)) {
     config_path := fpath.join({ app.storage_path, "config.json" }, context.temp_allocator)
-    raw_config, config_read := os.read_entire_file_from_filename(config_path)
+    raw_config, config_read := os.read_entire_file_from_filename(config_path, context.temp_allocator)
 
     parsed_config: Config_Parsed
 
index d87e77f3059072a21c0369f369daad0ed7e0cfb5..4b4cd7ccd88549fb836ff3e96cbf8eb44edc0019 100644 (file)
@@ -4,7 +4,9 @@ import "core:bytes"
 import "core:crypto/ed25519"
 import "core:encoding/endian"
 import "core:io"
+import "core:log"
 import "core:math/rand"
+import "core:mem"
 import "core:net"
 import "core:slice"
 import "core:sync"
@@ -36,6 +38,8 @@ request_host :: proc(
 
     _, _ = io.write(request_stream, id_bytes[:])
 
+    log.infof("ID %v", id_bytes)
+
     // Request.
     _ = common.client_request_to_bytes(request_stream, request)
 
@@ -45,9 +49,10 @@ request_host :: proc(
     len_bytes: [size_of(32)]u8
     endian.put_u32(len_bytes[:], .Little, u32(buffer_length))
 
-    _, _ = io.write_at(request_stream, len_bytes[:], 0)
+    mem.copy(raw_data(bytes_buf[size_of(u32):]), raw_data(bytes_buf[:buffer_length]), buffer_length)
+    mem.copy_non_overlapping(raw_data(bytes_buf[:]), raw_data(len_bytes[:]), size_of(u32))
 
-    request_bytes := bytes.buffer_to_bytes(&bytes_buffer)
+    request_bytes := bytes_buf[:size_of(u32) + buffer_length]
 
     _ = net.send_tcp(app.host.?, request_bytes) or_return
 
index 00009cb6fe150642bee3be07818557c7041e7fb6..24978b467a1bb316fade0d4aa71751fa4f583d4f 100644 (file)
@@ -282,6 +282,16 @@ app_set_info_bar :: proc(app: ^App, format: string, args: ..any) {
         delete(app.info_bar_content)
     }
 
+    sync.mutex_lock(&app.mutex)
+    defer sync.mutex_unlock(&app.mutex)
+
+    if len(format) == 0 {
+        app.info_bar_content = ""
+        app_update_info_bar(app)
+
+        return
+    }
+
     info_bar_content_builder: strings.Builder
 
     strings.builder_init_none(&info_bar_content_builder)
@@ -291,6 +301,8 @@ app_set_info_bar :: proc(app: ^App, format: string, args: ..any) {
 
     app.info_bar_content = strings.clone(strings.to_string(info_bar_content_builder))
     app_update_info_bar(app)
+
+    log.infof("Info bar %v", app.info_bar_content)
 }
 
 app_set_box_message :: proc(app: ^App, lines: []string) {
index 733182db55aa09ac1ce32d98b8a080bf3b33cb72..7ad97c90a450de9f57eed2c7f8663d7e5b31e92e 100644 (file)
@@ -39,9 +39,6 @@ State :: enum {
 }
 
 state_load_config :: proc(app: ^App) {
-    config_path := fpath.join({ app.storage_path, "config.json" }, context.temp_allocator)
-
-    raw_config, config_read := os.read_entire_file_from_filename(config_path)
     config, config_error := config_load(app)
 
     if err, ok := config_error.?; ok {
@@ -387,7 +384,7 @@ state_ask_profile_confirm_password :: proc(app: ^App) {
 }
 
 state_connect_to_host :: proc(app: ^App) {
-    app_set_info_bar(app, "Connecting to host..")
+    app_set_info_bar(app, "Connecting to host...")
 
     maybe_host: Maybe(net.TCP_Socket)
     hosts := strings.clone(app.profile.hosts, context.temp_allocator)
index b8d59c124a67a45621eb27a9ca94a8785a3417a4..1f6be342c67ac70a633da0960d1db2c1fca9f824 100644 (file)
@@ -175,6 +175,8 @@ client_request_from_bytes :: proc(stream: io.Stream) -> (request: Client_Request
 
     _ = io.read(stream, public_key_bytes[:]) or_return
 
+    log.infof("PK %v", public_key_bytes)
+
     public_key: ed25519.Public_Key
     ok := ed25519.public_key_set_bytes(&public_key, public_key_bytes[:])
     if !ok do return {}, .Invalid_Public_Key
@@ -205,6 +207,8 @@ client_request_to_bytes_signatureless :: proc(stream: io.Stream, request: Client
     ed25519.public_key_bytes(&request.public_key, public_key_bytes[:])
     _ = io.write(stream, public_key_bytes[:]) or_return
 
+    log.infof("PK %v", public_key_bytes)
+
     client_request_inner_to_bytes(stream, request.inner) or_return
 
     timestamp_bytes: [size_of(i64)]u8
index 2177bcfc9be2d0743ac3a6144f9bc759fb6725b4..9d47ae4f59b6b842406b1f3f80af122bf120c773 100644 (file)
@@ -3,6 +3,7 @@ package main
 import "core:bytes"
 import "core:encoding/endian"
 import "core:io"
+import "core:log"
 import "core:net"
 import "core:slice"
 
@@ -15,6 +16,8 @@ receive_request :: proc(client: net.TCP_Socket) -> (id: u32, request: common.Cli
     id_bytes := packet[:size_of(u32)]
     id, _ = endian.get_u32(id_bytes[:], .Little)
 
+    log.infof("ID %v", id_bytes)
+
     request_bytes := packet[size_of(u32):]
     request_buffer: bytes.Buffer
     request_buffer.buf = slice.into_dynamic(request_bytes[:])
index 829a1fad3fbdb16bac07b1d5ce004e9ae22d23e5..f3e1bc2d1464c930ea6dfa5a8692369938656526 100755 (executable)
Binary files a/server/server and b/server/server differ