summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJonatan Rhodin <jonatan.rhodin@mullvad.net>2023-06-14 13:29:05 +0200
committerDavid Lönnhager <david.l@mullvad.net>2023-06-28 16:25:26 +0200
commit4a6838d7a877e17fd4687b66c0c0b19bcde2db19 (patch)
tree9dd5cdab2fed35424b8b4fb32f3568182f572b31
parentc3dba6d769c346ecabba148d0277841b798b82d1 (diff)
downloadmullvadvpn-4a6838d7a877e17fd4687b66c0c0b19bcde2db19.tar.xz
mullvadvpn-4a6838d7a877e17fd4687b66c0c0b19bcde2db19.zip
Update rust and java code to expose wireguard port settings
- Add converters for wireguard constraint to and from java - Add java clas for wireguard constraint - Add code to set wireguard port
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Request.kt4
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/Port.kt6
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/RelayConstraints.kt6
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/RelayConstraintsUpdate.kt5
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/WireguardConstraints.kt6
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt19
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/RelayListListener.kt18
-rw-r--r--mullvad-jni/src/classes.rs2
-rw-r--r--mullvad-types/src/relay_constraints.rs49
9 files changed, 106 insertions, 9 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Request.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Request.kt
index 7ff4a63ff4..b2af9c989d 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Request.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ipc/Request.kt
@@ -8,6 +8,7 @@ import net.mullvad.mullvadvpn.model.DnsOptions
import net.mullvad.mullvadvpn.model.LocationConstraint
import net.mullvad.mullvadvpn.model.ObfuscationSettings
import net.mullvad.mullvadvpn.model.QuantumResistantState
+import net.mullvad.mullvadvpn.model.WireguardConstraints
// Requests that the service can handle
sealed class Request : Message.RequestMessage() {
@@ -87,6 +88,9 @@ sealed class Request : Message.RequestMessage() {
@Parcelize data class SetObfuscationSettings(val settings: ObfuscationSettings?) : Request()
@Parcelize
+ data class SetWireguardConstraints(val wireguardConstraints: WireguardConstraints?) : Request()
+
+ @Parcelize
data class SetWireGuardQuantumResistant(val quantumResistant: QuantumResistantState) :
Request()
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/Port.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/Port.kt
new file mode 100644
index 0000000000..52f495a7a7
--- /dev/null
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/Port.kt
@@ -0,0 +1,6 @@
+package net.mullvad.mullvadvpn.model
+
+import android.os.Parcelable
+import kotlinx.parcelize.Parcelize
+
+@Parcelize data class Port(val value: Int) : Parcelable
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/RelayConstraints.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/RelayConstraints.kt
index 9b02e043ad..da2acb39f6 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/RelayConstraints.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/RelayConstraints.kt
@@ -3,4 +3,8 @@ package net.mullvad.mullvadvpn.model
import android.os.Parcelable
import kotlinx.parcelize.Parcelize
-@Parcelize data class RelayConstraints(val location: Constraint<LocationConstraint>) : Parcelable
+@Parcelize
+data class RelayConstraints(
+ val location: Constraint<LocationConstraint>,
+ val wireguardConstraints: WireguardConstraints
+) : Parcelable
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/RelayConstraintsUpdate.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/RelayConstraintsUpdate.kt
index 94aa58c56a..bd5bfb9605 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/RelayConstraintsUpdate.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/RelayConstraintsUpdate.kt
@@ -1,3 +1,6 @@
package net.mullvad.mullvadvpn.model
-data class RelayConstraintsUpdate(var location: Constraint<LocationConstraint>?)
+data class RelayConstraintsUpdate(
+ var location: Constraint<LocationConstraint>?,
+ var wireguardConstraints: WireguardConstraints?
+)
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/WireguardConstraints.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/WireguardConstraints.kt
new file mode 100644
index 0000000000..1725b01f0f
--- /dev/null
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/model/WireguardConstraints.kt
@@ -0,0 +1,6 @@
+package net.mullvad.mullvadvpn.model
+
+import android.os.Parcelable
+import kotlinx.parcelize.Parcelize
+
+@Parcelize data class WireguardConstraints(val port: Constraint<Port>) : Parcelable
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt
index 7515bad230..4fa531eeb4 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/RelayListListener.kt
@@ -14,12 +14,14 @@ import net.mullvad.mullvadvpn.model.LocationConstraint
import net.mullvad.mullvadvpn.model.RelayConstraintsUpdate
import net.mullvad.mullvadvpn.model.RelayList
import net.mullvad.mullvadvpn.model.RelaySettingsUpdate
+import net.mullvad.mullvadvpn.model.WireguardConstraints
import net.mullvad.mullvadvpn.service.MullvadDaemon
class RelayListListener(endpoint: ServiceEndpoint) {
companion object {
private enum class Command {
SetRelayLocation,
+ SetWireguardConstraints
}
}
@@ -30,6 +32,10 @@ class RelayListListener(endpoint: ServiceEndpoint) {
observable<LocationConstraint?>(null) { _, _, _ ->
commandChannel.trySendBlocking(Command.SetRelayLocation)
}
+ private var selectedWireguardConstraints by
+ observable<WireguardConstraints?>(null) { _, _, _ ->
+ commandChannel.trySendBlocking(Command.SetWireguardConstraints)
+ }
var relayList by
observable<RelayList?>(null) { _, _, relays ->
@@ -48,6 +54,10 @@ class RelayListListener(endpoint: ServiceEndpoint) {
endpoint.dispatcher.registerHandler(Request.SetRelayLocation::class) { request ->
selectedRelayLocation = request.relayLocation
}
+
+ endpoint.dispatcher.registerHandler(Request.SetWireguardConstraints::class) { request ->
+ selectedWireguardConstraints = request.wireguardConstraints
+ }
}
fun onDestroy() {
@@ -72,7 +82,8 @@ class RelayListListener(endpoint: ServiceEndpoint) {
try {
for (command in channel) {
when (command) {
- Command.SetRelayLocation -> updateRelayConstraints()
+ Command.SetRelayLocation,
+ Command.SetWireguardConstraints -> updateRelayConstraints()
}
}
} catch (exception: ClosedReceiveChannelException) {
@@ -81,10 +92,12 @@ class RelayListListener(endpoint: ServiceEndpoint) {
}
private suspend fun updateRelayConstraints() {
- val constraint: Constraint<LocationConstraint> =
+ val location: Constraint<LocationConstraint> =
selectedRelayLocation?.let { location -> Constraint.Only(location) } ?: Constraint.Any()
+ val wireguardConstraints: WireguardConstraints? = selectedWireguardConstraints
- val update = RelaySettingsUpdate.Normal(RelayConstraintsUpdate(constraint))
+ val update =
+ RelaySettingsUpdate.Normal(RelayConstraintsUpdate(location, wireguardConstraints))
daemon.await().updateRelaySettings(update)
}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/RelayListListener.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/RelayListListener.kt
index 5a92eea719..5d18cca679 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/RelayListListener.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/serviceconnection/RelayListListener.kt
@@ -8,6 +8,7 @@ import net.mullvad.mullvadvpn.model.Constraint
import net.mullvad.mullvadvpn.model.LocationConstraint
import net.mullvad.mullvadvpn.model.RelayConstraints
import net.mullvad.mullvadvpn.model.RelaySettings
+import net.mullvad.mullvadvpn.model.WireguardConstraints
import net.mullvad.mullvadvpn.relaylist.RelayItem
import net.mullvad.mullvadvpn.relaylist.RelayList
@@ -33,6 +34,18 @@ class RelayListListener(
connection.send(Request.SetRelayLocation(value).message)
}
+ var selectedWireguardConstraints: WireguardConstraints?
+ get() {
+ val settings = relaySettings as? RelaySettings.Normal
+
+ return settings?.relayConstraints?.wireguardConstraints?.port?.let { port ->
+ WireguardConstraints(port)
+ }
+ }
+ set(value) {
+ connection.send(Request.SetWireguardConstraints(value).message)
+ }
+
var onRelayListChange: ((RelayList, RelayItem?) -> Unit)? = null
set(value) {
field = value
@@ -66,7 +79,10 @@ class RelayListListener(
val relayList = this.relayList
relaySettings =
- newRelaySettings ?: RelaySettings.Normal(RelayConstraints(Constraint.Any()))
+ newRelaySettings
+ ?: RelaySettings.Normal(
+ RelayConstraints(Constraint.Any(), WireguardConstraints(Constraint.Any()))
+ )
if (relayList != null) {
relayListChanged(relayList)
diff --git a/mullvad-jni/src/classes.rs b/mullvad-jni/src/classes.rs
index d4765e78a4..595084dbd6 100644
--- a/mullvad-jni/src/classes.rs
+++ b/mullvad-jni/src/classes.rs
@@ -31,6 +31,7 @@ pub const CLASSES: &[&str] = &[
"net/mullvad/mullvadvpn/model/ObfuscationSettings",
"net/mullvad/mullvadvpn/model/PublicKey",
"net/mullvad/mullvadvpn/model/QuantumResistantState",
+ "net/mullvad/mullvadvpn/model/Port",
"net/mullvad/mullvadvpn/model/Relay",
"net/mullvad/mullvadvpn/model/RelayConstraints",
"net/mullvad/mullvadvpn/model/RelayEndpointData$Bridge",
@@ -55,6 +56,7 @@ pub const CLASSES: &[&str] = &[
"net/mullvad/mullvadvpn/model/VoucherSubmission",
"net/mullvad/mullvadvpn/model/VoucherSubmissionResult",
"net/mullvad/mullvadvpn/model/LoginResult",
+ "net/mullvad/mullvadvpn/model/WireguardConstraints",
"net/mullvad/mullvadvpn/model/WireguardRelayEndpointData",
"net/mullvad/mullvadvpn/service/MullvadDaemon",
"net/mullvad/mullvadvpn/service/MullvadVpnService",
diff --git a/mullvad-types/src/relay_constraints.rs b/mullvad-types/src/relay_constraints.rs
index 1fe7d52fe1..eb7d3d6900 100644
--- a/mullvad-types/src/relay_constraints.rs
+++ b/mullvad-types/src/relay_constraints.rs
@@ -244,7 +244,6 @@ pub struct RelayConstraints {
pub ownership: Constraint<Ownership>,
#[cfg_attr(target_os = "android", jnix(skip))]
pub tunnel_protocol: Constraint<TunnelType>,
- #[cfg_attr(target_os = "android", jnix(skip))]
pub wireguard_constraints: WireguardConstraints,
#[cfg_attr(target_os = "android", jnix(skip))]
pub openvpn_constraints: OpenVpnConstraints,
@@ -539,14 +538,51 @@ impl fmt::Display for OpenVpnConstraints {
/// [`Constraint`]s applicable to WireGuard relays.
#[derive(Debug, Default, Clone, Eq, PartialEq, Deserialize, Serialize)]
-#[serde(default)]
+#[cfg_attr(target_os = "android", derive(IntoJava))]
+#[cfg_attr(target_os = "android", jnix(package = "net.mullvad.mullvadvpn.model"))]
+#[serde(rename_all = "snake_case", default)]
pub struct WireguardConstraints {
+ #[cfg_attr(
+ target_os = "android",
+ jnix(map = "|constraint| constraint.map(|v| Port { value: v as i32 })")
+ )]
pub port: Constraint<u16>,
+ #[cfg_attr(target_os = "android", jnix(skip))]
pub ip_version: Constraint<IpVersion>,
+ #[cfg_attr(target_os = "android", jnix(skip))]
pub use_multihop: bool,
+ #[cfg_attr(target_os = "android", jnix(skip))]
pub entry_location: Constraint<LocationConstraint>,
}
+#[cfg(target_os = "android")]
+impl<'env, 'sub_env> FromJava<'env, JObject<'sub_env>> for WireguardConstraints
+where
+ 'env: 'sub_env,
+{
+ const JNI_SIGNATURE: &'static str = "Lnet/mullvad/mullvadvpn/model/WireguardConstraints;";
+
+ fn from_java(env: &JnixEnv<'env>, object: JObject<'sub_env>) -> Self {
+ let object = env
+ .call_method(
+ object,
+ "component1",
+ "()Lnet/mullvad/mullvadvpn/model/Constraint;",
+ &[],
+ )
+ .expect("missing WireguardConstraints.port")
+ .l()
+ .expect("WireguardConstraints.port did not return an object");
+
+ let port: Constraint<Port> = Constraint::from_java(env, object);
+
+ WireguardConstraints {
+ port: port.map(|port| port.value as u16),
+ ..Default::default()
+ }
+ }
+}
+
impl fmt::Display for WireguardConstraints {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
match self.port {
@@ -569,6 +605,14 @@ impl fmt::Display for WireguardConstraints {
}
}
+/// Used for jni conversion.
+#[cfg(target_os = "android")]
+#[derive(Debug, Default, Clone, Eq, PartialEq, FromJava, IntoJava)]
+#[jnix(package = "net.mullvad.mullvadvpn.model")]
+struct Port {
+ value: i32,
+}
+
/// Specifies a specific endpoint or [`BridgeConstraints`] to use when `mullvad-daemon` selects a
/// bridge server.
#[derive(Debug, Clone, Eq, PartialEq, Deserialize, Serialize)]
@@ -768,7 +812,6 @@ pub struct RelayConstraintsUpdate {
pub ownership: Option<Constraint<Ownership>>,
#[cfg_attr(target_os = "android", jnix(default))]
pub tunnel_protocol: Option<Constraint<TunnelType>>,
- #[cfg_attr(target_os = "android", jnix(default))]
pub wireguard_constraints: Option<WireguardConstraints>,
#[cfg_attr(target_os = "android", jnix(default))]
pub openvpn_constraints: Option<OpenVpnConstraints>,