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 f5ddb6bb..d7d5cdd0 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt @@ -330,7 +330,7 @@ class Routing(private val caller: Any, private val downstream: String) : IpNeigh stop() Timber.i("Stopped routing for $downstream by $caller") TrafficRecorder.update() // record stats before exiting to prevent stats losing - clients.values.forEach { it.close() } + synchronized(this) { clients.values.forEach { it.close() } } currentDns?.transaction?.revert() fallbackUpstream.subrouting?.transaction?.revert() upstream.subrouting?.transaction?.revert() diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpNeighbourMonitor.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpNeighbourMonitor.kt index 0a8c379b..5d359cb4 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpNeighbourMonitor.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/monitor/IpNeighbourMonitor.kt @@ -6,14 +6,13 @@ import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.launch import java.net.InetAddress import java.util.* -import java.util.concurrent.ConcurrentHashMap class IpNeighbourMonitor private constructor() : IpMonitor() { companion object { - private val callbacks = Collections.newSetFromMap(ConcurrentHashMap()) + private val callbacks = mutableSetOf() var instance: IpNeighbourMonitor? = null - fun registerCallback(callback: Callback) = synchronized(this) { + fun registerCallback(callback: Callback) = synchronized(callbacks) { if (!callbacks.add(callback)) return@synchronized var monitor = instance if (monitor == null) { @@ -24,7 +23,7 @@ class IpNeighbourMonitor private constructor() : IpMonitor() { callback.onIpNeighbourAvailable(synchronized(monitor.neighbours) { monitor.neighbours.values.toList() }) } } - fun unregisterCallback(callback: Callback) = synchronized(this) { + fun unregisterCallback(callback: Callback) = synchronized(callbacks) { if (!callbacks.remove(callback) || callbacks.isNotEmpty()) return@synchronized instance?.destroy() instance = null @@ -68,7 +67,9 @@ class IpNeighbourMonitor private constructor() : IpMonitor() { updatePosted = false neighbours.values.toList() } - for (callback in callbacks) callback.onIpNeighbourAvailable(neighbours) + synchronized(callbacks) { + for (callback in callbacks) callback.onIpNeighbourAvailable(neighbours) + } } updatePosted = true }