From c74f2e4b16a09367ec0f08bbb23e51458b6e925f Mon Sep 17 00:00:00 2001 From: problematicconsumer Date: Fri, 22 Dec 2023 15:36:08 +0330 Subject: [PATCH] Update core (sing-box v1.7.5) --- .../com/hiddify/hiddify/bg/VPNService.kt | 72 ++++++++++++------- .../com/hiddify/hiddify/ktx/Wrappers.kt | 10 ++- dependencies.properties | 2 +- libcore | 2 +- 4 files changed, 59 insertions(+), 27 deletions(-) diff --git a/android/app/src/main/kotlin/com/hiddify/hiddify/bg/VPNService.kt b/android/app/src/main/kotlin/com/hiddify/hiddify/bg/VPNService.kt index d6ce8514..da38b11a 100644 --- a/android/app/src/main/kotlin/com/hiddify/hiddify/bg/VPNService.kt +++ b/android/app/src/main/kotlin/com/hiddify/hiddify/bg/VPNService.kt @@ -8,6 +8,7 @@ import android.net.VpnService import android.os.Build import android.os.IBinder import com.hiddify.hiddify.constant.PerAppProxyMode +import com.hiddify.hiddify.ktx.toIpPrefix import io.nekohasekai.libbox.TunOptions import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.runBlocking @@ -31,6 +32,7 @@ class VPNService : VpnService(), PlatformInterfaceWrapper { } return service.onBind(intent) } + override fun onDestroy() { service.onDestroy() } @@ -62,42 +64,64 @@ class VPNService : VpnService(), PlatformInterfaceWrapper { } val inet4Address = options.inet4Address - if (inet4Address.hasNext()) { - while (inet4Address.hasNext()) { - val address = inet4Address.next() - builder.addAddress(address.address, address.prefix) - } + while (inet4Address.hasNext()) { + val address = inet4Address.next() + builder.addAddress(address.address(), address.prefix()) } val inet6Address = options.inet6Address - if (inet6Address.hasNext()) { - while (inet6Address.hasNext()) { - val address = inet6Address.next() - builder.addAddress(address.address, address.prefix) - } + while (inet6Address.hasNext()) { + val address = inet6Address.next() + builder.addAddress(address.address(), address.prefix()) } if (options.autoRoute) { builder.addDnsServer(options.dnsServerAddress) - val inet4RouteAddress = options.inet4RouteAddress - if (inet4RouteAddress.hasNext()) { - while (inet4RouteAddress.hasNext()) { - val address = inet4RouteAddress.next() - builder.addRoute(address.address, address.prefix) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + val inet4RouteAddress = options.inet4RouteAddress + if (inet4RouteAddress.hasNext()) { + while (inet4RouteAddress.hasNext()) { + builder.addRoute(inet4RouteAddress.next().toIpPrefix()) + } + } else { + builder.addRoute("0.0.0.0", 0) } - } else { - builder.addRoute("0.0.0.0", 0) - } - val inet6RouteAddress = options.inet6RouteAddress - if (inet6RouteAddress.hasNext()) { - while (inet6RouteAddress.hasNext()) { - val address = inet6RouteAddress.next() - builder.addRoute(address.address, address.prefix) + val inet6RouteAddress = options.inet6RouteAddress + if (inet6RouteAddress.hasNext()) { + while (inet6RouteAddress.hasNext()) { + builder.addRoute(inet6RouteAddress.next().toIpPrefix()) + } + } else { + builder.addRoute("::", 0) + } + + val inet4RouteExcludeAddress = options.inet4RouteExcludeAddress + while (inet4RouteExcludeAddress.hasNext()) { + builder.excludeRoute(inet4RouteExcludeAddress.next().toIpPrefix()) + } + + val inet6RouteExcludeAddress = options.inet6RouteExcludeAddress + while (inet6RouteExcludeAddress.hasNext()) { + builder.excludeRoute(inet6RouteExcludeAddress.next().toIpPrefix()) } } else { - builder.addRoute("::", 0) + val inet4RouteAddress = options.inet4RouteRange + if (inet4RouteAddress.hasNext()) { + while (inet4RouteAddress.hasNext()) { + val address = inet4RouteAddress.next() + builder.addRoute(address.address(), address.prefix()) + } + } + + val inet6RouteAddress = options.inet6RouteRange + if (inet6RouteAddress.hasNext()) { + while (inet6RouteAddress.hasNext()) { + val address = inet6RouteAddress.next() + builder.addRoute(address.address(), address.prefix()) + } + } } if (Settings.perAppProxyEnabled) { diff --git a/android/app/src/main/kotlin/com/hiddify/hiddify/ktx/Wrappers.kt b/android/app/src/main/kotlin/com/hiddify/hiddify/ktx/Wrappers.kt index 85fc0984..c74f8af1 100644 --- a/android/app/src/main/kotlin/com/hiddify/hiddify/ktx/Wrappers.kt +++ b/android/app/src/main/kotlin/com/hiddify/hiddify/ktx/Wrappers.kt @@ -1,6 +1,11 @@ package com.hiddify.hiddify.ktx +import android.net.IpPrefix +import android.os.Build +import androidx.annotation.RequiresApi +import io.nekohasekai.libbox.RoutePrefix import io.nekohasekai.libbox.StringIterator +import java.net.InetAddress fun StringIterator.toList(): List { return mutableListOf().apply { @@ -8,4 +13,7 @@ fun StringIterator.toList(): List { add(next()) } } -} \ No newline at end of file +} + +@RequiresApi(Build.VERSION_CODES.TIRAMISU) +fun RoutePrefix.toIpPrefix() = IpPrefix(InetAddress.getByName(address()), prefix()) \ No newline at end of file diff --git a/dependencies.properties b/dependencies.properties index 07c387f5..8b4083da 100644 --- a/dependencies.properties +++ b/dependencies.properties @@ -1 +1 @@ -core.version=0.9.0 \ No newline at end of file +core.version=0.9.1 \ No newline at end of file diff --git a/libcore b/libcore index 4099f968..8e9d5239 160000 --- a/libcore +++ b/libcore @@ -1 +1 @@ -Subproject commit 4099f968e21264f94d0feb9004cd20281aadc20f +Subproject commit 8e9d5239f49a7b452cb4c25121f3e3826e22e0a5