Add stopped check in Routing
This commit is contained in:
@@ -379,7 +379,7 @@ class RepeaterService : Service(), CoroutineScope, WifiP2pManager.ChannelListene
|
|||||||
persistNextGroup = false
|
persistNextGroup = false
|
||||||
}
|
}
|
||||||
check(routingManager == null)
|
check(routingManager == null)
|
||||||
routingManager = object : RoutingManager.LocalOnly(this, group.`interface`!!) {
|
routingManager = object : RoutingManager.LocalOnly(this@RepeaterService, group.`interface`!!) {
|
||||||
override fun ifaceHandler(iface: NetworkInterface) {
|
override fun ifaceHandler(iface: NetworkInterface) {
|
||||||
iface.hardwareAddress?.asIterable()?.macToString()?.let { lastMac = it }
|
iface.hardwareAddress?.asIterable()?.macToString()?.let { lastMac = it }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,6 +129,8 @@ class Routing(private val caller: Any, private val downstream: String,
|
|||||||
private val hostSubnet = "${hostAddress.address.hostAddress}/${hostAddress.networkPrefixLength}"
|
private val hostSubnet = "${hostAddress.address.hostAddress}/${hostAddress.networkPrefixLength}"
|
||||||
private val transaction = RootSession.beginTransaction()
|
private val transaction = RootSession.beginTransaction()
|
||||||
|
|
||||||
|
@Volatile
|
||||||
|
private var stopped = false
|
||||||
private var masqueradeMode = MasqueradeMode.None
|
private var masqueradeMode = MasqueradeMode.None
|
||||||
|
|
||||||
private val upstreams = HashSet<String>()
|
private val upstreams = HashSet<String>()
|
||||||
@@ -164,6 +166,7 @@ class Routing(private val caller: Any, private val downstream: String,
|
|||||||
var dns: List<InetAddress> = emptyList()
|
var dns: List<InetAddress> = emptyList()
|
||||||
|
|
||||||
override fun onAvailable(ifname: String, properties: LinkProperties) = synchronized(this@Routing) {
|
override fun onAvailable(ifname: String, properties: LinkProperties) = synchronized(this@Routing) {
|
||||||
|
if (stopped) return
|
||||||
val subrouting = subrouting
|
val subrouting = subrouting
|
||||||
when {
|
when {
|
||||||
subrouting != null -> check(subrouting.upstream == ifname) { "${subrouting.upstream} != $ifname" }
|
subrouting != null -> check(subrouting.upstream == ifname) { "${subrouting.upstream} != $ifname" }
|
||||||
@@ -181,6 +184,7 @@ class Routing(private val caller: Any, private val downstream: String,
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onLost() = synchronized(this@Routing) {
|
override fun onLost() = synchronized(this@Routing) {
|
||||||
|
if (stopped) return
|
||||||
val subrouting = subrouting ?: return
|
val subrouting = subrouting ?: return
|
||||||
// we could be removing fallback subrouting which no collision could ever happen, check before removing
|
// we could be removing fallback subrouting which no collision could ever happen, check before removing
|
||||||
subrouting.upstream?.let { check(upstreams.remove(it)) }
|
subrouting.upstream?.let { check(upstreams.remove(it)) }
|
||||||
@@ -193,6 +197,7 @@ class Routing(private val caller: Any, private val downstream: String,
|
|||||||
private val fallbackUpstream = object : Upstream(RULE_PRIORITY_UPSTREAM_FALLBACK) {
|
private val fallbackUpstream = object : Upstream(RULE_PRIORITY_UPSTREAM_FALLBACK) {
|
||||||
var fallbackInactive = true
|
var fallbackInactive = true
|
||||||
override fun onFallback() = synchronized(this@Routing) {
|
override fun onFallback() = synchronized(this@Routing) {
|
||||||
|
if (stopped) return
|
||||||
fallbackInactive = false
|
fallbackInactive = false
|
||||||
check(subrouting == null)
|
check(subrouting == null)
|
||||||
subrouting = try {
|
subrouting = try {
|
||||||
@@ -231,6 +236,7 @@ class Routing(private val caller: Any, private val downstream: String,
|
|||||||
}
|
}
|
||||||
private val clients = mutableMapOf<InetAddress, Client>()
|
private val clients = mutableMapOf<InetAddress, Client>()
|
||||||
override fun onIpNeighbourAvailable(neighbours: Collection<IpNeighbour>) = synchronized(this) {
|
override fun onIpNeighbourAvailable(neighbours: Collection<IpNeighbour>) = synchronized(this) {
|
||||||
|
if (stopped) return
|
||||||
val toRemove = HashSet(clients.keys)
|
val toRemove = HashSet(clients.keys)
|
||||||
for (neighbour in neighbours) {
|
for (neighbour in neighbours) {
|
||||||
if (neighbour.dev != downstream || neighbour.ip !is Inet4Address ||
|
if (neighbour.dev != downstream || neighbour.ip !is Inet4Address ||
|
||||||
@@ -328,6 +334,7 @@ class Routing(private val caller: Any, private val downstream: String,
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun stop() {
|
fun stop() {
|
||||||
|
stopped = true
|
||||||
IpNeighbourMonitor.unregisterCallback(this)
|
IpNeighbourMonitor.unregisterCallback(this)
|
||||||
FallbackUpstreamMonitor.unregisterCallback(fallbackUpstream)
|
FallbackUpstreamMonitor.unregisterCallback(fallbackUpstream)
|
||||||
UpstreamMonitor.unregisterCallback(upstream)
|
UpstreamMonitor.unregisterCallback(upstream)
|
||||||
|
|||||||
Reference in New Issue
Block a user