aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorpacien2019-03-25 03:15:05 +0100
committerpacien2019-03-25 03:15:05 +0100
commitb43bdea667ce27740acf1f6eaa3d7f103c503bc8 (patch)
tree0cbaf0115369832f39ca41e8a69cf2bf11e22862 /app/src/main
parentac694d006dbda068370a6e81105763d857e42aa1 (diff)
downloadtincapp-b43bdea667ce27740acf1f6eaa3d7f103c503bc8.tar.gz
stop any previously unstopped daemon on start
github ref: closes #80
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/org/pacien/tincapp/service/TincVpnService.kt12
1 files changed, 6 insertions, 6 deletions
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 @@
1/* 1/*
2 * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon 2 * Tinc App, an Android binding and user interface for the tinc mesh VPN daemon
3 * Copyright (C) 2017-2018 Pacien TRAN-GIRARD 3 * Copyright (C) 2017-2019 Pacien TRAN-GIRARD
4 * 4 *
5 * This program is free software: you can redistribute it and/or modify 5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by 6 * it under the terms of the GNU General Public License as published by
@@ -52,7 +52,7 @@ class TincVpnService : VpnService() {
52 private val connectivityChangeReceiver = ConnectivityChangeReceiver 52 private val connectivityChangeReceiver = ConnectivityChangeReceiver
53 53
54 override fun onDestroy() { 54 override fun onDestroy() {
55 stopVpn() 55 stopVpn().join()
56 super.onDestroy() 56 super.onDestroy()
57 } 57 }
58 58
@@ -98,7 +98,7 @@ class TincVpnService : VpnService() {
98 return reportError(resources.getString(R.string.notification_error_message_no_configuration_for_network_format, netName), docTopic = "configuration") 98 return reportError(resources.getString(R.string.notification_error_message_no_configuration_for_network_format, netName), docTopic = "configuration")
99 99
100 log.info("Starting tinc daemon for network \"$netName\".") 100 log.info("Starting tinc daemon for network \"$netName\".")
101 if (isConnected()) stopVpn() 101 if (isConnected() || getCurrentNetName() != null) stopVpn().join()
102 102
103 val privateKeys = try { 103 val privateKeys = try {
104 TincConfiguration.fromTincConfiguration(AppPaths.existing(AppPaths.tincConfFile(netName))).let { tincCfg -> 104 TincConfiguration.fromTincConfiguration(AppPaths.existing(AppPaths.tincConfFile(netName))).let { tincCfg ->
@@ -156,18 +156,18 @@ class TincVpnService : VpnService() {
156 } 156 }
157 } 157 }
158 158
159 private fun stopVpn(): Unit = synchronized(this) { 159 private fun stopVpn(): CompletableFuture<Unit> = synchronized(this) {
160 log.info("Stopping any running tinc daemon.") 160 log.info("Stopping any running tinc daemon.")
161 161
162 connectivityChangeReceiver.unregisterWatcher(this) 162 connectivityChangeReceiver.unregisterWatcher(this)
163 163
164 getCurrentNetName()?.let { 164 getCurrentNetName()?.let {
165 Tinc.stop(it).thenRun { 165 Tinc.stop(it).handle { _, _ ->
166 log.info("All tinc daemons stopped.") 166 log.info("All tinc daemons stopped.")
167 broadcastEvent(Actions.EVENT_DISCONNECTED) 167 broadcastEvent(Actions.EVENT_DISCONNECTED)
168 setState(null, null, null, null, null) 168 setState(null, null, null, null, null)
169 } 169 }
170 } 170 } ?: CompletableFuture.completedFuture(Unit)
171 } 171 }
172 172
173 private fun reportError(msg: String, e: Throwable? = null, docTopic: String? = null) { 173 private fun reportError(msg: String, e: Throwable? = null, docTopic: String? = null) {