Skip to content

Commit

Permalink
Merge branch 'slow-reconnection-on-grpc-droid-1223'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Aug 5, 2024
2 parents 7af6b25 + be695fa commit 79f4d12
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 3 deletions.
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

0 comments on commit 79f4d12

Please sign in to comment.