From 9b949f8c6b90b61c7e35f3bf8a8724e18c2fefe8 Mon Sep 17 00:00:00 2001 From: Alex Emmet <111742636+Alex-Emmet@users.noreply.github.com> Date: Sun, 4 Jan 2026 22:37:08 +0100 Subject: [PATCH 1/2] This commit should have been Iota Auth... --- src/data/communication.rs | 18 ++++++++++++- src/main.rs | 4 +-- src/omikron/omikron_connection.rs | 42 +++++++++++++++++++++++++------ 3 files changed, 53 insertions(+), 11 deletions(-) diff --git a/src/data/communication.rs b/src/data/communication.rs index 2f8c689..7af1340 100644 --- a/src/data/communication.rs +++ b/src/data/communication.rs @@ -36,6 +36,8 @@ pub enum DataTypes { shared_secret, call_id, call_token, + untill, + enable, start_date, end_date, receiver_id, @@ -110,6 +112,8 @@ impl DataTypes { "sharedsecret" => DataTypes::shared_secret, "callid" => DataTypes::call_id, "calltoken" => DataTypes::call_token, + "untill" => DataTypes::untill, + "enable" => DataTypes::enable, "startdate" => DataTypes::start_date, "enddate" => DataTypes::end_date, "receiverid" => DataTypes::receiver_id, @@ -159,11 +163,14 @@ impl DataTypes { pub enum CommunicationType { error, error_invalid_user_id, + error_invalid_omikron_id, error_not_found, + error_not_authenticated, error_no_iota, error_invalid_challenge, error_invalid_secret, error_invalid_private_key, + error_invalid_public_key, error_no_user_id, error_no_call_id, error_invalid_call_id, @@ -210,6 +217,9 @@ pub enum CommunicationType { watch_stream, call_token, call_invite, + call_disconnect_user, + call_timeout_user, + call_set_anonymous_joining, end_call, function, update, @@ -223,14 +233,20 @@ impl CommunicationType { "watchstream" => CommunicationType::watch_stream, "calltoken" => CommunicationType::call_token, "callinvite" => CommunicationType::call_invite, + "calldisconnectuser" => CommunicationType::call_disconnect_user, + "calltimeoutuser" => CommunicationType::call_timeout_user, + "callsetanonymousjoining" => CommunicationType::call_set_anonymous_joining, "endcall" => CommunicationType::end_call, "function" => CommunicationType::function, "update" => CommunicationType::update, "createuser" => CommunicationType::create_user, "errorinvaliduserid" => CommunicationType::error_invalid_user_id, + "errorinvalidomikronid" => CommunicationType::error_invalid_omikron_id, "errornotfound" => CommunicationType::error_not_found, + "errornotauthenticated" => CommunicationType::error_not_authenticated, "errornoiota" => CommunicationType::error_no_iota, "errorinvalidchallenge" => CommunicationType::error_invalid_challenge, + "errorinvalidpublickey" => CommunicationType::error_invalid_public_key, "errorinvalidsecret" => CommunicationType::error_invalid_secret, "errorinvalidprivatekey" => CommunicationType::error_invalid_private_key, "errornouserid" => CommunicationType::error_no_user_id, @@ -243,7 +259,7 @@ impl CommunicationType { "message" => CommunicationType::message, "messagesend" => CommunicationType::message_send, "messagelive" => CommunicationType::message_live, - "messageother_iota" => CommunicationType::message_other_iota, + "messageotheriota" => CommunicationType::message_other_iota, "messagechunk" => CommunicationType::message_chunk, "messagesget" => CommunicationType::messages_get, "changeconfirm" => CommunicationType::change_confirm, diff --git a/src/main.rs b/src/main.rs index 815932d..795407d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -77,7 +77,7 @@ async fn main() { JsonValue::Number(Number::from( SystemTime::now() .duration_since(UNIX_EPOCH) - .unwrap() + .unwrap_or(Duration::from_millis(0)) .as_millis() as i64, )), ); @@ -126,7 +126,7 @@ async fn main() { let iface: NetworkInterface = iface; if iface.ips.len() > 0 { let ipsv = format!("{}", iface.ips[0]); - let ips: &str = ipsv.split('/').next().unwrap(); + let ips: &str = ipsv.split('/').next().unwrap_or(""); if format!("{}", ips).starts_with("10.") || format!("{}", ips).starts_with("192.") { ip = ips.to_string(); } diff --git a/src/omikron/omikron_connection.rs b/src/omikron/omikron_connection.rs index 4529155..5f95029 100644 --- a/src/omikron/omikron_connection.rs +++ b/src/omikron/omikron_connection.rs @@ -40,8 +40,8 @@ pub struct OmikronConnection { pub user_id: Arc>, pub(crate) writer: Arc + Send + Unpin>>>>, - waiting: Arc>>>, // waiting for responses - pingpong: Arc>>>, // ping-pong handler + waiting: Arc>>>, + pingpong: Arc>>>, pub last_ping: Arc>, pub message_send_times: Arc>>, pub is_connected: Arc>, @@ -346,17 +346,20 @@ impl OmikronConnection { .unwrap_or(&JsonValue::Null) .as_i64() .unwrap_or(0); + let now_ms = SystemTime::now() + .duration_since(UNIX_EPOCH) + .unwrap() + .as_millis() as u128; + chat_files::add_message( - SystemTime::now() - .duration_since(UNIX_EPOCH) - .unwrap() - .as_millis() as u128, + now_ms, true, my_id, other_id, &*cv.get_data(DataTypes::content).unwrap().to_string(), ); - let ack = CommunicationValue::new(CommunicationType::message) + + let ack = CommunicationValue::new(CommunicationType::success) .with_id(cv.get_id()) .with_receiver(my_id); Self::send_message_static( @@ -365,7 +368,30 @@ impl OmikronConnection { ack.to_json().to_string(), ) .await; - let forward = CommunicationValue::forward_to_other_iota(&mut cv); + + let forward = + CommunicationValue::new(CommunicationType::message_other_iota) + .with_id(cv.get_id()) + .with_receiver(other_id) + .add_data( + DataTypes::receiver_id, + JsonValue::Number(Number::from(other_id)), + ) + .with_sender(my_id) + .add_data( + DataTypes::send_time, + JsonValue::String(now_ms.to_string()), + ) + .add_data( + DataTypes::sender_id, + JsonValue::Number(Number::from(my_id)), + ) + .add_data( + DataTypes::content, + JsonValue::String( + cv.get_data(DataTypes::content).unwrap().to_string(), + ), + ); Self::send_message_static( &writer.clone(), is_connected, From 343687a31b3591c27067ca3cec24e7534d46a17b Mon Sep 17 00:00:00 2001 From: Alex Emmet <111742636+Alex-Emmet@users.noreply.github.com> Date: Tue, 6 Jan 2026 22:15:55 +0100 Subject: [PATCH 2/2] Stable Connection --- src/data/communication.rs | 24 ++++++++++++++++------ src/omikron/omikron_connection.rs | 33 ++++++++++++++----------------- 2 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/data/communication.rs b/src/data/communication.rs index 7af1340..58fd957 100644 --- a/src/data/communication.rs +++ b/src/data/communication.rs @@ -16,6 +16,7 @@ pub enum DataTypes { iota_id, user_id, user_ids, + iota_ids, user_state, user_states, user_pings, @@ -75,7 +76,7 @@ pub enum DataTypes { challenge, community_title, communities, - + rho_connections, user, } @@ -92,6 +93,7 @@ impl DataTypes { "iotaid" => DataTypes::iota_id, "userid" => DataTypes::user_id, "userids" => DataTypes::user_ids, + "iotaids" => DataTypes::iota_ids, "userstate" => DataTypes::user_state, "userstates" => DataTypes::user_states, "userpings" => DataTypes::user_pings, @@ -151,7 +153,7 @@ impl DataTypes { "challenge" => DataTypes::challenge, "communitytitle" => DataTypes::community_title, "communities" => DataTypes::communities, - + "rhoconnections" => DataTypes::rho_connections, "user" => DataTypes::user, _ => DataTypes::error_type, // fallback if unknown } @@ -202,8 +204,6 @@ pub enum CommunicationType { pong, add_chat, send_chat, - iota_connected, - iota_closed, client_changed, client_connected, client_disconnected, @@ -224,6 +224,13 @@ pub enum CommunicationType { function, update, create_user, + rho_update, + + user_connected, + user_disconnected, + iota_connected, + iota_disconnected, + sync_client_iota_status, } impl CommunicationType { pub fn parse(p0: String) -> CommunicationType { @@ -280,8 +287,6 @@ impl CommunicationType { "pong" => CommunicationType::pong, "addchat" => CommunicationType::add_chat, "sendchat" => CommunicationType::send_chat, - "iotaconnected" => CommunicationType::iota_connected, - "iotaclosed" => CommunicationType::iota_closed, "clientchanged" => CommunicationType::client_changed, "clientconnected" => CommunicationType::client_connected, "clientdisconnected" => CommunicationType::client_disconnected, @@ -292,6 +297,13 @@ impl CommunicationType { "webrtcice" => CommunicationType::webrtc_ice, "startstream" => CommunicationType::start_stream, "endstream" => CommunicationType::end_stream, + "rhoupdate" => CommunicationType::rho_update, + + "iotaconnected" => CommunicationType::iota_connected, + "iotadisconnected" => CommunicationType::iota_disconnected, + "userconnected" => CommunicationType::user_connected, + "userdisconnected" => CommunicationType::user_disconnected, + "syncclientiotastatus" => CommunicationType::sync_client_iota_status, _ => CommunicationType::error, } diff --git a/src/omikron/omikron_connection.rs b/src/omikron/omikron_connection.rs index 5f95029..60aed8d 100644 --- a/src/omikron/omikron_connection.rs +++ b/src/omikron/omikron_connection.rs @@ -73,7 +73,7 @@ impl OmikronConnection { pingpong: Arc::new(Mutex::new(None)), last_ping: Arc::new(Mutex::new(-1)), message_send_times: Arc::new(Mutex::new(HashMap::new())), - is_connected: Arc::new(Mutex::new(false)), + is_connected: Arc::new(Mutex::new(true)), }); let boxed_reader: Box< dyn Stream> + Send + Unpin, @@ -161,25 +161,22 @@ impl OmikronConnection { ACTIVE_TASKS.lock().unwrap().push("Listener".to_string()); } tokio::spawn(async move { - while !*SHUTDOWN.read().await { - if poll(Duration::from_millis(100)).unwrap() { - if let Some(msg) = read_half.next().await { - if *is_connected_out.lock().await == false { - log_message("Disconnected, not handeling incomming"); - break; - } - Self::handle_message( - msg, - waiting_out.clone(), - writer_out.clone(), - is_connected_out.clone(), - sel_out.clone(), - variant.clone(), - sel_arc_out.clone(), - ); - } + while let Some(msg) = read_half.next().await { + if *SHUTDOWN.read().await { + break; } + Self::handle_message( + msg, + waiting_out.clone(), + writer_out.clone(), + is_connected_out.clone(), + sel_out.clone(), + variant.clone(), + sel_arc_out.clone(), + ); } + *is_connected_out.lock().await = false; + log_message("Connection closed."); }); { ACTIVE_TASKS