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 87505c87..ddec2f1d 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt @@ -185,9 +185,8 @@ class Routing(private val caller: Any, private val downstream: String) : IpNeigh override fun onAvailable(properties: LinkProperties?) = synchronized(this@Routing) { if (stopped) return val toRemove = subrouting.keys.toMutableSet() - for (link in properties?.allStackedLinks ?: emptySequence()) { - val ifname = link.interfaceName - if (ifname == null || toRemove.remove(ifname) || !upstreams.add(ifname)) continue + for (ifname in properties?.allInterfaceNames ?: emptyList()) { + if (toRemove.remove(ifname) || !upstreams.add(ifname)) continue try { subrouting[ifname] = Subrouting(priority, ifname) } catch (e: Exception) { diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/preference/UpstreamsPreference.kt b/mobile/src/main/java/be/mygod/vpnhotspot/preference/UpstreamsPreference.kt index 0be0fd1f..56a0d318 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/preference/UpstreamsPreference.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/preference/UpstreamsPreference.kt @@ -14,7 +14,7 @@ import be.mygod.vpnhotspot.R import be.mygod.vpnhotspot.net.monitor.FallbackUpstreamMonitor import be.mygod.vpnhotspot.net.monitor.UpstreamMonitor import be.mygod.vpnhotspot.util.SpanFormatter -import be.mygod.vpnhotspot.util.allStackedLinks +import be.mygod.vpnhotspot.util.allRoutes import be.mygod.vpnhotspot.util.parseNumericAddress import timber.log.Timber @@ -25,9 +25,8 @@ class UpstreamsPreference(context: Context, attrs: AttributeSet) : Preference(co private val internetV6Address = parseNumericAddress("2001:4860:4860::8888") } - private data class Interface(val ifname: String, val internet: Boolean = true) private open inner class Monitor : UpstreamMonitor.Callback { - protected var currentInterfaces = emptyList() + protected var currentInterfaces = emptyMap() val charSequence get() = currentInterfaces.map { (ifname, internet) -> if (internet) SpannableStringBuilder(ifname).apply { setSpan(StyleSpan(Typeface.BOLD), 0, length, 0) @@ -36,18 +35,18 @@ class UpstreamsPreference(context: Context, attrs: AttributeSet) : Preference(co override fun onAvailable(properties: LinkProperties?) { - currentInterfaces = properties?.allStackedLinks?.mapNotNull { prop -> - prop.interfaceName?.let { ifname -> - Interface(ifname, prop.routes.any { - try { - it.matches(internetV4Address) || it.matches(internetV6Address) - } catch (e: RuntimeException) { - Timber.w(e) - false - } - }) + val result = mutableMapOf() + for (route in properties?.allRoutes ?: emptyList()) { + result.compute(route.`interface` ?: continue) { _, internet -> + internet == true || try { + route.matches(internetV4Address) || route.matches(internetV6Address) + } catch (e: RuntimeException) { + Timber.w(e) + false + } } - }?.toList() ?: emptyList() + } + currentInterfaces = result onUpdate() } } @@ -55,7 +54,7 @@ class UpstreamsPreference(context: Context, attrs: AttributeSet) : Preference(co private val primary = Monitor() private val fallback: Monitor = object : Monitor() { override fun onFallback() { - currentInterfaces = listOf(Interface("")) + currentInterfaces = mapOf("" to true) onUpdate() } } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/util/Utils.kt b/mobile/src/main/java/be/mygod/vpnhotspot/util/Utils.kt index 09c570c8..6b7c3ddd 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/util/Utils.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/util/Utils.kt @@ -117,17 +117,6 @@ val LinkProperties.allInterfaceNames get() = getAllInterfaceNames.invoke(this) a private val getAllRoutes by lazy { LinkProperties::class.java.getDeclaredMethod("getAllRoutes") } @Suppress("UNCHECKED_CAST") val LinkProperties.allRoutes get() = getAllRoutes.invoke(this) as List -private val getStackedLinks by lazy { LinkProperties::class.java.getDeclaredMethod("getStackedLinks") } -@Suppress("UNCHECKED_CAST") -private val LinkProperties.stackedLinks get() = getStackedLinks.invoke(this) as List - -private suspend fun SequenceScope.yieldRec(prop: LinkProperties) { - yield(prop) - for (link in prop.stackedLinks) yieldRec(link) -} -val LinkProperties.allStackedLinks get() = let { - sequence { yieldRec(it) } -} fun Context.launchUrl(url: String) { if (app.hasTouch) try {