Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dummy name resolver #6567

Merged
merged 1 commit into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import mullvad_daemon.management_interface.ManagementInterface
import mullvad_daemon.management_interface.ManagementServiceGrpcKt
import net.mullvad.mullvadvpn.lib.daemon.grpc.mapper.fromDomain
import net.mullvad.mullvadvpn.lib.daemon.grpc.mapper.toDomain
import net.mullvad.mullvadvpn.lib.daemon.grpc.resolver.DummyNameResolverFactory
import net.mullvad.mullvadvpn.lib.daemon.grpc.util.LogInterceptor
import net.mullvad.mullvadvpn.lib.daemon.grpc.util.connectivityFlow
import net.mullvad.mullvadvpn.lib.model.AccountData
Expand Down Expand Up @@ -142,6 +143,10 @@ class ManagementService(
rpcSocketFile.absolutePath,
LocalSocketAddress.Namespace.FILESYSTEM
)
// We need to provide a DummyNameResolver to avoid default NameResolver making incorrect
// InetSocketAddress look ups. For more info see:
// https://github.com/grpc/grpc-java/issues/11442
.nameResolverFactory(DummyNameResolverFactory())
.build()

val connectionState: StateFlow<GrpcConnectivityState> =
Expand Down Expand Up @@ -194,7 +199,6 @@ class ManagementService(
error("ManagementService already started")
}

channel.resetConnectBackoff()
job = scope.launch { subscribeEvents() }
}

Expand All @@ -204,6 +208,8 @@ class ManagementService(
job = null
}

fun enterIdle() = channel.enterIdle()

private suspend fun subscribeEvents() =
withContext(Dispatchers.IO) {
launch {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package net.mullvad.mullvadvpn.lib.daemon.grpc.resolver

import io.grpc.EquivalentAddressGroup
import io.grpc.NameResolver
import java.net.InetSocketAddress

class DummyNameResolver : NameResolver() {

override fun getServiceAuthority(): String = SERVICE_AUTHORITY

override fun start(listener: Listener2) {
val resolutionResult =
ResolutionResult.newBuilder()
.setAddresses(
listOf(
EquivalentAddressGroup(
InetSocketAddress.createUnresolved(DUMMY_HOST, DUMMY_PORT)
)
)
)
.build()

listener.onResult(resolutionResult)
}

override fun shutdown() {
// Do nothing
}

companion object {
const val SERVICE_AUTHORITY = "localhost"
private const val DUMMY_HOST = ""
private const val DUMMY_PORT = 80
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package net.mullvad.mullvadvpn.lib.daemon.grpc.resolver

import io.grpc.NameResolver
import java.net.URI

class DummyNameResolverFactory : NameResolver.Factory() {
override fun newNameResolver(targetUri: URI, args: NameResolver.Args): NameResolver {
return DummyNameResolver()
}

override fun getDefaultScheme(): String {
return DNS_SCHEME
}

companion object {
private const val DNS_SCHEME = "dns"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ class MullvadVpnService : TalpidVpnService(), ShouldBeOnForegroundProvider {
prepareFiles(this@MullvadVpnService)
migrateSplitTunneling.migrate()

Logger.d("Start daemon")
Logger.i("Start daemon")
startDaemon()

Logger.d("Start management service")
Logger.i("Start management service")
managementService.start()
}
}
Expand Down Expand Up @@ -213,6 +213,9 @@ class MullvadVpnService : TalpidVpnService(), ShouldBeOnForegroundProvider {

Logger.i("Shutdown MullvadDaemon")
MullvadDaemon.shutdown()
Logger.i("Enter Idle")
managementService.enterIdle()
Logger.i("Shutdown complete")
super.onDestroy()
}

Expand Down
Loading