Skip to content

Commit

Permalink
Rename tunnel provider getTun to openTun
Browse files Browse the repository at this point in the history
  • Loading branch information
dlon committed Aug 13, 2024
1 parent c424070 commit 869b8ad
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion talpid-core/src/tunnel_state_machine/connecting_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
"{}",
Expand Down
2 changes: 1 addition & 1 deletion talpid-core/src/tunnel_state_machine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
20 changes: 10 additions & 10 deletions talpid-tunnel/src/tun_provider/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,20 +83,20 @@ impl AndroidTunProvider {
&mut self.config
}

/// Retrieve a tunnel device with the provided configuration.
pub fn get_tun(&mut self) -> Result<VpnServiceTun, Error> {
self.get_tun_inner("getTun")
/// Open a tunnel with the current configuration.
pub fn open_tun(&mut self) -> Result<VpnServiceTun, Error> {
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<VpnServiceTun, Error> {
self.get_tun_inner("getTunForced")
pub fn open_tun_forced(&mut self) -> Result<VpnServiceTun, Error> {
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<VpnServiceTun, Error> {
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<VpnServiceTun, Error> {
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)?;
Expand All @@ -109,7 +109,7 @@ impl AndroidTunProvider {
})
}

fn get_tun_fd(&self, get_tun_func_name: &'static str) -> Result<RawFd, Error> {
fn open_tun_fd(&self, get_tun_func_name: &'static str) -> Result<RawFd, Error> {
let config = VpnServiceConfig::new(self.config.clone());

let env = self.env()?;
Expand Down
2 changes: 1 addition & 1 deletion talpid-tunnel/src/tun_provider/stub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!();
}
}
Expand Down
3 changes: 2 additions & 1 deletion talpid-tunnel/src/tun_provider/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ impl UnixTunProvider {
&mut self.config
}

pub fn get_tun(&mut self) -> Result<UnixTun, Error> {
/// Open a tunnel using the current tunnel config.
pub fn open_tun(&mut self) -> Result<UnixTun, Error> {
let mut tunnel_device = TunnelDevice::new().map_err(Error::CreateTunnelDevice)?;

for ip in self.config.addresses.iter() {
Expand Down
2 changes: 1 addition & 1 deletion talpid-wireguard/src/wireguard_go/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit 869b8ad

Please sign in to comment.