From 73027e6474b06459183c5f3c9bba6e32f13ac19f Mon Sep 17 00:00:00 2001 From: Alex Emmet <111742636+Alex-Emmet@users.noreply.github.com> Date: Sat, 4 Jul 2026 23:02:04 +0200 Subject: [PATCH] [Fix]Connection Stability --- Cargo.lock | 154 ++++++---------------------- src/server/api.rs | 27 ++++- src/sql/user_online_tracker.rs | 40 ++++++++ src/transport/omikron_connection.rs | 1 + type-maps.yaml | 40 -------- 5 files changed, 97 insertions(+), 165 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 16c9bf5..c75fa4a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1459,11 +1459,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" dependencies = [ "cfg-if", - "js-sys", "libc", "r-efi 5.3.0", "wasip2", - "wasm-bindgen", ] [[package]] @@ -1473,9 +1471,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" dependencies = [ "cfg-if", + "js-sys", "libc", "r-efi 6.0.0", "rand_core 0.10.1", + "wasm-bindgen", ] [[package]] @@ -2280,7 +2280,7 @@ dependencies = [ [[package]] name = "mtp" version = "0.1.0" -source = "git+https://git.methanium.net/methanium/mtp#b96c072a0f87de7828e45cf3dcd44aef4a9e459d" +source = "git+https://git.methanium.net/methanium/mtp#2e7c0b489360d5d05fe53326811616e730c1a556" dependencies = [ "mtp-client", "mtp-codec", @@ -2288,14 +2288,13 @@ dependencies = [ "mtp-crypto", "mtp-files", "mtp-host", - "mtp-transport", "mtp-type-map", ] [[package]] name = "mtp-client" version = "0.1.0" -source = "git+https://git.methanium.net/methanium/mtp#b96c072a0f87de7828e45cf3dcd44aef4a9e459d" +source = "git+https://git.methanium.net/methanium/mtp#2e7c0b489360d5d05fe53326811616e730c1a556" dependencies = [ "mtp-codec", "mtp-common", @@ -2308,7 +2307,7 @@ dependencies = [ [[package]] name = "mtp-codec" version = "0.1.0" -source = "git+https://git.methanium.net/methanium/mtp#b96c072a0f87de7828e45cf3dcd44aef4a9e459d" +source = "git+https://git.methanium.net/methanium/mtp#2e7c0b489360d5d05fe53326811616e730c1a556" dependencies = [ "base64", "byteorder", @@ -2321,7 +2320,7 @@ dependencies = [ [[package]] name = "mtp-common" version = "0.1.0" -source = "git+https://git.methanium.net/methanium/mtp#b96c072a0f87de7828e45cf3dcd44aef4a9e459d" +source = "git+https://git.methanium.net/methanium/mtp#2e7c0b489360d5d05fe53326811616e730c1a556" dependencies = [ "quinn", "rustls", @@ -2332,7 +2331,7 @@ dependencies = [ [[package]] name = "mtp-crypto" version = "0.1.0" -source = "git+https://git.methanium.net/methanium/mtp#b96c072a0f87de7828e45cf3dcd44aef4a9e459d" +source = "git+https://git.methanium.net/methanium/mtp#2e7c0b489360d5d05fe53326811616e730c1a556" dependencies = [ "base64", "chacha20poly1305", @@ -2351,7 +2350,7 @@ dependencies = [ [[package]] name = "mtp-files" version = "0.1.0" -source = "git+https://git.methanium.net/methanium/mtp#b96c072a0f87de7828e45cf3dcd44aef4a9e459d" +source = "git+https://git.methanium.net/methanium/mtp#2e7c0b489360d5d05fe53326811616e730c1a556" dependencies = [ "mtp-crypto", "thiserror 1.0.69", @@ -2360,7 +2359,7 @@ dependencies = [ [[package]] name = "mtp-host" version = "0.1.0" -source = "git+https://git.methanium.net/methanium/mtp#b96c072a0f87de7828e45cf3dcd44aef4a9e459d" +source = "git+https://git.methanium.net/methanium/mtp#2e7c0b489360d5d05fe53326811616e730c1a556" dependencies = [ "mtp-codec", "mtp-common", @@ -2373,7 +2372,7 @@ dependencies = [ [[package]] name = "mtp-transport" version = "0.1.0" -source = "git+https://git.methanium.net/methanium/mtp#b96c072a0f87de7828e45cf3dcd44aef4a9e459d" +source = "git+https://git.methanium.net/methanium/mtp#2e7c0b489360d5d05fe53326811616e730c1a556" dependencies = [ "log", "mtp-codec", @@ -2387,7 +2386,7 @@ dependencies = [ [[package]] name = "mtp-type-map" version = "0.1.0" -source = "git+https://git.methanium.net/methanium/mtp#b96c072a0f87de7828e45cf3dcd44aef4a9e459d" +source = "git+https://git.methanium.net/methanium/mtp#2e7c0b489360d5d05fe53326811616e730c1a556" dependencies = [ "serde", "serde_yaml", @@ -2774,15 +2773,16 @@ dependencies = [ [[package]] name = "quinn-proto" -version = "0.11.15" +version = "0.11.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fcb935c5bec503c2f0e306bdd3e58bb9029dcb14fa8d9ac76e3a5256ac0763e" +checksum = "2f4bfc015262b9df63c8845072ce59068853ff5872180c2ce2f13038b970e560" dependencies = [ "aws-lc-rs", "bytes", - "getrandom 0.3.4", + "getrandom 0.4.3", "lru-slab", - "rand 0.9.4", + "rand 0.10.2", + "rand_pcg", "ring", "rustc-hash", "rustls", @@ -2796,16 +2796,16 @@ dependencies = [ [[package]] name = "quinn-udp" -version = "0.5.14" +version = "0.5.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "addec6a0dcad8a8d96a771f815f0eaf55f9d1805756410b39f5fa81332574cbd" +checksum = "35a133f956daabe89a61a685c2649f13d82d5aa4bd5d12d1277e1072a21c0694" dependencies = [ "cfg_aliases", "libc", "once_cell", "socket2 0.6.4", "tracing", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -2836,20 +2836,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5ca0ecfa931c29007047d1bc58e623ab12e5590e8c7cc53200d5202b69266d8a" dependencies = [ "libc", - "rand_chacha 0.3.1", + "rand_chacha", "rand_core 0.6.4", ] -[[package]] -name = "rand" -version = "0.9.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44c5af06bb1b7d3216d91932aed5265164bf384dc89cd6ba05cf59a35f5f76ea" -dependencies = [ - "rand_chacha 0.9.0", - "rand_core 0.9.5", -] - [[package]] name = "rand" version = "0.10.2" @@ -2871,16 +2861,6 @@ dependencies = [ "rand_core 0.6.4", ] -[[package]] -name = "rand_chacha" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" -dependencies = [ - "ppv-lite86", - "rand_core 0.9.5", -] - [[package]] name = "rand_core" version = "0.5.1" @@ -2896,21 +2876,21 @@ dependencies = [ "getrandom 0.2.17", ] -[[package]] -name = "rand_core" -version = "0.9.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76afc826de14238e6e8c374ddcc1fa19e374fd8dd986b0d2af0d02377261d83c" -dependencies = [ - "getrandom 0.3.4", -] - [[package]] name = "rand_core" version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" +[[package]] +name = "rand_pcg" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "caa0f4137e1c0a72f4c651489402276c8e8e1cf081f3b0ba156d2cbeef09e86a" +dependencies = [ + "rand_core 0.10.1", +] + [[package]] name = "rcgen" version = "0.14.8" @@ -4386,15 +4366,6 @@ dependencies = [ "windows-targets 0.52.6", ] -[[package]] -name = "windows-sys" -version = "0.60.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" -dependencies = [ - "windows-targets 0.53.5", -] - [[package]] name = "windows-sys" version = "0.61.2" @@ -4428,30 +4399,13 @@ dependencies = [ "windows_aarch64_gnullvm 0.52.6", "windows_aarch64_msvc 0.52.6", "windows_i686_gnu 0.52.6", - "windows_i686_gnullvm 0.52.6", + "windows_i686_gnullvm", "windows_i686_msvc 0.52.6", "windows_x86_64_gnu 0.52.6", "windows_x86_64_gnullvm 0.52.6", "windows_x86_64_msvc 0.52.6", ] -[[package]] -name = "windows-targets" -version = "0.53.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4945f9f551b88e0d65f3db0bc25c33b8acea4d9e41163edf90dcd0b19f9069f3" -dependencies = [ - "windows-link", - "windows_aarch64_gnullvm 0.53.1", - "windows_aarch64_msvc 0.53.1", - "windows_i686_gnu 0.53.1", - "windows_i686_gnullvm 0.53.1", - "windows_i686_msvc 0.53.1", - "windows_x86_64_gnu 0.53.1", - "windows_x86_64_gnullvm 0.53.1", - "windows_x86_64_msvc 0.53.1", -] - [[package]] name = "windows_aarch64_gnullvm" version = "0.48.5" @@ -4464,12 +4418,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" -[[package]] -name = "windows_aarch64_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9d8416fa8b42f5c947f8482c43e7d89e73a173cead56d044f6a56104a6d1b53" - [[package]] name = "windows_aarch64_msvc" version = "0.48.5" @@ -4482,12 +4430,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" -[[package]] -name = "windows_aarch64_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9d782e804c2f632e395708e99a94275910eb9100b2114651e04744e9b125006" - [[package]] name = "windows_i686_gnu" version = "0.48.5" @@ -4500,24 +4442,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" -[[package]] -name = "windows_i686_gnu" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "960e6da069d81e09becb0ca57a65220ddff016ff2d6af6a223cf372a506593a3" - [[package]] name = "windows_i686_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" -[[package]] -name = "windows_i686_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa7359d10048f68ab8b09fa71c3daccfb0e9b559aed648a8f95469c27057180c" - [[package]] name = "windows_i686_msvc" version = "0.48.5" @@ -4530,12 +4460,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" -[[package]] -name = "windows_i686_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e7ac75179f18232fe9c285163565a57ef8d3c89254a30685b57d83a38d326c2" - [[package]] name = "windows_x86_64_gnu" version = "0.48.5" @@ -4548,12 +4472,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" -[[package]] -name = "windows_x86_64_gnu" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c3842cdd74a865a8066ab39c8a7a473c0778a3f29370b5fd6b4b9aa7df4a499" - [[package]] name = "windows_x86_64_gnullvm" version = "0.48.5" @@ -4566,12 +4484,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0ffa179e2d07eee8ad8f57493436566c7cc30ac536a3379fdf008f47f6bb7ae1" - [[package]] name = "windows_x86_64_msvc" version = "0.48.5" @@ -4584,12 +4496,6 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" -[[package]] -name = "windows_x86_64_msvc" -version = "0.53.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6bbff5f0aada427a1e5a6da5f1f98158182f26556f345ac9e04d36d0ebed650" - [[package]] name = "wit-bindgen" version = "0.57.1" diff --git a/src/server/api.rs b/src/server/api.rs index faf11b7..c8aeeb9 100644 --- a/src/server/api.rs +++ b/src/server/api.rs @@ -1,7 +1,7 @@ use crate::load_keyring; use crate::sql::sql; use crate::sql::sql::{get_by_user_id, get_iota_by_id, get_omikron_by_id}; -use crate::sql::user_online_tracker::get_iota_primary_omikron_connection; +use crate::sql::user_online_tracker::{get_all_connections, get_iota_primary_omikron_connection}; use crate::transport::omikron_manager::get_random_omikron; use crate::util::file_util::get_directory; use actix_web::HttpResponse; @@ -151,6 +151,31 @@ pub async fn handle(path: &str, body_string: Option) -> HttpResponse { } } + ["api", "get", "connections"] => { + if let Ok(connections) = get_all_connections().await { + let mut res = JsonValue::new_object(); + res["status"] = "success".into(); + + for (omikron_id, iota_map) in connections { + let mut omikron_obj = JsonValue::new_object(); + for (iota_id, user_ids) in iota_map { + let mut user_arr = JsonValue::new_array(); + for user_id in user_ids { + let _ = user_arr.push(user_id); + } + omikron_obj[&iota_id.to_string()] = user_arr; + } + res[&omikron_id.to_string()] = omikron_obj; + } + + (StatusCode::OK, res.dump()) + } else { + let mut res = JsonValue::new_object(); + res["status"] = "error".into(); + (StatusCode::INTERNAL_SERVER_ERROR, res.dump()) + } + } + // ================================================== // GET IOTA BY ID // ================================================== diff --git a/src/sql/user_online_tracker.rs b/src/sql/user_online_tracker.rs index 304d5b5..288fcdc 100644 --- a/src/sql/user_online_tracker.rs +++ b/src/sql/user_online_tracker.rs @@ -67,6 +67,46 @@ pub fn get_iota_omikron_connections(iota_id: i64) -> Option> { IOTA_OMIKRON_CONNECTIONS.get(&iota_id).map(|v| v.clone()) } +pub async fn get_all_connections() +-> Result>>, ()> { + let mut result: std::collections::HashMap>> = + std::collections::HashMap::new(); + + for entry in IOTA_OMIKRON_CONNECTIONS.iter() { + let iota_id = *entry.key(); + for omikron_id in entry.value().iter() { + result + .entry(*omikron_id) + .or_insert_with(std::collections::HashMap::new) + .entry(iota_id) + .or_insert_with(Vec::new); + } + } + + for entry in IOTA_OMIKRON_CONNECTIONS.iter() { + let iota_id = *entry.key(); + let omikron_ids = entry.value().clone(); + + if let Ok(users) = sql::sql::get_users_by_iota_id(iota_id.try_into().unwrap()).await { + for user in users { + let user_id = user.0 as i64; + if let Some(conn) = USER_STATUS_MAP.get(&user_id) { + let user_omikron_id = conn.omikron_id; + if omikron_ids.contains(&user_omikron_id) { + if let Some(iota_map) = result.get_mut(&user_omikron_id) { + if let Some(user_vec) = iota_map.get_mut(&iota_id) { + user_vec.push(user_id); + } + } + } + } + } + } + } + + Ok(result) +} + pub fn track_user_status(user_id: i64, status: UserStatus, omikron_id: i64) { USER_STATUS_MAP.insert( user_id, diff --git a/src/transport/omikron_connection.rs b/src/transport/omikron_connection.rs index 2b2ba69..2da779d 100644 --- a/src/transport/omikron_connection.rs +++ b/src/transport/omikron_connection.rs @@ -304,6 +304,7 @@ impl OmikronConnection { let response = CommunicationValue::new(CommunicationType::IotaUserData) .with_id(cv.get_id()) + .add_typed_default(DataType::IotaId, DataValue::SignedNumber(iota_id.into())) .add_typed_default(DataType::UserIds, DataValue::Array(user_ids)); let _ = self.send(&response).await; diff --git a/type-maps.yaml b/type-maps.yaml index 73a15e3..6d51730 100644 --- a/type-maps.yaml +++ b/type-maps.yaml @@ -1,46 +1,6 @@ # The version a Client should use protocol_version: "1.0" -# Note that markers 0 to 31 are reserved for default use, manually working with them is not recommended -# Fixed CommunicationType markers are: -# Error: 0 -# ErrorParsing: 1 -# ErrorBadVersion: 2 -# Disconnect: 3 -# Redirect: 4 -# Shutdown: 5 -# BadRequest: 6 -# Unauthorized: 7 -# Forbidden: 8 -# NotFound: 9 -# TooManyRequests: 10 -# InternalServerError: 11 -# BadGateway: 12 -# ServiceUnavailable: 13 -# GatewayTimeout: 14 -# Identification: 15 -# IdentificationResponse: 16 -# Register: 17 -# RegisterResponse: 18 -# Ping: 19 -# Pong: 20 -# -# Fixed Data Type markers are: -# Error: 0 -# ErrorParsing: 1 -# ErrorMessage: 2 -# Version: 3 -# Description: 4 -# Timestamp: 5 -# Id: 6 -# ClientNonce: 7 -# ServerNonce: 8 -# PublicKeys: 9 -# Signature: 10 -# Connected: 11 -# -# If a Type can't be used it will be mapped to 0 - type_maps: "1.0": # Protocol version 1.0 CommunicationTypes: