Skip to content
This repository has been archived by the owner on Nov 14, 2024. It is now read-only.

Commit

Permalink
Refactor routing function
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust authored and AnGgIt86 committed Sep 25, 2024
1 parent 7ba9122 commit cf35b2d
Show file tree
Hide file tree
Showing 57 changed files with 1,652 additions and 966 deletions.
8 changes: 7 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,13 @@
<activity
android:exported="false"
android:theme="@style/AppThemeDayNight.NoActionBar"
android:name=".ui.RoutingSettingsActivity"
android:name=".ui.RoutingSettingActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
android:exported="false"
android:theme="@style/AppThemeDayNight.NoActionBar"
android:name=".ui.RoutingEditActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" />
<activity
Expand Down
73 changes: 73 additions & 0 deletions app/src/main/assets/custom_routing_black
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
[
{
"remarks": "Bypassing bittorrent",
"outboundTag": "direct",
"protocol": [
"bittorrent"
]
},
{
"remarks": "Google cn",
"outboundTag": "proxy",
"domain": [
"domain:googleapis.cn",
"domain:gstatic.com"
]
},
{
"remarks": "Block udp443",
"outboundTag": "block",
"port": "443",
"network": "udp"
},
{
"remarks": "Block ads",
"outboundTag": "block",
"domain": [
"geosite:category-ads-all"
]
},
{
"remarks": "Bypass LAN domain name",
"outboundTag": "direct",
"domain": [
"geosite:private"
]
},
{
"remarks": "Bypass LAN IP",
"outboundTag": "direct",
"ip": [
"geoip:private"
]
},
{
"remarks": "Proxy GFW",
"outboundTag": "proxy",
"domain": [
"geosite:gfw",
"geosite:greatfire"
]
},
{
"remarks": "Agent for Google, etc.",
"outboundTag": "proxy",
"ip": [
"1.0.0.1",
"1.1.1.1",
"8.8.8.8",
"8.8.4.4",
"geoip:facebook",
"geoip:fastly",
"geoip:google",
"geoip:netflix",
"geoip:telegram",
"geoip:twitter"
]
},
{
"remarks": "Final direct connection",
"port": "0-65535",
"outboundTag": "direct"
}
]
34 changes: 34 additions & 0 deletions app/src/main/assets/custom_routing_global
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[
{
"remarks": "Block udp443",
"outboundTag": "block",
"port": "443",
"network": "udp"
},
{
"remarks": "Block ads",
"outboundTag": "block",
"domain": [
"geosite:category-ads-all"
]
},
{
"remarks": "Bypass LAN domain name",
"outboundTag": "direct",
"domain": [
"geosite:private"
]
},
{
"remarks": "Bypass LAN IP",
"outboundTag": "direct",
"ip": [
"geoip:private"
]
},
{
"remarks": "Final Agent",
"port": "0-65535",
"outboundTag": "proxy"
}
]
81 changes: 81 additions & 0 deletions app/src/main/assets/custom_routing_white
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
[
{
"remarks": "Google cn",
"outboundTag": "proxy",
"domain": [
"domain:googleapis.cn",
"domain:gstatic.com"
]
},
{
"remarks": "Block udp443",
"outboundTag": "block",
"port": "443",
"network": "udp"
},
{
"remarks": "Block ads",
"outboundTag": "block",
"domain": [
"geosite:category-ads-all"
]
},
{
"remarks": "Bypass LAN domain name",
"outboundTag": "direct",
"domain": [
"geosite:private"
]
},
{
"remarks": "Bypass LAN IP",
"outboundTag": "direct",
"ip": [
"geoip:private"
]
},
{
"remarks": "Bypass Chinese Domain Names",
"outboundTag": "direct",
"domain": [
"domain:dns.alidns.com",
"domain:doh.pub",
"domain:dot.pub",
"domain:doh.360.cn",
"domain:dot.360.cn",
"geosite:cn",
"geosite:geolocation-cn"
]
},
{
"remarks": "Bypass Chinese IP",
"outboundTag": "direct",
"ip": [
"223.5.5.5/32",
"223.6.6.6/32",
"2400:3200::1/128",
"2400:3200:baba::1/128",
"119.29.29.29/32",
"1.12.12.12/32",
"120.53.53.53/32",
"2402:4e00::/128",
"2402:4e00:1::/128",
"180.76.76.76/32",
"2400:da00::6666/128",
"114.114.114.114/32",
"114.114.115.115/32",
"180.184.1.1/32",
"180.184.2.2/32",
"101.226.4.6/32",
"218.30.118.6/32",
"123.125.81.6/32",
"140.207.198.6/32",
"geoip:cn"
]
},
{
"remarks": "Final Agent",
"port": "0-65535",
"outboundTag": "proxy"
}
]
2 changes: 1 addition & 1 deletion app/src/main/java/com/neko/splash/SplashActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SplashActivity : BaseActivity() {
Handler(Looper.getMainLooper()).postDelayed({
val cursor: Cursor? = myDB.bacaSemuaData()
if (cursor == null || cursor.count == 0) {
startActivity(Intent(this@SplashActivity, MainActivity::class.java))
startActivity(Intent(this@SplashActivity, TambahActivity::class.java))
} else {
try {
val db = myDB.readableDatabase
Expand Down
10 changes: 7 additions & 3 deletions app/src/main/kotlin/com/neko/v2ray/AngApplication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import android.content.Context
import androidx.multidex.MultiDexApplication
import androidx.work.Configuration
import com.tencent.mmkv.MMKV
import com.neko.v2ray.util.SettingsManager

class AngApplication : MultiDexApplication(), Configuration.Provider {
override val workManagerConfiguration: Configuration = Configuration.Builder().setDefaultProcessName("${BuildConfig.APPLICATION_ID}:bg").build()

class AngApplication : MultiDexApplication() {
companion object {
lateinit var application: AngApplication
}
Expand All @@ -17,8 +16,13 @@ class AngApplication : MultiDexApplication(), Configuration.Provider {
application = this
}

private val workManagerConfiguration: Configuration = Configuration.Builder()
.setDefaultProcessName("${BuildConfig.APPLICATION_ID}:bg")
.build()

override fun onCreate() {
super.onCreate()
MMKV.initialize(this)
SettingsManager.initRoutingRulesets(this)
}
}
6 changes: 1 addition & 5 deletions app/src/main/kotlin/com/neko/v2ray/AppConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,7 @@ object AppConfig {
const val PREF_LOCAL_DNS_PORT = "pref_local_dns_port"
const val PREF_VPN_DNS = "pref_vpn_dns"
const val PREF_ROUTING_DOMAIN_STRATEGY = "pref_routing_domain_strategy"
const val PREF_ROUTING_MODE = "pref_routing_mode"
const val PREF_V2RAY_ROUTING_AGENT = "pref_v2ray_routing_agent"
const val PREF_V2RAY_ROUTING_DIRECT = "pref_v2ray_routing_direct"
const val PREF_V2RAY_ROUTING_BLOCKED = "pref_v2ray_routing_blocked"
const val PREF_ROUTING_CUSTOM = "pref_routing_custom"
const val PREF_ROUTING_RULESET = "pref_routing_ruleset"
const val PREF_MUX_ENABLED = "pref_mux_enabled"
const val PREF_MUX_CONCURRENCY = "pref_mux_concurrency"
const val PREF_MUX_XUDP_CONCURRENCY = "pref_mux_xudp_concurrency"
Expand Down
9 changes: 0 additions & 9 deletions app/src/main/kotlin/com/neko/v2ray/dto/ERoutingMode.kt

This file was deleted.

12 changes: 12 additions & 0 deletions app/src/main/kotlin/com/neko/v2ray/dto/RulesetItem.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.neko.v2ray.dto

data class RulesetItem(
var remarks: String? = "",
var ip: List<String>? = null,
var domain: List<String>? = null,
var outboundTag: String = "",
var port: String? = null,
var network: String? = null,
var protocol: List<String>? = null,
var enabled: Boolean = true,
)
10 changes: 4 additions & 6 deletions app/src/main/kotlin/com/neko/v2ray/service/V2RayVpnService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ import android.util.Log
import androidx.annotation.RequiresApi
import com.neko.v2ray.AppConfig
import com.neko.v2ray.R
import com.neko.v2ray.dto.ERoutingMode
import com.neko.v2ray.util.MmkvManager.settingsStorage
import com.neko.v2ray.util.MyContextWrapper
import com.neko.v2ray.util.SettingsManager
import com.neko.v2ray.util.Utils
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
Expand Down Expand Up @@ -115,13 +115,11 @@ class V2RayVpnService : VpnService(), ServiceControl {
val builder = Builder()
//val enableLocalDns = defaultDPreference.getPrefBoolean(AppConfig.PREF_LOCAL_DNS_ENABLED, false)

val routingMode = settingsStorage?.decodeString(AppConfig.PREF_ROUTING_MODE)
?: ERoutingMode.BYPASS_LAN_MAINLAND.value

builder.setMtu(VPN_MTU)
builder.addAddress(PRIVATE_VLAN4_CLIENT, 30)
//builder.addDnsServer(PRIVATE_VLAN4_ROUTER)
if (routingMode == ERoutingMode.BYPASS_LAN.value || routingMode == ERoutingMode.BYPASS_LAN_MAINLAND.value) {
val bypassLan = SettingsManager.routingRulesetsBypassLan()
if (bypassLan) {
resources.getStringArray(R.array.bypass_private_ip_address).forEach {
val addr = it.split('/')
builder.addRoute(addr[0], addr[1].toInt())
Expand All @@ -132,7 +130,7 @@ class V2RayVpnService : VpnService(), ServiceControl {

if (settingsStorage?.decodeBool(AppConfig.PREF_PREFER_IPV6) == true) {
builder.addAddress(PRIVATE_VLAN6_CLIENT, 126)
if (routingMode == ERoutingMode.BYPASS_LAN.value || routingMode == ERoutingMode.BYPASS_LAN_MAINLAND.value) {
if (bypassLan) {
builder.addRoute("2000::", 3) //currently only 1/8 of total ipV6 is in use
} else {
builder.addRoute("::", 0)
Expand Down
8 changes: 6 additions & 2 deletions app/src/main/kotlin/com/neko/v2ray/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -902,6 +902,10 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
Utils.openUri(this, AppConfig.v2rayNGIssues)
}

fun uwuRoutingSetting(view: View) {
requestSubSettingActivity.launch(Intent(this, RoutingSettingActivity::class.java))
}

fun uwuExitApp(view: View) {
keluar()
}
Expand Down Expand Up @@ -959,8 +963,8 @@ class MainActivity : BaseActivity(), NavigationView.OnNavigationItemSelectedList
)
}

R.id.user_asset_setting -> {
startActivity(Intent(this, UserAssetActivity::class.java))
R.id.routing_setting -> {
requestSubSettingActivity.launch(Intent(this, RoutingSettingActivity::class.java))
}

R.id.promotion -> {
Expand Down
Loading

0 comments on commit cf35b2d

Please sign in to comment.