From 0af08f5096693881a03c5914906e783b7dd99288 Mon Sep 17 00:00:00 2001 From: Bug Magnet Date: Fri, 14 Jun 2024 10:19:31 +0200 Subject: [PATCH] Clean up the code --- .../src/ios_ffi/ios_runtime.rs | 16 +++++++++----- .../src/ios_ffi/ios_tcp_connection.rs | 22 ++++++++----------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/talpid-tunnel-config-client/src/ios_ffi/ios_runtime.rs b/talpid-tunnel-config-client/src/ios_ffi/ios_runtime.rs index 509b38c461c1..1ab08a19bc21 100644 --- a/talpid-tunnel-config-client/src/ios_ffi/ios_runtime.rs +++ b/talpid-tunnel-config-client/src/ios_ffi/ios_runtime.rs @@ -96,8 +96,8 @@ impl IOSRuntime { self.run_service_inner(); }); } - /// Creates a `RelayConfigService` using the in-tunnel TCP Connection provided by the Packet - /// Tunnel Provider # Safety + /// Creates a `RelayConfigService` using the in-tunnel TCP Connection provided by the Packet Tunnel Provider + /// # Safety /// It is unsafe to call this with an already used `SwiftContext` async unsafe fn ios_tcp_client( ctx: SwiftContext, @@ -153,16 +153,20 @@ impl IOSRuntime { let preshared_key_bytes = preshared_key.as_bytes(); swift_post_quantum_key_ready(packet_tunnel_ptr, preshared_key_bytes.as_ptr(), self.ephemeral_key.as_ptr()); }, - None => unsafe { + None => { log::error!("No suitable peer was found"); - swift_post_quantum_key_ready(packet_tunnel_ptr, ptr::null(), ptr::null()); + unsafe { + swift_post_quantum_key_ready(packet_tunnel_ptr, ptr::null(), ptr::null()); + } } } }, - Err(error) => unsafe { + Err(error) => { log::error!("Key exchange failed {}", error); - swift_post_quantum_key_ready(packet_tunnel_ptr, ptr::null(), ptr::null()); + unsafe { + swift_post_quantum_key_ready(packet_tunnel_ptr, ptr::null(), ptr::null()); + } } } } diff --git a/talpid-tunnel-config-client/src/ios_ffi/ios_tcp_connection.rs b/talpid-tunnel-config-client/src/ios_ffi/ios_tcp_connection.rs index 656bb142c85e..b550cc69b3e0 100644 --- a/talpid-tunnel-config-client/src/ios_ffi/ios_tcp_connection.rs +++ b/talpid-tunnel-config-client/src/ios_ffi/ios_tcp_connection.rs @@ -64,7 +64,7 @@ unsafe impl Send for ConnectionContext {} impl IosTcpProvider { /// # Safety - /// `tcp_connection` must be pointing to a valid instance of a `NWTCPConnection`, created by the + /// `connection` must be pointing to a valid instance of a `NWTCPConnection`, created by the /// `PacketTunnelProvider` pub unsafe fn new(connection: Arc>) -> (Self, IosTcpShutdownHandle) { let (tx, rx) = mpsc::unbounded_channel(); @@ -93,17 +93,15 @@ impl IosTcpProvider { impl IosTcpShutdownHandle { pub fn shutdown(self) { - { - let Ok(mut context) = self.context.lock() else { - return; - }; - - context.tcp_connection = None; - if let Some(waker) = context.waker.take() { - waker.wake(); - } - std::mem::drop(context); + let Ok(mut context) = self.context.lock() else { + return; + }; + + context.tcp_connection = None; + if let Some(waker) = context.waker.take() { + waker.wake(); } + std::mem::drop(context); } } @@ -136,7 +134,6 @@ impl AsyncWrite for IosTcpProvider { let raw_sender = Weak::into_raw(Arc::downgrade(&self.write_tx)); unsafe { swift_nw_tcp_connection_send( - // self.tcp_connection, tcp_ptr, buf.as_ptr() as _, buf.len(), @@ -193,7 +190,6 @@ impl AsyncRead for IosTcpProvider { if !self.read_in_progress { let raw_sender = Weak::into_raw(Arc::downgrade(&self.read_tx)); unsafe { - // TODO swift_nw_tcp_connection_read(tcp_ptr, raw_sender as _); } self.read_in_progress = true;