From 5f5bb063c0934c426678aed88e2f0a762a7d5d39 Mon Sep 17 00:00:00 2001 From: Mygod Date: Tue, 2 Oct 2018 22:41:43 +0800 Subject: [PATCH] Record stats before exit --- mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt index b0005ee8..3a964910 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt @@ -130,6 +130,7 @@ class Routing(private val owner: Context, val upstream: String?, private val dow } fun revert() { stop() + TrafficRecorder.update() // record stats before exiting to prevent stats losing synchronized(subroutes) { subroutes.forEach { (_, subroute) -> subroute.close() } } transaction.revert() } @@ -145,7 +146,10 @@ class Routing(private val owner: Context, val upstream: String?, private val dow synchronized(subroutes) { val toRemove = HashSet(subroutes.keys) for (client in it) if (!client.record.blocked) updateForClient(client, toRemove) - for (address in toRemove) subroutes.remove(address)!!.close() + if (toRemove.isNotEmpty()) { + TrafficRecorder.update() // record stats before removing rules to prevent stats losing + for (address in toRemove) subroutes.remove(address)!!.close() + } } } }