Skip to content

Commit 0af08f5

Browse files
committed
Clean up the code
1 parent 9030a3b commit 0af08f5

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

talpid-tunnel-config-client/src/ios_ffi/ios_runtime.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ impl IOSRuntime {
9696
self.run_service_inner();
9797
});
9898
}
99-
/// Creates a `RelayConfigService` using the in-tunnel TCP Connection provided by the Packet
100-
/// Tunnel Provider # Safety
99+
/// Creates a `RelayConfigService` using the in-tunnel TCP Connection provided by the Packet Tunnel Provider
100+
/// # Safety
101101
/// It is unsafe to call this with an already used `SwiftContext`
102102
async unsafe fn ios_tcp_client(
103103
ctx: SwiftContext,
@@ -153,16 +153,20 @@ impl IOSRuntime {
153153
let preshared_key_bytes = preshared_key.as_bytes();
154154
swift_post_quantum_key_ready(packet_tunnel_ptr, preshared_key_bytes.as_ptr(), self.ephemeral_key.as_ptr());
155155
},
156-
None => unsafe {
156+
None => {
157157
log::error!("No suitable peer was found");
158-
swift_post_quantum_key_ready(packet_tunnel_ptr, ptr::null(), ptr::null());
158+
unsafe {
159+
swift_post_quantum_key_ready(packet_tunnel_ptr, ptr::null(), ptr::null());
160+
}
159161
}
160162

161163
}
162164
},
163-
Err(error) => unsafe {
165+
Err(error) => {
164166
log::error!("Key exchange failed {}", error);
165-
swift_post_quantum_key_ready(packet_tunnel_ptr, ptr::null(), ptr::null());
167+
unsafe {
168+
swift_post_quantum_key_ready(packet_tunnel_ptr, ptr::null(), ptr::null());
169+
}
166170
}
167171
}
168172
}

talpid-tunnel-config-client/src/ios_ffi/ios_tcp_connection.rs

+9-13
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ unsafe impl Send for ConnectionContext {}
6464

6565
impl IosTcpProvider {
6666
/// # Safety
67-
/// `tcp_connection` must be pointing to a valid instance of a `NWTCPConnection`, created by the
67+
/// `connection` must be pointing to a valid instance of a `NWTCPConnection`, created by the
6868
/// `PacketTunnelProvider`
6969
pub unsafe fn new(connection: Arc<Mutex<ConnectionContext>>) -> (Self, IosTcpShutdownHandle) {
7070
let (tx, rx) = mpsc::unbounded_channel();
@@ -93,17 +93,15 @@ impl IosTcpProvider {
9393

9494
impl IosTcpShutdownHandle {
9595
pub fn shutdown(self) {
96-
{
97-
let Ok(mut context) = self.context.lock() else {
98-
return;
99-
};
100-
101-
context.tcp_connection = None;
102-
if let Some(waker) = context.waker.take() {
103-
waker.wake();
104-
}
105-
std::mem::drop(context);
96+
let Ok(mut context) = self.context.lock() else {
97+
return;
98+
};
99+
100+
context.tcp_connection = None;
101+
if let Some(waker) = context.waker.take() {
102+
waker.wake();
106103
}
104+
std::mem::drop(context);
107105
}
108106
}
109107

@@ -136,7 +134,6 @@ impl AsyncWrite for IosTcpProvider {
136134
let raw_sender = Weak::into_raw(Arc::downgrade(&self.write_tx));
137135
unsafe {
138136
swift_nw_tcp_connection_send(
139-
// self.tcp_connection,
140137
tcp_ptr,
141138
buf.as_ptr() as _,
142139
buf.len(),
@@ -193,7 +190,6 @@ impl AsyncRead for IosTcpProvider {
193190
if !self.read_in_progress {
194191
let raw_sender = Weak::into_raw(Arc::downgrade(&self.read_tx));
195192
unsafe {
196-
// TODO
197193
swift_nw_tcp_connection_read(tcp_ptr, raw_sender as _);
198194
}
199195
self.read_in_progress = true;

0 commit comments

Comments
 (0)