summaryrefslogtreecommitdiffhomepage
path: root/android/src
diff options
context:
space:
mode:
authorJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2021-01-12 14:32:33 +0000
committerJanito Vaqueiro Ferreira Filho <janito@mullvad.net>2021-04-21 12:24:47 +0000
commitf975e715edcfae96ef09138956f085c9af9a0d9e (patch)
tree59654430965a8055799e68eecfbc40158edecf1c /android/src
parentb786f8a73ad9c54c18e94e1474a81ca4f78c3e4f (diff)
downloadmullvadvpn-f975e715edcfae96ef09138956f085c9af9a0d9e.tar.xz
mullvadvpn-f975e715edcfae96ef09138956f085c9af9a0d9e.zip
Allow to set WireGuard MTU with `SettingsListener`
Diffstat (limited to 'android/src')
-rw-r--r--android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/SettingsListener.kt31
1 files changed, 31 insertions, 0 deletions
diff --git a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/SettingsListener.kt b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/SettingsListener.kt
index e1efe2f8c7..0a52279c6e 100644
--- a/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/SettingsListener.kt
+++ b/android/src/main/kotlin/net/mullvad/mullvadvpn/service/endpoint/SettingsListener.kt
@@ -1,6 +1,13 @@
package net.mullvad.mullvadvpn.service.endpoint
+import kotlinx.coroutines.Dispatchers
+import kotlinx.coroutines.GlobalScope
+import kotlinx.coroutines.channels.Channel
+import kotlinx.coroutines.channels.ClosedReceiveChannelException
+import kotlinx.coroutines.channels.actor
+import kotlinx.coroutines.channels.sendBlocking
import net.mullvad.mullvadvpn.ipc.Event
+import net.mullvad.mullvadvpn.ipc.Request
import net.mullvad.mullvadvpn.model.DnsOptions
import net.mullvad.mullvadvpn.model.RelaySettings
import net.mullvad.mullvadvpn.model.Settings
@@ -8,6 +15,11 @@ import net.mullvad.mullvadvpn.service.MullvadDaemon
import net.mullvad.talpid.util.EventNotifier
class SettingsListener(endpoint: ServiceEndpoint) {
+ private sealed class Command {
+ class SetWireGuardMtu(val mtu: Int?) : Command()
+ }
+
+ private val commandChannel = spawnActor()
private val daemon = endpoint.intermittentDaemon
val accountNumberNotifier = EventNotifier<String?>(null)
@@ -29,9 +41,16 @@ class SettingsListener(endpoint: ServiceEndpoint) {
settingsNotifier.subscribe(this) { settings ->
endpoint.sendEvent(Event.SettingsUpdate(settings))
}
+
+ endpoint.dispatcher.apply {
+ registerHandler(Request.SetWireGuardMtu::class) { request ->
+ commandChannel.sendBlocking(Command.SetWireGuardMtu(request.mtu))
+ }
+ }
}
fun onDestroy() {
+ commandChannel.close()
daemon.unregisterListener(this)
accountNumberNotifier.unsubscribeAll()
@@ -81,4 +100,16 @@ class SettingsListener(endpoint: ServiceEndpoint) {
}
}
}
+
+ private fun spawnActor() = GlobalScope.actor<Command>(Dispatchers.Default, Channel.UNLIMITED) {
+ try {
+ for (command in channel) {
+ when (command) {
+ is Command.SetWireGuardMtu -> daemon.await().setWireguardMtu(command.mtu)
+ }
+ }
+ } catch (exception: ClosedReceiveChannelException) {
+ // Closed sender, so stop the actor
+ }
+ }
}