From d56e6c8a03b3702404f9982500bfe5c1bc92b6cf Mon Sep 17 00:00:00 2001 From: Alex Emmet <111742636+Alex-Emmet@users.noreply.github.com> Date: Sat, 4 Jul 2026 23:02:02 +0200 Subject: [PATCH] [Fix]Connection Stability --- Cargo.lock | 147 +++++++++++++------------------------ src/rho/connection.rs | 2 + src/rho/iota_connection.rs | 2 + src/rho/server.rs | 24 ++++-- type-maps.yaml | 40 ---------- 5 files changed, 73 insertions(+), 142 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1547438..cc9e8f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -406,6 +406,17 @@ dependencies = [ "cpufeatures 0.2.17", ] +[[package]] +name = "chacha20" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d524456ba66e72eb8b115ff89e01e497f8e6d11d78b70b1aa13c0fbd97540a81" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.0", + "rand_core 0.10.1", +] + [[package]] name = "chacha20poly1305" version = "0.10.1" @@ -413,7 +424,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "10cd79432192d1c0f4e1a0fef9527696cc039165d729fb41b3f4f4f354c2dc35" dependencies = [ "aead", - "chacha20", + "chacha20 0.9.1", "cipher", "poly1305", "zeroize", @@ -1009,11 +1020,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]] @@ -1023,9 +1032,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]] @@ -1722,7 +1733,7 @@ dependencies = [ [[package]] name = "mtp" version = "0.1.0" -source = "git+https://git.methanium.net/Methanium/mtp.git#b96c072a0f87de7828e45cf3dcd44aef4a9e459d" +source = "git+https://git.methanium.net/Methanium/mtp.git#2e7c0b489360d5d05fe53326811616e730c1a556" dependencies = [ "mtp-client", "mtp-codec", @@ -1730,14 +1741,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.git#b96c072a0f87de7828e45cf3dcd44aef4a9e459d" +source = "git+https://git.methanium.net/Methanium/mtp.git#2e7c0b489360d5d05fe53326811616e730c1a556" dependencies = [ "mtp-codec", "mtp-common", @@ -1750,7 +1760,7 @@ dependencies = [ [[package]] name = "mtp-codec" version = "0.1.0" -source = "git+https://git.methanium.net/Methanium/mtp.git#b96c072a0f87de7828e45cf3dcd44aef4a9e459d" +source = "git+https://git.methanium.net/Methanium/mtp.git#2e7c0b489360d5d05fe53326811616e730c1a556" dependencies = [ "base64 0.22.1", "byteorder", @@ -1763,7 +1773,7 @@ dependencies = [ [[package]] name = "mtp-common" version = "0.1.0" -source = "git+https://git.methanium.net/Methanium/mtp.git#b96c072a0f87de7828e45cf3dcd44aef4a9e459d" +source = "git+https://git.methanium.net/Methanium/mtp.git#2e7c0b489360d5d05fe53326811616e730c1a556" dependencies = [ "quinn", "rustls", @@ -1774,7 +1784,7 @@ dependencies = [ [[package]] name = "mtp-crypto" version = "0.1.0" -source = "git+https://git.methanium.net/Methanium/mtp.git#b96c072a0f87de7828e45cf3dcd44aef4a9e459d" +source = "git+https://git.methanium.net/Methanium/mtp.git#2e7c0b489360d5d05fe53326811616e730c1a556" dependencies = [ "base64 0.22.1", "chacha20poly1305", @@ -1793,7 +1803,7 @@ dependencies = [ [[package]] name = "mtp-files" version = "0.1.0" -source = "git+https://git.methanium.net/Methanium/mtp.git#b96c072a0f87de7828e45cf3dcd44aef4a9e459d" +source = "git+https://git.methanium.net/Methanium/mtp.git#2e7c0b489360d5d05fe53326811616e730c1a556" dependencies = [ "mtp-crypto", "thiserror 1.0.69", @@ -1802,7 +1812,7 @@ dependencies = [ [[package]] name = "mtp-host" version = "0.1.0" -source = "git+https://git.methanium.net/Methanium/mtp.git#b96c072a0f87de7828e45cf3dcd44aef4a9e459d" +source = "git+https://git.methanium.net/Methanium/mtp.git#2e7c0b489360d5d05fe53326811616e730c1a556" dependencies = [ "mtp-codec", "mtp-common", @@ -1815,7 +1825,7 @@ dependencies = [ [[package]] name = "mtp-transport" version = "0.1.0" -source = "git+https://git.methanium.net/Methanium/mtp.git#b96c072a0f87de7828e45cf3dcd44aef4a9e459d" +source = "git+https://git.methanium.net/Methanium/mtp.git#2e7c0b489360d5d05fe53326811616e730c1a556" dependencies = [ "log", "mtp-codec", @@ -1829,7 +1839,7 @@ dependencies = [ [[package]] name = "mtp-type-map" version = "0.1.0" -source = "git+https://git.methanium.net/Methanium/mtp.git#b96c072a0f87de7828e45cf3dcd44aef4a9e459d" +source = "git+https://git.methanium.net/Methanium/mtp.git#2e7c0b489360d5d05fe53326811616e730c1a556" dependencies = [ "serde", "serde_yaml", @@ -2490,15 +2500,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", @@ -2512,16 +2523,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", "tracing", - "windows-sys 0.60.2", + "windows-sys 0.61.2", ] [[package]] @@ -2566,6 +2577,17 @@ dependencies = [ "rand_core 0.9.5", ] +[[package]] +name = "rand" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80" +dependencies = [ + "chacha20 0.10.1", + "getrandom 0.4.3", + "rand_core 0.10.1", +] + [[package]] name = "rand_chacha" version = "0.3.1" @@ -2610,6 +2632,15 @@ 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" @@ -3721,15 +3752,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" @@ -3763,30 +3785,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.42.2" @@ -3799,12 +3804,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.42.2" @@ -3817,12 +3816,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.42.2" @@ -3835,24 +3828,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.42.2" @@ -3865,12 +3846,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.42.2" @@ -3883,12 +3858,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.42.2" @@ -3901,12 +3870,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.42.2" @@ -3919,12 +3882,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/rho/connection.rs b/src/rho/connection.rs index 431a846..90abac0 100755 --- a/src/rho/connection.rs +++ b/src/rho/connection.rs @@ -296,6 +296,8 @@ impl GeneralConnection { client.start(); } ConnectionKind::Iota => { + log_in!(id as i64, PrintType::Iota, "Iota {} connected", id); + let notify = CommunicationValue::new(CommunicationType::IotaConnected) .add_typed_default(DataType::IotaId, DataValue::SignedNumber(id.into())); get_omega_connection().send_message(¬ify).await; diff --git a/src/rho/iota_connection.rs b/src/rho/iota_connection.rs index c872ccb..dca059c 100755 --- a/src/rho/iota_connection.rs +++ b/src/rho/iota_connection.rs @@ -4,6 +4,7 @@ use crate::log_cv_in; use crate::log_cv_out; use crate::log_err; use crate::log_in; +use crate::log_out; use crate::omega::omega_connection::get_omega_connection; use crate::rho::connection::GeneralConnection; use crate::util::logger::PrintType; @@ -493,6 +494,7 @@ impl IotaConnection { } pub async fn handle_close(&self) { + log_out!(self.iota_id as i64, PrintType::Iota, "Iota {} disconnected", self.iota_id); if let Some(rho_conn) = self.get_rho_connection().await { rho_conn.close_iota_connection().await; } diff --git a/src/rho/server.rs b/src/rho/server.rs index 951f52b..1b0abf3 100644 --- a/src/rho/server.rs +++ b/src/rho/server.rs @@ -27,8 +27,11 @@ pub async fn get_by_connector_id( description: Option, ) -> Option { let request = match description.as_deref() { - Some("iota") => CommunicationValue::new(CommunicationType::GetIotaData) - .add_typed_default(DataType::IotaId, DataValue::SignedNumber(client_id as i128)), + Some("iota") => { + println!("Iota connection request for client_id: {}", client_id); + CommunicationValue::new(CommunicationType::GetIotaData) + .add_typed_default(DataType::IotaId, DataValue::SignedNumber(client_id as i128)) + } Some("client") => CommunicationValue::new(CommunicationType::GetUserData) .add_typed_default(DataType::UserId, DataValue::SignedNumber(client_id as i128)), _ => return None, @@ -59,9 +62,11 @@ pub async fn get_by_connector_id( /* Only Iota registration goes through mtp's Register flow; users are registered out of band. */ pub async fn complete_register(pub_key: PublicKeyBundle, description: Option) -> u64 { + println!("Iota register start"); if description.as_deref() != Some("iota") { return 0; } + println!("Iota connection request"); let request = CommunicationValue::new(CommunicationType::CompleteRegisterIota) .add_typed_default( @@ -126,16 +131,21 @@ pub async fn start(port: u16) -> Result<(), Box> { .with_authentication_policy(AuthenticationPolicy::AllowAuthentication); let mut host: Host = Host::new(host_config).await?; - log!(0, PrintType::General, "Server listening on port {}", port); + log!(0, PrintType::General, "Server listening on port {}.", port); loop { let conn = match host.accept().await { - Ok(Some(conn)) => conn, + Ok(Some(conn)) => { + println!("Accepted connection"); + conn + } Ok(None) => break, Err(e) => { - // A single client's failed/aborted handshake (bad auth, a - // probe, a mid-handshake disconnect) must not take down the - // whole listener - only that connection attempt is lost. + /* + * A single client's failed/aborted handshake (bad auth, a + * probe, a mid-handshake disconnect) must not take down the + * whole listener, only that connection attempt is lost. + */ log_err!(0, PrintType::General, "Rejected connection: {}", e); continue; } diff --git a/type-maps.yaml b/type-maps.yaml index 5cd196f..7fecac8 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: