Skip to content

Commit

Permalink
Remove unused parts of legacy CustomDns
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Sep 12, 2023
1 parent 7e566fb commit 74d797e
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 81 deletions.
Original file line number Diff line number Diff line change
@@ -1,83 +1,13 @@
package net.mullvad.mullvadvpn.ui.serviceconnection

import android.os.Messenger
import java.net.InetAddress
import net.mullvad.mullvadvpn.lib.ipc.Request
import net.mullvad.mullvadvpn.lib.ipc.extensions.trySendRequest
import net.mullvad.mullvadvpn.model.DnsOptions
import net.mullvad.mullvadvpn.model.DnsState
import net.mullvad.talpid.util.EventNotifier

class CustomDns(private val connection: Messenger, private val settingsListener: SettingsListener) {
@Deprecated(
message = "Will soon be removed in favor of onDnsOptionsChanged.",
replaceWith = ReplaceWith("onDnsOptionsChanged")
)
val onEnabledChanged = EventNotifier(false)
@Deprecated(
message = "Will soon be removed in favor of onDnsOptionsChanged.",
replaceWith = ReplaceWith("onDnsOptionsChanged")
)
val onDnsServersChanged = EventNotifier<List<InetAddress>>(emptyList())
val onDnsOptionsChanged = EventNotifier<DnsOptions?>(null)

init {
settingsListener.dnsOptionsNotifier.subscribe(this) { maybeDnsOptions ->
maybeDnsOptions?.let { dnsOptions ->
synchronized(this) {
onEnabledChanged.notifyIfChanged(dnsOptions.state == DnsState.Custom)
onDnsServersChanged.notifyIfChanged(dnsOptions.customOptions.addresses)
onDnsOptionsChanged.notifyIfChanged(dnsOptions)
}
}
}
}

fun enable() {
connection.send(Request.SetEnableCustomDns(true).message)
}

fun disable() {
connection.send(Request.SetEnableCustomDns(false).message)
}

fun isCustomDnsEnabled(): Boolean {
return onEnabledChanged.latestEvent ?: false
}

fun addDnsServer(server: InetAddress): Boolean {
val didntAlreadyHaveServer = !onDnsServersChanged.latestEvent.contains(server)

connection.send(Request.AddCustomDnsServer(server).message)

return didntAlreadyHaveServer
}

fun replaceDnsServer(oldServer: InetAddress, newServer: InetAddress): Boolean {
synchronized(this) {
val dnsServers = onDnsServersChanged.latestEvent
val containsOldServer = dnsServers.contains(oldServer)
val replacementIsValid = oldServer == newServer || !dnsServers.contains(newServer)

connection.send(Request.ReplaceCustomDnsServer(oldServer, newServer).message)

return containsOldServer && replacementIsValid
}
}

fun removeDnsServer(server: InetAddress) {
connection.send(Request.RemoveCustomDnsServer(server).message)
}
class CustomDns(private val connection: Messenger) {

fun setDnsOptions(dnsOptions: DnsOptions) {
connection.trySendRequest(Request.SetDnsOptions(dnsOptions), false)
}

fun onDestroy() {
onEnabledChanged.unsubscribeAll()
onDnsServersChanged.unsubscribeAll()
onDnsOptionsChanged.unsubscribeAll()

settingsListener.dnsOptionsNotifier.unsubscribe(this)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import net.mullvad.mullvadvpn.lib.ipc.DispatchingHandler
import net.mullvad.mullvadvpn.lib.ipc.Event
import net.mullvad.mullvadvpn.lib.ipc.Request
import org.koin.core.component.KoinComponent
import org.koin.core.component.get

// Container of classes that communicate with the service through an active connection
//
Expand All @@ -34,7 +33,7 @@ class ServiceConnectionContainer(
val vpnPermission = VpnPermission(connection, dispatcher)

val appVersionInfoCache = AppVersionInfoCache(dispatcher, settingsListener)
val customDns = CustomDns(connection, settingsListener)
val customDns = CustomDns(connection)
var relayListListener = RelayListListener(connection, dispatcher, settingsListener)

private var listenerId: Int? = null
Expand Down Expand Up @@ -62,7 +61,6 @@ class ServiceConnectionContainer(
voucherRedeemer.onDestroy()

appVersionInfoCache.onDestroy()
customDns.onDestroy()
relayListListener.onDestroy()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ import android.os.Messenger
import net.mullvad.mullvadvpn.lib.ipc.Event
import net.mullvad.mullvadvpn.lib.ipc.EventDispatcher
import net.mullvad.mullvadvpn.lib.ipc.Request
import net.mullvad.mullvadvpn.model.DnsOptions
import net.mullvad.mullvadvpn.model.ObfuscationSettings
import net.mullvad.mullvadvpn.model.QuantumResistantState
import net.mullvad.mullvadvpn.model.RelaySettings
import net.mullvad.mullvadvpn.model.Settings
import net.mullvad.talpid.util.EventNotifier

class SettingsListener(private val connection: Messenger, eventDispatcher: EventDispatcher) {
val dnsOptionsNotifier = EventNotifier<DnsOptions?>(null)
val relaySettingsNotifier = EventNotifier<RelaySettings?>(null)
val settingsNotifier = EventNotifier<Settings?>(null)

Expand Down Expand Up @@ -55,7 +53,6 @@ class SettingsListener(private val connection: Messenger, eventDispatcher: Event
}

fun onDestroy() {
dnsOptionsNotifier.unsubscribeAll()
relaySettingsNotifier.unsubscribeAll()
settingsNotifier.unsubscribeAll()
}
Expand All @@ -65,10 +62,6 @@ class SettingsListener(private val connection: Messenger, eventDispatcher: Event
}

private fun handleNewSettings(newSettings: Settings) {
if (settings?.tunnelOptions?.dnsOptions != newSettings.tunnelOptions.dnsOptions) {
dnsOptionsNotifier.notify(newSettings.tunnelOptions.dnsOptions)
}

if (settings?.relaySettings != newSettings.relaySettings) {
relaySettingsNotifier.notify(newSettings.relaySettings)
}
Expand Down

0 comments on commit 74d797e

Please sign in to comment.