From 869b8ad2d7d09207730fae8cc3c371e32162a1ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20L=C3=B6nnhager?= Date: Mon, 12 Aug 2024 16:51:46 +0200 Subject: [PATCH] Rename tunnel provider getTun to openTun --- .../net/mullvad/talpid/TalpidVpnService.kt | 10 +++++----- .../tunnel_state_machine/connecting_state.rs | 2 +- talpid-core/src/tunnel_state_machine/mod.rs | 2 +- talpid-tunnel/src/tun_provider/android/mod.rs | 20 +++++++++---------- talpid-tunnel/src/tun_provider/stub.rs | 2 +- talpid-tunnel/src/tun_provider/unix.rs | 3 ++- talpid-wireguard/src/wireguard_go/mod.rs | 2 +- 7 files changed, 21 insertions(+), 20 deletions(-) diff --git a/android/lib/talpid/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt b/android/lib/talpid/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt index e3d9d935257d..1c4b51a52038 100644 --- a/android/lib/talpid/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt +++ b/android/lib/talpid/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt @@ -43,25 +43,25 @@ open class TalpidVpnService : LifecycleVpnService() { connectivityListener.unregister() } - fun getTun(config: TunConfig): CreateTunResult { + fun openTun(config: TunConfig): CreateTunResult { synchronized(this) { val tunStatus = activeTunStatus if (config == currentTunConfig && tunStatus != null && tunStatus.isOpen) { return tunStatus } else { - return getTunImpl(config) + return openTunImpl(config) } } } - fun getTunForced(config: TunConfig): CreateTunResult { + fun openTunForced(config: TunConfig): CreateTunResult { synchronized(this) { - return getTunImpl(config) + return openTunImpl(config) } } - private fun getTunImpl(config: TunConfig): CreateTunResult { + private fun openTunImpl(config: TunConfig): CreateTunResult { val newTunStatus = createTun(config) currentTunConfig = config diff --git a/talpid-core/src/tunnel_state_machine/connecting_state.rs b/talpid-core/src/tunnel_state_machine/connecting_state.rs index 91944a5a54e7..d9a58a0ea723 100644 --- a/talpid-core/src/tunnel_state_machine/connecting_state.rs +++ b/talpid-core/src/tunnel_state_machine/connecting_state.rs @@ -103,7 +103,7 @@ impl ConnectingState { shared_values.prepare_tun_config(false); if retry_attempt > 0 && retry_attempt % MAX_ATTEMPTS_WITH_SAME_TUN == 0 { if let Err(error) = - { shared_values.tun_provider.lock().unwrap().get_tun_forced() } + { shared_values.tun_provider.lock().unwrap().open_tun_forced() } { log::error!( "{}", diff --git a/talpid-core/src/tunnel_state_machine/mod.rs b/talpid-core/src/tunnel_state_machine/mod.rs index e0007fcaa7bc..7ea15be575f7 100644 --- a/talpid-core/src/tunnel_state_machine/mod.rs +++ b/talpid-core/src/tunnel_state_machine/mod.rs @@ -639,7 +639,7 @@ impl SharedTunnelStateValues { pub fn restart_tunnel(&self, blocking: bool) -> Result<(), talpid_tunnel::tun_provider::Error> { self.prepare_tun_config(blocking); - match self.tun_provider.lock().unwrap().get_tun() { + match self.tun_provider.lock().unwrap().open_tun() { Ok(_tun) => Ok(()), Err(error) => { log::error!( diff --git a/talpid-tunnel/src/tun_provider/android/mod.rs b/talpid-tunnel/src/tun_provider/android/mod.rs index c77a3c2fb859..d50aced6be91 100644 --- a/talpid-tunnel/src/tun_provider/android/mod.rs +++ b/talpid-tunnel/src/tun_provider/android/mod.rs @@ -83,20 +83,20 @@ impl AndroidTunProvider { &mut self.config } - /// Retrieve a tunnel device with the provided configuration. - pub fn get_tun(&mut self) -> Result { - self.get_tun_inner("getTun") + /// Open a tunnel with the current configuration. + pub fn open_tun(&mut self) -> Result { + self.open_tun_inner("openTun") } - /// Retrieve a tunnel device with the provided configuration. + /// Open a tunnel with the current configuration. /// Force recreation even if the tunnel config hasn't changed. - pub fn get_tun_forced(&mut self) -> Result { - self.get_tun_inner("getTunForced") + pub fn open_tun_forced(&mut self) -> Result { + self.open_tun_inner("openTunForced") } - /// Retrieve a tunnel device with the provided configuration. - fn get_tun_inner(&mut self, get_tun_func_name: &'static str) -> Result { - let tun_fd = self.get_tun_fd(get_tun_func_name)?; + /// Open a tunnel with the current configuration. + fn open_tun_inner(&mut self, get_tun_func_name: &'static str) -> Result { + let tun_fd = self.open_tun_fd(get_tun_func_name)?; let jvm = unsafe { JavaVM::from_raw(self.jvm.get_java_vm_pointer()) } .map_err(Error::CloneJavaVm)?; @@ -109,7 +109,7 @@ impl AndroidTunProvider { }) } - fn get_tun_fd(&self, get_tun_func_name: &'static str) -> Result { + fn open_tun_fd(&self, get_tun_func_name: &'static str) -> Result { let config = VpnServiceConfig::new(self.config.clone()); let env = self.env()?; diff --git a/talpid-tunnel/src/tun_provider/stub.rs b/talpid-tunnel/src/tun_provider/stub.rs index 4227c2f8fbb6..6635c79f15f4 100644 --- a/talpid-tunnel/src/tun_provider/stub.rs +++ b/talpid-tunnel/src/tun_provider/stub.rs @@ -11,7 +11,7 @@ impl StubTunProvider { StubTunProvider } - pub fn get_tun(&mut self, _: TunConfig) -> Result<(), Error> { + pub fn open_tun(&mut self, _: TunConfig) -> Result<(), Error> { unimplemented!(); } } diff --git a/talpid-tunnel/src/tun_provider/unix.rs b/talpid-tunnel/src/tun_provider/unix.rs index 01498ea9f2d0..672d79207f38 100644 --- a/talpid-tunnel/src/tun_provider/unix.rs +++ b/talpid-tunnel/src/tun_provider/unix.rs @@ -42,7 +42,8 @@ impl UnixTunProvider { &mut self.config } - pub fn get_tun(&mut self) -> Result { + /// Open a tunnel using the current tunnel config. + pub fn open_tun(&mut self) -> Result { let mut tunnel_device = TunnelDevice::new().map_err(Error::CreateTunnelDevice)?; for ip in self.config.addresses.iter() { diff --git a/talpid-wireguard/src/wireguard_go/mod.rs b/talpid-wireguard/src/wireguard_go/mod.rs index 859abcb909d2..f117beb71279 100644 --- a/talpid-wireguard/src/wireguard_go/mod.rs +++ b/talpid-wireguard/src/wireguard_go/mod.rs @@ -142,7 +142,7 @@ impl WgGoTunnel { for _ in 1..=MAX_PREPARE_TUN_ATTEMPTS { let tunnel_device = tun_provider - .get_tun() + .open_tun() .map_err(TunnelError::SetupTunnelDevice)?; match nix::unistd::dup(tunnel_device.as_raw_fd()) {