From: jxnshi Date: Thu, 6 Feb 2025 15:07:11 +0000 (+0100) Subject: Trying to fix requests X-Git-Url: https://jxnshi.xyz/repos?a=commitdiff_plain;h=7d9b98f69e13567f2046214cc05ddafc81d727a4;p=mesange.git Trying to fix requests --- diff --git a/client-cli/client-cli b/client-cli/client-cli index b68c1dc..1910a97 100755 Binary files a/client-cli/client-cli and b/client-cli/client-cli differ diff --git a/client-cli/config.odin b/client-cli/config.odin index ac7e669..0552629 100644 --- a/client-cli/config.odin +++ b/client-cli/config.odin @@ -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 diff --git a/client-cli/host.odin b/client-cli/host.odin index d87e77f..4b4cd7c 100644 --- a/client-cli/host.odin +++ b/client-cli/host.odin @@ -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 diff --git a/client-cli/main.odin b/client-cli/main.odin index 00009cb..24978b4 100644 --- a/client-cli/main.odin +++ b/client-cli/main.odin @@ -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) { diff --git a/client-cli/state.odin b/client-cli/state.odin index 733182d..7ad97c9 100644 --- a/client-cli/state.odin +++ b/client-cli/state.odin @@ -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) diff --git a/common/request.odin b/common/request.odin index b8d59c1..1f6be34 100644 --- a/common/request.odin +++ b/common/request.odin @@ -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 diff --git a/server/client.odin b/server/client.odin index 2177bcf..9d47ae4 100644 --- a/server/client.odin +++ b/server/client.odin @@ -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[:]) diff --git a/server/server b/server/server index 829a1fa..f3e1bc2 100755 Binary files a/server/server and b/server/server differ