1
1
//! This module takes care of obtaining ephemeral peers, updating the WireGuard configuration and
2
2
//! restarting obfuscation and WG tunnels when necessary.
3
3
4
- #[ cfg( force_wireguard_handshake) ]
5
- use super :: connectivity;
6
4
#[ cfg( target_os = "android" ) ] // On Android, the Tunnel trait is not imported by default.
7
5
use super :: Tunnel ;
8
6
use super :: { config:: Config , obfuscation:: ObfuscatorHandle , CloseMsg , Error , TunnelType } ;
@@ -33,9 +31,6 @@ pub async fn config_ephemeral_peers(
33
31
retry_attempt : u32 ,
34
32
obfuscator : Arc < AsyncMutex < Option < ObfuscatorHandle > > > ,
35
33
close_obfs_sender : sync_mpsc:: Sender < CloseMsg > ,
36
- #[ cfg( force_wireguard_handshake) ] connectivity : & mut connectivity:: Check <
37
- connectivity:: Cancellable ,
38
- > ,
39
34
) -> std:: result:: Result < ( ) , CloseMsg > {
40
35
let iface_name = {
41
36
let tunnel = tunnel. lock ( ) . await ;
@@ -49,16 +44,8 @@ pub async fn config_ephemeral_peers(
49
44
log:: trace!( "Temporarily lowering tunnel MTU before ephemeral peer config" ) ;
50
45
try_set_ipv4_mtu ( & iface_name, talpid_tunnel:: MIN_IPV4_MTU ) ;
51
46
52
- config_ephemeral_peers_inner (
53
- tunnel,
54
- config,
55
- retry_attempt,
56
- obfuscator,
57
- close_obfs_sender,
58
- #[ cfg( force_wireguard_handshake) ]
59
- connectivity,
60
- )
61
- . await ?;
47
+ config_ephemeral_peers_inner ( tunnel, config, retry_attempt, obfuscator, close_obfs_sender)
48
+ . await ?;
62
49
63
50
log:: trace!( "Resetting tunnel MTU" ) ;
64
51
try_set_ipv4_mtu ( & iface_name, config. mtu ) ;
@@ -88,9 +75,6 @@ pub async fn config_ephemeral_peers(
88
75
retry_attempt : u32 ,
89
76
obfuscator : Arc < AsyncMutex < Option < ObfuscatorHandle > > > ,
90
77
close_obfs_sender : sync_mpsc:: Sender < CloseMsg > ,
91
- #[ cfg( force_wireguard_handshake) ] connectivity : & mut connectivity:: Check <
92
- connectivity:: Cancellable ,
93
- > ,
94
78
#[ cfg( target_os = "android" ) ] tun_provider : Arc < Mutex < TunProvider > > ,
95
79
) -> Result < ( ) , CloseMsg > {
96
80
config_ephemeral_peers_inner (
@@ -99,8 +83,6 @@ pub async fn config_ephemeral_peers(
99
83
retry_attempt,
100
84
obfuscator,
101
85
close_obfs_sender,
102
- #[ cfg( force_wireguard_handshake) ]
103
- connectivity,
104
86
#[ cfg( target_os = "android" ) ]
105
87
tun_provider,
106
88
)
@@ -113,16 +95,8 @@ async fn config_ephemeral_peers_inner(
113
95
retry_attempt : u32 ,
114
96
obfuscator : Arc < AsyncMutex < Option < ObfuscatorHandle > > > ,
115
97
close_obfs_sender : sync_mpsc:: Sender < CloseMsg > ,
116
- #[ cfg( force_wireguard_handshake) ] connectivity : & mut connectivity:: Check <
117
- connectivity:: Cancellable ,
118
- > ,
119
98
#[ cfg( target_os = "android" ) ] tun_provider : Arc < Mutex < TunProvider > > ,
120
99
) -> Result < ( ) , CloseMsg > {
121
- // NOTE: This one often fails with multihop on Windows, even though the handshake afterwards
122
- // succeeds. So we try anyway if it fails.
123
- #[ cfg( force_wireguard_handshake) ]
124
- let _ = establish_tunnel_connection ( tunnel, connectivity) ;
125
-
126
100
let ephemeral_private_key = PrivateKey :: new_from_random ( ) ;
127
101
let close_obfs_sender = close_obfs_sender. clone ( ) ;
128
102
@@ -160,10 +134,6 @@ async fn config_ephemeral_peers_inner(
160
134
& tun_provider,
161
135
)
162
136
. await ?;
163
-
164
- #[ cfg( force_wireguard_handshake) ]
165
- establish_tunnel_connection ( tunnel, connectivity) ?;
166
-
167
137
let entry_ephemeral_peer = request_ephemeral_peer (
168
138
retry_attempt,
169
139
& entry_config,
@@ -244,6 +214,7 @@ async fn reconfigure_tunnel(
244
214
* obfs_guard = super :: obfuscation:: apply_obfuscation_config (
245
215
& mut config,
246
216
close_obfs_sender,
217
+ #[ cfg( target_os = "android" ) ]
247
218
tun_provider. clone ( ) ,
248
219
)
249
220
. await
@@ -297,37 +268,6 @@ async fn reconfigure_tunnel(
297
268
Ok ( config)
298
269
}
299
270
300
- /// Ensure that the WireGuard tunnel works. This is useful after updating the WireGuard config, to
301
- /// force a WireGuard handshake. This should reduce the number of PQ timeouts.
302
- #[ cfg( force_wireguard_handshake) ]
303
- fn establish_tunnel_connection (
304
- tunnel : & Arc < AsyncMutex < Option < TunnelType > > > ,
305
- connectivity : & mut connectivity:: Check < connectivity:: Cancellable > ,
306
- ) -> Result < ( ) , CloseMsg > {
307
- use talpid_types:: ErrorExt ;
308
-
309
- let ping_result = tokio:: task:: block_in_place ( || {
310
- let shared_tunnel = tunnel. blocking_lock ( ) ;
311
- let tunnel = shared_tunnel. as_ref ( ) . expect ( "tunnel was None" ) ;
312
- connectivity. establish_connectivity ( tunnel)
313
- } ) ;
314
-
315
- match ping_result {
316
- Ok ( true ) => Ok ( ( ) ) ,
317
- Ok ( false ) => {
318
- log:: warn!( "Timeout while checking tunnel connection" ) ;
319
- Err ( CloseMsg :: PingErr )
320
- }
321
- Err ( error) => {
322
- log:: error!(
323
- "{}" ,
324
- error. display_chain_with_msg( "Failed to check tunnel connection" )
325
- ) ;
326
- Err ( CloseMsg :: PingErr )
327
- }
328
- }
329
- }
330
-
331
271
async fn request_ephemeral_peer (
332
272
retry_attempt : u32 ,
333
273
config : & Config ,
0 commit comments