Skip to content

Commit

Permalink
Clean up the code
Browse files Browse the repository at this point in the history
  • Loading branch information
buggmagnet committed Jun 14, 2024
1 parent 7fba9e1 commit 76d6ac5
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
16 changes: 10 additions & 6 deletions talpid-tunnel-config-client/src/ios_ffi/ios_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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());
}
}
}
}
Expand Down
22 changes: 9 additions & 13 deletions talpid-tunnel-config-client/src/ios_ffi/ios_tcp_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Mutex<ConnectionContext>>) -> (Self, IosTcpShutdownHandle) {
let (tx, rx) = mpsc::unbounded_channel();
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 76d6ac5

Please sign in to comment.