summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2019-11-21 11:17:23 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2019-11-21 13:19:57 +0000
commitf66f39b9b29421b5fd02605f07b585ef3440c3b4 (patch)
tree50e56943dac9bd5b78da848875a9beff4ac57ae0
parent40d3b7634aff71b89fc89a8f6082a01a5c61630f (diff)
downloadmullvadvpn-f66f39b9b29421b5fd02605f07b585ef3440c3b4.tar.xz
mullvadvpn-f66f39b9b29421b5fd02605f07b585ef3440c3b4.zip
Create `TalpidVpnService` super class
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadVpnService.kt31
-rw-r--r--android/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt32
-rw-r--r--mullvad-jni/src/lib.rs1
-rw-r--r--mullvad-jni/src/vpn_service_tun_provider.rs10
4 files changed, 40 insertions, 34 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadVpnService.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadVpnService.kt
index 174387eabb..67fe711a6c 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadVpnService.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/MullvadVpnService.kt
@@ -1,7 +1,6 @@
package net.mullvad.mullvadvpn
import android.content.Intent
-import android.net.VpnService
import android.os.Binder
import android.os.IBinder
import kotlinx.coroutines.CompletableDeferred
@@ -11,9 +10,9 @@ import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.runBlocking
import net.mullvad.mullvadvpn.dataproxy.ConnectionProxy
-import net.mullvad.talpid.tun_provider.TunConfig
+import net.mullvad.talpid.TalpidVpnService
-class MullvadVpnService : VpnService() {
+class MullvadVpnService : TalpidVpnService() {
private val binder = LocalBinder()
private val created = CompletableDeferred<Unit>()
@@ -50,32 +49,6 @@ class MullvadVpnService : VpnService() {
created.cancel()
}
- fun createTun(config: TunConfig): Int {
- val builder = Builder().apply {
- for (address in config.addresses) {
- addAddress(address, 32)
- }
-
- for (dnsServer in config.dnsServers) {
- addDnsServer(dnsServer)
- }
-
- for (route in config.routes) {
- addRoute(route.address, route.prefixLength.toInt())
- }
-
- setMtu(config.mtu)
- }
-
- val vpnInterface = builder.establish()
-
- return vpnInterface.detachFd()
- }
-
- fun bypass(socket: Int): Boolean {
- return protect(socket)
- }
-
inner class LocalBinder : Binder() {
val daemon
get() = this@MullvadVpnService.daemon
diff --git a/android/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt b/android/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt
new file mode 100644
index 0000000000..96de4082cc
--- /dev/null
+++ b/android/src/main/kotlin/net/mullvad/talpid/TalpidVpnService.kt
@@ -0,0 +1,32 @@
+package net.mullvad.talpid
+
+import android.net.VpnService
+import net.mullvad.talpid.tun_provider.TunConfig
+
+open class TalpidVpnService : VpnService() {
+ fun createTun(config: TunConfig): Int {
+ val builder = Builder().apply {
+ for (address in config.addresses) {
+ addAddress(address, 32)
+ }
+
+ for (dnsServer in config.dnsServers) {
+ addDnsServer(dnsServer)
+ }
+
+ for (route in config.routes) {
+ addRoute(route.address, route.prefixLength.toInt())
+ }
+
+ setMtu(config.mtu)
+ }
+
+ val vpnInterface = builder.establish()
+
+ return vpnInterface.detachFd()
+ }
+
+ fun bypass(socket: Int): Boolean {
+ return protect(socket)
+ }
+}
diff --git a/mullvad-jni/src/lib.rs b/mullvad-jni/src/lib.rs
index 33bd4095ee..11c4d8b7e7 100644
--- a/mullvad-jni/src/lib.rs
+++ b/mullvad-jni/src/lib.rs
@@ -88,6 +88,7 @@ const CLASSES_TO_LOAD: &[&str] = &[
"net/mullvad/talpid/tunnel/ParameterGenerationError$NoMatchingBridgeRelay",
"net/mullvad/talpid/tunnel/ParameterGenerationError$NoWireguardKey",
"net/mullvad/talpid/tunnel/ParameterGenerationError$CustomTunnelHostResultionError",
+ "net/mullvad/talpid/TalpidVpnService",
];
lazy_static! {
diff --git a/mullvad-jni/src/vpn_service_tun_provider.rs b/mullvad-jni/src/vpn_service_tun_provider.rs
index 54045c5da6..35ca55c300 100644
--- a/mullvad-jni/src/vpn_service_tun_provider.rs
+++ b/mullvad-jni/src/vpn_service_tun_provider.rs
@@ -25,23 +25,23 @@ pub enum Error {
#[error(display = "Failed to allow socket to bypass tunnel")]
Bypass,
- #[error(display = "Failed to call Java method MullvadVpnService.{}", _0)]
+ #[error(display = "Failed to call Java method TalpidVpnService.{}", _0)]
CallMethod(&'static str, #[error(source)] jni::errors::Error),
#[error(display = "Failed to create Java VM handle clone")]
CloneJavaVm(#[error(source)] jni::errors::Error),
- #[error(display = "Failed to create global reference to MullvadVpnService instance")]
+ #[error(display = "Failed to create global reference to TalpidVpnService instance")]
CreateGlobalReference(#[error(source)] jni::errors::Error),
- #[error(display = "Failed to find MullvadVpnService.{} method", _0)]
+ #[error(display = "Failed to find TalpidVpnService.{} method", _0)]
FindMethod(&'static str, #[error(source)] jni::errors::Error),
#[error(display = "Failed to get Java VM instance")]
GetJvmInstance(#[error(source)] jni::errors::Error),
#[error(
- display = "Received an invalid result from MullvadVpnService.{}: {}",
+ display = "Received an invalid result from TalpidVpnService.{}: {}",
_0,
_1
)]
@@ -61,7 +61,7 @@ impl VpnServiceTunProvider {
/// Create a new VpnServiceTunProvider interfacing with Android's VpnService.
pub fn new(env: &JNIEnv, mullvad_vpn_service: &JObject) -> Result<Self, Error> {
let jvm = env.get_java_vm().map_err(Error::GetJvmInstance)?;
- let class = get_class("net/mullvad/mullvadvpn/MullvadVpnService");
+ let class = get_class("net/mullvad/talpid/TalpidVpnService");
let object = env
.new_global_ref(*mullvad_vpn_service)
.map_err(Error::CreateGlobalReference)?;