Skip to content

Commit

Permalink
remove geoip embed and sideload
Browse files Browse the repository at this point in the history
we had geoip.metadb and geosite.dat in asserts
  • Loading branch information
wwqgtxx committed Sep 11, 2024
1 parent a1d838a commit 262a6b5
Show file tree
Hide file tree
Showing 26 changed files with 3 additions and 411 deletions.
7 changes: 0 additions & 7 deletions .github/workflows/update-dependencies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ jobs:
distribution: 'zulu'
java-version: 17

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
Expand All @@ -37,10 +34,6 @@ jobs:
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Download GeoIP Database
run: |
./gradlew :core:downloadGeoipDatabase
- name: Install update-go-mod-replace
run: |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,45 +45,14 @@ class OverrideSettingsActivity : BaseActivity<OverrideSettingsDesign>() {
withClash {
clearOverride(Clash.OverrideSlot.Persist)
}

service.sideloadGeoip = ""
}

finish()
}
}
OverrideSettingsDesign.Request.EditSideloadGeoip -> {
withContext(Dispatchers.IO) {
val list = querySideloadProviders()
val initial = service.sideloadGeoip
val exist = list.any { info -> info.packageName == initial }

service.sideloadGeoip =
design.requestSelectSideload(if (exist) initial else "", list)
}
}
}
}
}
}
}

private fun querySideloadProviders(): List<AppInfo> {
val apps = packageManager.getInstalledPackages(PackageManager.GET_META_DATA)
.filter {
it.applicationInfo.metaData?.containsKey(Metadata.GEOIP_FILE_NAME)
?: false
}
.map { it.toAppInfo(packageManager) }

return listOf(
AppInfo(
packageName = "",
label = getString(R.string.use_built_in),
icon = getDrawableCompat(R.drawable.ic_baseline_work)!!,
installTime = 0,
updateDate = 0,
)
) + apps
}
}
54 changes: 1 addition & 53 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ plugins {
id("golang-android")
}

val geoipDatabaseUrl =
"https://raw.githubusercontent.com/Loyalsoldier/geoip/release/Country.mmdb"
val geoipInvalidate = Duration.ofDays(7)!!
val geoipOutput = buildDir.resolve("intermediates/golang_blob")
val golangSource = file("src/main/golang/native")

golang {
Expand Down Expand Up @@ -66,52 +62,4 @@ afterEvaluate {
tasks.withType(GolangBuildTask::class.java).forEach {
it.inputs.dir(golangSource)
}
}

task("downloadGeoipDatabase") {
val databaseFile = geoipOutput.resolve("Country.mmdb")
val moduleFile = geoipOutput.resolve("go.mod")
val sourceFile = geoipOutput.resolve("blob.go")

val moduleContent = """
module "cfa/blob"
""".trimIndent()

val sourceContent = """
package blob
import _ "embed"
//go:embed Country.mmdb
var GeoipDatabase []byte
""".trimIndent()

outputs.dir(geoipOutput)

onlyIf {
System.currentTimeMillis() - databaseFile.lastModified() > geoipInvalidate.toMillis()
}

doLast {
geoipOutput.mkdirs()

moduleFile.writeText(moduleContent)
sourceFile.writeText(sourceContent)

URL(geoipDatabaseUrl).openConnection().getInputStream().use { input ->
FileOutputStream(databaseFile).use { output ->
input.copyTo(output)
}
}
}
}

afterEvaluate {
val downloadTask = tasks["downloadGeoipDatabase"]

tasks.forEach {
if (it.name.startsWith("externalGolangBuild")) {
it.dependsOn(downloadTask)
}
}
}
}
4 changes: 0 additions & 4 deletions core/src/foss/golang/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ go 1.20

require cfa v0.0.0

require cfa/blob v0.0.0-00010101000000-000000000000 // indirect

require (
github.com/3andne/restls-client-go v0.1.6 // indirect
github.com/RyuaNerin/go-krypto v1.2.4 // indirect
Expand Down Expand Up @@ -115,5 +113,3 @@ replace github.com/sagernet/sing => github.com/metacubex/sing v0.0.0-20240724044
replace cfa => ../../main/golang

replace github.com/metacubex/mihomo => ./clash

replace cfa/blob => ../../../build/intermediates/golang_blob
27 changes: 0 additions & 27 deletions core/src/main/cpp/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,33 +287,6 @@ Java_com_github_kr328_clash_core_bridge_Bridge_nativeClearOverride(JNIEnv *env,
clearOverride(slot);
}

JNIEXPORT void JNICALL
Java_com_github_kr328_clash_core_bridge_Bridge_nativeInstallSideloadGeoip(JNIEnv *env, jobject thiz,
jbyteArray data) {
TRACE_METHOD();

if (data == NULL) {
installSideloadGeoip(NULL, 0);

return;
}

jbyte *bytes = (*env)->GetByteArrayElements(env, data, NULL);
int size = (*env)->GetArrayLength(env, data);

scoped_string err = installSideloadGeoip(bytes, size);

(*env)->ReleaseByteArrayElements(env, data, bytes, JNI_ABORT);

if (err != NULL) {
(*env)->ThrowNew(
env,
find_class("com/github/kr328/clash/core/bridge/ClashException"),
err
);
}
}

JNIEXPORT jstring JNICALL
Java_com_github_kr328_clash_core_bridge_Bridge_nativeQueryConfiguration(JNIEnv *env, jobject thiz) {
TRACE_METHOD();
Expand Down
1 change: 0 additions & 1 deletion core/src/main/golang/.idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/src/main/golang/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ go 1.20
require (
github.com/dlclark/regexp2 v1.11.4
github.com/metacubex/mihomo v1.7.0
github.com/oschwald/maxminddb-golang v1.12.0
golang.org/x/sync v0.8.0
gopkg.in/yaml.v3 v3.0.1
)
Expand Down Expand Up @@ -71,6 +70,7 @@ require (
github.com/oasisprotocol/deoxysii v0.0.0-20220228165953-2091330c22b7 // indirect
github.com/onsi/ginkgo/v2 v2.9.5 // indirect
github.com/openacid/low v0.1.21 // indirect
github.com/oschwald/maxminddb-golang v1.12.0 // indirect
github.com/pierrec/lz4/v4 v4.1.14 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
github.com/puzpuzpuz/xsync/v3 v3.4.0 // indirect
Expand Down
4 changes: 0 additions & 4 deletions core/src/main/golang/native/delegate/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,19 @@ import (
"errors"
"syscall"

"cfa/blob"

"github.com/metacubex/mihomo/component/process"
"github.com/metacubex/mihomo/log"

"cfa/native/app"
"cfa/native/platform"

"github.com/metacubex/mihomo/component/dialer"
"github.com/metacubex/mihomo/component/mmdb"
"github.com/metacubex/mihomo/constant"
)

var errBlocked = errors.New("blocked")

func Init(home, versionName string, platformVersion int) {
mmdb.LoadFromBytes(blob.GeoipDatabase)
constant.SetHomeDir(home)
app.ApplyVersionName(versionName)
app.ApplyPlatformVersion(platformVersion)
Expand Down
13 changes: 0 additions & 13 deletions core/src/main/golang/native/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,3 @@ func updateProvider(completable unsafe.Pointer, pType C.c_string, name C.c_strin
func suspend(suspended C.int) {
tunnel.Suspend(suspended != 0)
}

//export installSideloadGeoip
func installSideloadGeoip(block unsafe.Pointer, blockSize C.int) *C.char {
if block == nil {
_ = tunnel.InstallSideloadGeoip(nil)

return nil
}

bytes := C.GoBytes(block, blockSize)

return marshalString(tunnel.InstallSideloadGeoip(bytes))
}
24 changes: 0 additions & 24 deletions core/src/main/golang/native/tunnel/geoip.go

This file was deleted.

4 changes: 0 additions & 4 deletions core/src/main/java/com/github/kr328/clash/core/Clash.kt
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,6 @@ object Clash {
Bridge.nativeClearOverride(slot.ordinal)
}

fun installSideloadGeoip(data: ByteArray?) {
Bridge.nativeInstallSideloadGeoip(data)
}

fun queryConfiguration(): UiConfiguration {
return Json.Default.decodeFromString(
UiConfiguration.serializer(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ object Bridge {
external fun nativeReadOverride(slot: Int): String
external fun nativeWriteOverride(slot: Int, content: String)
external fun nativeClearOverride(slot: Int)
external fun nativeInstallSideloadGeoip(data: ByteArray?)
external fun nativeQueryConfiguration(): String
external fun nativeSubscribeLogcat(callback: LogcatInterface)
external fun nativeCoreVersion(): String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.view.View
import com.github.kr328.clash.core.model.ConfigurationOverride
import com.github.kr328.clash.core.model.LogMessage
import com.github.kr328.clash.core.model.TunnelState
import com.github.kr328.clash.design.adapter.SideloadProviderAdapter
import com.github.kr328.clash.design.databinding.DesignSettingsOverideBinding
import com.github.kr328.clash.design.databinding.DialogPreferenceListBinding
import com.github.kr328.clash.design.dialog.FullScreenDialog
Expand All @@ -23,7 +22,7 @@ class OverrideSettingsDesign(
configuration: ConfigurationOverride
) : Design<OverrideSettingsDesign.Request>(context) {
enum class Request {
ResetOverride, EditSideloadGeoip
ResetOverride
}

private val binding = DesignSettingsOverideBinding
Expand Down Expand Up @@ -52,49 +51,6 @@ class OverrideSettingsDesign(
}
}

suspend fun requestSelectSideload(initial: String, apps: List<AppInfo>): String =
withContext(Dispatchers.Main) {
suspendCancellableCoroutine { ctx ->
val binding = DialogPreferenceListBinding
.inflate(context.layoutInflater, context.root, false)
val adapter = SideloadProviderAdapter(context, apps, initial)
val dialog = FullScreenDialog(context)

dialog.setContentView(binding.root)

binding.surface = dialog.surface

binding.titleView.text = context.getString(R.string.sideload_geoip)

binding.newView.visibility = View.INVISIBLE

binding.mainList.applyLinearAdapter(context, adapter)

binding.resetView.setOnClickListener {
ctx.resume("")

dialog.dismiss()
}

binding.cancelView.setOnClickListener {
dialog.dismiss()
}

binding.okView.setOnClickListener {
ctx.resume(adapter.selectedPackageName)

dialog.dismiss()
}

dialog.setOnDismissListener {
if (!ctx.isCompleted)
ctx.resume(initial)
}

dialog.show()
}
}

init {
binding.self = this

Expand Down Expand Up @@ -247,15 +203,6 @@ class OverrideSettingsDesign(
placeholder = R.string.dont_modify,
)

clickable(
title = R.string.sideload_geoip,
summary = R.string.sideload_geoip_summary
) {
clicked {
requests.trySend(Request.EditSideloadGeoip)
}
}

category(R.string.dns)

val dnsDependencies: MutableList<Preference> = mutableListOf()
Expand Down
Loading

0 comments on commit 262a6b5

Please sign in to comment.