From a4f7a9387d4d07f68ab09d7edead42bde2bdeccd Mon Sep 17 00:00:00 2001 From: Alex Emmet <111742636+Alex-Emmet@users.noreply.github.com> Date: Mon, 9 Mar 2026 22:22:10 +0100 Subject: [PATCH] [Fix] Omikron Connection --- Cargo.lock | 59 ++++++++----------------------- src/omikron/omikron_connection.rs | 34 +++++++++++------- src/omikron/ping_pong_task.rs | 2 +- 3 files changed, 38 insertions(+), 57 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 19b496b..6773323 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -982,10 +982,10 @@ dependencies = [ [[package]] name = "epsilon-core" version = "0.1.0" -source = "git+https://github.com/Tensamin/Epsilon.git#1eb12cceb70d99dded2327e0a5f215a5cd137eb3" +source = "git+https://github.com/Tensamin/Epsilon.git#809a32581843e663d35d4b3222f2cc59371d2786" dependencies = [ + "base64", "byteorder", - "quinn", "rand 0.8.5", "strum 0.28.0", "strum_macros 0.28.0", @@ -994,21 +994,15 @@ dependencies = [ [[package]] name = "epsilon-native" version = "0.1.0" -source = "git+https://github.com/Tensamin/Epsilon.git#1eb12cceb70d99dded2327e0a5f215a5cd137eb3" +source = "git+https://github.com/Tensamin/Epsilon.git#809a32581843e663d35d4b3222f2cc59371d2786" dependencies = [ - "anyhow", - "async-trait", - "aws-lc-rs", - "bytes", "epsilon-core", "quinn", - "rcgen", "rustls", "rustls-native-certs", "thiserror 2.0.18", "tokio", "wtransport", - "wtransport-proto", ] [[package]] @@ -1046,18 +1040,6 @@ dependencies = [ "regex", ] -[[package]] -name = "fastbloom" -version = "0.14.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e7f34442dbe69c60fe8eaf58a8cafff81a1f278816d8ab4db255b3bef4ac3c4" -dependencies = [ - "getrandom 0.3.4", - "libm", - "rand 0.9.2", - "siphasher", -] - [[package]] name = "fastrand" version = "2.3.0" @@ -1942,12 +1924,6 @@ version = "0.2.183" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d" -[[package]] -name = "libm" -version = "0.2.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" - [[package]] name = "line-clipping" version = "0.3.5" @@ -2218,18 +2194,18 @@ dependencies = [ [[package]] name = "objc2-core-foundation" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c10c2894a6fed806ade6027bcd50662746363a9589d3ec9d9bef30a4e4bc166" +checksum = "2a180dd8642fa45cdb7dd721cd4c11b1cadd4929ce112ebd8b9f5803cc79d536" dependencies = [ "bitflags 2.11.0", ] [[package]] name = "objc2-io-kit" -version = "0.3.1" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71c1c64d6120e51cd86033f67176b1cb66780c2efe34dec55176f77befd93c0a" +checksum = "33fafba39597d6dc1fb709123dfa8289d39406734be322956a69f0931c73bb15" dependencies = [ "libc", "objc2-core-foundation", @@ -2694,13 +2670,12 @@ dependencies = [ [[package]] name = "quinn-proto" -version = "0.11.13" +version = "0.11.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1906b49b0c3bc04b5fe5d86a77925ae6524a19b816ae38ce1e426255f1d8a31" +checksum = "434b42fec591c96ef50e21e886936e66d3cc3f737104fdb9b737c40ffb94c098" dependencies = [ "aws-lc-rs", "bytes", - "fastbloom", "getrandom 0.3.4", "lru-slab", "rand 0.9.2", @@ -2708,7 +2683,6 @@ dependencies = [ "rustc-hash", "rustls", "rustls-pki-types", - "rustls-platform-verifier", "slab", "thiserror 2.0.18", "tinyvec", @@ -2908,8 +2882,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10b99e0098aa4082912d4c649628623db6aba77335e4f4569ff5083a6448b32e" dependencies = [ "aws-lc-rs", - "pem", - "ring", "rustls-pki-types", "time", "x509-parser 0.18.1", @@ -3471,9 +3443,9 @@ dependencies = [ [[package]] name = "sysinfo" -version = "0.38.3" +version = "0.38.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d03c61d2a49c649a15c407338afe7accafde9dac869995dccb73e5f7ef7d9034" +checksum = "92ab6a2f8bfe508deb3c6406578252e491d299cbbf3bc0529ecc3313aee4a52f" dependencies = [ "libc", "memchr", @@ -4801,7 +4773,6 @@ dependencies = [ "lazy_static", "nom", "oid-registry", - "ring", "rusticata-macros", "thiserror 2.0.18", "time", @@ -4841,18 +4812,18 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.8.40" +version = "0.8.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a789c6e490b576db9f7e6b6d661bcc9799f7c0ac8352f56ea20193b2681532e5" +checksum = "f2578b716f8a7a858b7f02d5bd870c14bf4ddbbcf3a4c05414ba6503640505e3" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.8.40" +version = "0.8.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f65c489a7071a749c849713807783f70672b28094011623e200cb86dcb835953" +checksum = "7e6cc098ea4d3bd6246687de65af3f920c430e236bee1e3bf2e441463f08a02f" dependencies = [ "proc-macro2", "quote", diff --git a/src/omikron/omikron_connection.rs b/src/omikron/omikron_connection.rs index 3e92317..d1e22fa 100755 --- a/src/omikron/omikron_connection.rs +++ b/src/omikron/omikron_connection.rs @@ -6,7 +6,7 @@ use crate::util::crypto_util::{DataFormat, SecurePayload}; use crate::util::file_util::{get_children, load_file, save_file}; use crate::util::{chat_files, chats_util}; use crate::util::{config_util::CONFIG, crypto_helper}; -use crate::{ACTIVE_TASKS, SHUTDOWN, log, log_cv_in, log_t}; +use crate::{ACTIVE_TASKS, SHUTDOWN, log, log_cv_in, log_cv_out, log_t}; use dashmap::DashMap; use epsilon_core::{CommunicationType, CommunicationValue, DataTypes, DataValue}; use epsilon_native::{Receiver, Sender}; @@ -28,7 +28,7 @@ const OMIKRON_PORT_DEFAULT: u16 = 959; const RECONNECT_DELAY: Duration = Duration::from_secs(5); const MAX_RECONNECT_DELAY: Duration = Duration::from_secs(300); const CONNECTION_TIMEOUT: Duration = Duration::from_secs(10); -const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(10); +const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(5); const TASK_CLEANUP_INTERVAL: Duration = Duration::from_secs(60); const TASK_MAX_AGE: Duration = Duration::from_secs(60); @@ -282,6 +282,7 @@ impl OmikronConnection { if iota_id == 0 || public_key.is_none() || private_key.is_none() { log_t!("iota_register_new"); + let key_pair = crypto_helper::generate_keypair(); let public_key_base64 = crypto_helper::public_key_to_base64(&key_pair.public); let private_key_base64 = crypto_helper::secret_key_to_base64(&key_pair.secret); @@ -351,12 +352,20 @@ impl OmikronConnection { self.clone().handle_message(cv).await; } Err(e) => { - log!("Receive error: {}", e); + log!( + "Receive error: {} connection_id={} receiver_open={}", + e, + self.connection_id, + receiver.is_open() + ); break; } } if !receiver.is_open() { - log!("Connection closed "); + log!( + "Connection closed connection_id={} receiver_open=false", + self.connection_id + ); break; } } @@ -387,7 +396,9 @@ impl OmikronConnection { // ------------------------------------------------------------------------- pub async fn handle_message(self: Arc, cv: CommunicationValue) { - log_cv_in!(&cv); + if !cv.is_type(CommunicationType::ping) && !cv.is_type(CommunicationType::pong) { + log_cv_in!(&cv); + } let msg_id = cv.get_id(); @@ -436,7 +447,6 @@ impl OmikronConnection { if cv.is_type(CommunicationType::identification_response) { if let Some(accepted) = cv.get_data(DataTypes::accepted).as_bool() { - log!("Omikron connected: {}", accepted.to_string()); let mut state = self.state.write().await; if let ConnectionState::Connected { identified: _ } = *state { *state = ConnectionState::Connected { identified: true }; @@ -771,16 +781,13 @@ impl OmikronConnection { }; if let Some(decrypted) = solved_challenge { + let solved = decrypted.export(DataFormat::Raw); + let response = CommunicationValue::new(CommunicationType::challenge_response) .with_id(cv.get_id()) - .add_data( - DataTypes::challenge, - DataValue::Str(decrypted.export(DataFormat::Base64)), - ); + .add_data(DataTypes::challenge, DataValue::Str(solved)); self.send_message(&response).await; - } else { - log!("Failed to decrypt challenge"); } } @@ -803,6 +810,9 @@ impl OmikronConnection { let sender_clone = Arc::clone(sender); drop(sender_guard); + if !cv.is_type(CommunicationType::ping) && !cv.is_type(CommunicationType::pong) { + log_cv_out!(&cv); + } if let Err(e) = sender_clone.send(cv).await { log_t!("send_message_failed", e.to_string()); } diff --git a/src/omikron/ping_pong_task.rs b/src/omikron/ping_pong_task.rs index fde0623..aca9302 100644 --- a/src/omikron/ping_pong_task.rs +++ b/src/omikron/ping_pong_task.rs @@ -22,7 +22,7 @@ impl OmikronConnection { .with_id(id) .add_data( DataTypes::last_ping, - DataValue::Number(*self.last_ping.lock().await), + DataValue::Array(vec![DataValue::Number(*self.last_ping.lock().await)]), ); self.send_message(&ping_message).await;