From b43bdea667ce27740acf1f6eaa3d7f103c503bc8 Mon Sep 17 00:00:00 2001 From: pacien Date: Mon, 25 Mar 2019 03:15:05 +0100 Subject: stop any previously unstopped daemon on start github ref: closes #80 --- .../main/java/org/pacien/tincapp/service/TincVpnService.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'app/src/main/java/org') diff --git a/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt b/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt index 28f1347..be5b11d 100644 --- a/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt +++ b/app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt @@ -1,6 +1,6 @@ /* * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon - * Copyright (C) 2017-2018 Pacien TRAN-GIRARD + * Copyright (C) 2017-2019 Pacien TRAN-GIRARD * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -52,7 +52,7 @@ class TincVpnService : VpnService() { private val connectivityChangeReceiver = ConnectivityChangeReceiver override fun onDestroy() { - stopVpn() + stopVpn().join() super.onDestroy() } @@ -98,7 +98,7 @@ class TincVpnService : VpnService() { return reportError(resources.getString(R.string.notification_error_message_no_configuration_for_network_format, netName), docTopic = "configuration") log.info("Starting tinc daemon for network \"$netName\".") - if (isConnected()) stopVpn() + if (isConnected() || getCurrentNetName() != null) stopVpn().join() val privateKeys = try { TincConfiguration.fromTincConfiguration(AppPaths.existing(AppPaths.tincConfFile(netName))).let { tincCfg -> @@ -156,18 +156,18 @@ class TincVpnService : VpnService() { } } - private fun stopVpn(): Unit = synchronized(this) { + private fun stopVpn(): CompletableFuture = synchronized(this) { log.info("Stopping any running tinc daemon.") connectivityChangeReceiver.unregisterWatcher(this) getCurrentNetName()?.let { - Tinc.stop(it).thenRun { + Tinc.stop(it).handle { _, _ -> log.info("All tinc daemons stopped.") broadcastEvent(Actions.EVENT_DISCONNECTED) setState(null, null, null, null, null) } - } + } ?: CompletableFuture.completedFuture(Unit) } private fun reportError(msg: String, e: Throwable? = null, docTopic: String? = null) { -- cgit v1.2.3