From 799e52309f9023e47e17dbdf7f5ba3b3a4d13f10 Mon Sep 17 00:00:00 2001 From: Leon406 Date: Sat, 20 Apr 2024 10:12:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96clash=E8=A7=A3?= =?UTF-8?q?=E6=9E=90=EF=BC=8C=E5=BC=82=E5=B8=B8=E7=AB=AF=E5=8F=A3=E5=A4=84?= =?UTF-8?q?=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 2 +- src/main/java/me/leon/Clash.kt | 9 ++- src/main/java/me/leon/Parser.kt | 1 + src/main/java/me/leon/Subs.kt | 15 ++--- src/test/java/me/leon/ConnectTest.kt | 4 +- src/test/java/me/leon/NetworkSubTest.kt | 33 ++++------- src/test/java/me/leon/NodeCrawler.kt | 79 +++++++++++++------------ sub/pool/subpool | 2 - 8 files changed, 71 insertions(+), 74 deletions(-) delete mode 100644 sub/pool/subpool diff --git a/build.gradle b/build.gradle index de112cd9616..b79662d10a2 100644 --- a/build.gradle +++ b/build.gradle @@ -14,7 +14,7 @@ dependencies { implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3' implementation 'com.google.code.gson:gson:2.10.1' //for yaml 1.1, 1.32 limit maxsize 3M - implementation 'org.yaml:snakeyaml:2.2' + implementation 'org.yaml:snakeyaml:1.31' //mmdb格式 implementation 'com.maxmind.geoip2:geoip2:4.2.0' //dat格式 diff --git a/src/main/java/me/leon/Clash.kt b/src/main/java/me/leon/Clash.kt index 2fee68f7d26..a263f89d770 100644 --- a/src/main/java/me/leon/Clash.kt +++ b/src/main/java/me/leon/Clash.kt @@ -29,7 +29,10 @@ data class Clash( var ipv6: Boolean = false var `cfw-bypass`: List = mutableListOf() var `cfw-latency-timeout`: Int = 0 - var `experimental`: Any = Any() + var experimental: Any = Any() + var `find-process-mode`: Any = Any() + var `global-client-fingerprint`: Any = Any() + var sniffer: Any = Any() var rule: List = mutableListOf() var `proxy-providers`: LinkedHashMap = linkedMapOf() } @@ -73,7 +76,9 @@ data class Node( // hysteria var auth_str: String = "" + var `auth-str`: String = "" var alpn: String = "" + var up: String = "" var disable_mtu_discovery: Boolean = false // http协议 @@ -82,6 +87,8 @@ data class Node( var `grpc-opts`: LinkedHashMap = linkedMapOf() var group: String = "" + // vmess + var `client-fingerprint` :String = "" data class VmessWsOpts( var path: String = "", var headers: LinkedHashMap = linkedMapOf() diff --git a/src/main/java/me/leon/Parser.kt b/src/main/java/me/leon/Parser.kt index 019034682f1..14ba17dc85e 100644 --- a/src/main/java/me/leon/Parser.kt +++ b/src/main/java/me/leon/Parser.kt @@ -220,6 +220,7 @@ object Parser { // 移除yaml中的标签 { data + .replace("\\[[^\"]+?]".toRegex(),"") .parseYaml() .proxies .asSequence() diff --git a/src/main/java/me/leon/Subs.kt b/src/main/java/me/leon/Subs.kt index c2e36bb1169..54664da2781 100644 --- a/src/main/java/me/leon/Subs.kt +++ b/src/main/java/me/leon/Subs.kt @@ -66,7 +66,7 @@ data class V2ray( ps = value } override var serverPort: Int = 0 - get() = port.toInt() + get() = runCatching { port.toInt() }.getOrDefault(-1) override val SERVER get() = add override var nation: String = "" @@ -90,7 +90,7 @@ data class SS( remark = value } override val serverPort - get() = port.toInt() + get() = runCatching { port.toInt() }.getOrDefault(-1) override val SERVER get() = server @@ -119,7 +119,7 @@ data class SSR( remarks = value } override val serverPort - get() = port.toInt() + get() = runCatching { port.toInt() }.getOrDefault(-1) override val SERVER get() = server override var nation: String = "" @@ -150,7 +150,7 @@ data class Trojan(val password: String = "", val server: String = "", val port: private val params get() = if (query.isEmpty()) "" else "?$query" override val serverPort - get() = port.toInt() + get() = runCatching { port.toInt() }.getOrDefault(-1) override val SERVER get() = server override var nation: String = "" @@ -176,13 +176,14 @@ data class Vless(val uuid: String = "", val server: String = "", val port: Strin private val params get() = if (query.isEmpty()) "" else "?$query" override val serverPort - get() = port.toInt() + get() = runCatching { port.toInt() }.getOrDefault(-1) override val SERVER get() = server override var nation: String = "" override fun toUri() = "vless://${"${uuid.urlEncode()}@$server:$port$params"}#${name.urlEncode()}" + override fun info() = if (query.isEmpty()) { "$nation $name vless $server:$port" @@ -193,8 +194,8 @@ data class Vless(val uuid: String = "", val server: String = "", val port: Strin fun Sub.methodUnSupported() = this is SSR && (method in SSR_unSupportMethod || protocol in SSR_unSupportProtocol) || - this is SS && method in SS_unSupportCipher || - this is V2ray && net in VMESS_unSupportProtocol + this is SS && method in SS_unSupportCipher || + this is V2ray && net in VMESS_unSupportProtocol val SSR_unSupportMethod = arrayOf("none", "rc4", "rc4-md5") val SSR_unSupportProtocol = arrayOf("auth_chain_a") diff --git a/src/test/java/me/leon/ConnectTest.kt b/src/test/java/me/leon/ConnectTest.kt index c04c60af3ec..5033da1f354 100644 --- a/src/test/java/me/leon/ConnectTest.kt +++ b/src/test/java/me/leon/ConnectTest.kt @@ -41,7 +41,7 @@ class ConnectTest { @Test fun url404() { runBlocking { - ("$ROOT/pool/sublists".readLines() + "$ROOT/pool/subs") + ("$ROOT/pool/sublists".readLines() + "$ROOT/pool/subs".readLines()) .filterNot { it.startsWith("#") } .map { async(DISPATCHER) { @@ -54,7 +54,5 @@ class ConnectTest { println(it) } } - - } } diff --git a/src/test/java/me/leon/NetworkSubTest.kt b/src/test/java/me/leon/NetworkSubTest.kt index c164c492ff0..350cdf1edc6 100644 --- a/src/test/java/me/leon/NetworkSubTest.kt +++ b/src/test/java/me/leon/NetworkSubTest.kt @@ -6,29 +6,9 @@ import org.junit.jupiter.api.Test class NetworkSubTest { @Test fun subParse() { - /** - * https://qiaomenzhuanfx.netlify.app/ - * https://ghproxy.net/https://raw.githubusercontent.com/learnhard-cn/free_proxy_ss/main/clash/providers/provider_home_netflix.yaml - * https://ghproxy.com/https://raw.githubusercontent.com/Jsnzkpg/Jsnzkpg/Jsnzkpg/Jsnzkpg - * https://ghproxy.net/https://raw.githubusercontent.com/git-yusteven/openit/main/long - * https://ghproxy.net/https://raw.githubusercontent.com/webdao/v2ray/master/nodes.txt - * https://ghproxy.com/https://raw.githubusercontent.com/mahdibland/get_v2/main/pub/changfengoss13.yaml - * https://ghproxy.com/https://raw.githubusercontent.com/mahdibland/get_v2/main/pub/changfengoss1.yaml - * https://ghproxy.com/https://raw.githubusercontent.com/eycorsican/rule-sets/master/kitsunebi_sub - * https://ghproxy.net/https://raw.githubusercontent.com/alanbobs999/TopFreeProxies/master/sub/sub_merge_base64.txt - * https://ghproxy.net/https://raw.githubusercontent.com/JasonZhao2k08/fly/main/index.html - */ - // https://ghproxy.com/https://raw.githubusercontent.com/samjoeyang/subscribe/main/fly + val e = - "https://ghproxy.net/https://raw.githubusercontent.com/alanbobs999/TopFreeProxies/master/sub/sub_merge_base64.txt" - // runBlocking { - // Parser.parseFromSub(e) - // .map { it to async(DISPATCHER) { it.SERVER.quickConnect(it.serverPort, - // 1000) } } - // .filter { it.second.await() > -1 } - // .also { println(it.size) } - // .forEach { println(it.first.info() + ":" + it.second) } - // } + "https://gitlab.com/univstar1/v2ray/-/raw/main/data/clash/general.yaml" listOf( e, @@ -74,6 +54,15 @@ class NetworkSubTest { println(it.info()) } } + @Test + fun parseSs() { + val uri = + "ss://YWVzLTI1Ni1jZmI6OWQ2Y2NlYWEzNzNiZjJjOGFjYjIyZTYwYjZhNThiZTZANDUuNzkuMTExLjIxNDo0NDM=#%E7%BE%8E%E5%9B%BD" + Parser.parseSs(uri).also { + Assertions.assertEquals(uri, it.toUri()) + println(it.info()) + } + } @Test fun parseText() { diff --git a/src/test/java/me/leon/NodeCrawler.kt b/src/test/java/me/leon/NodeCrawler.kt index 7b3fbcde5e8..4b4d0fe42d6 100644 --- a/src/test/java/me/leon/NodeCrawler.kt +++ b/src/test/java/me/leon/NodeCrawler.kt @@ -6,7 +6,7 @@ import me.leon.support.* import org.junit.jupiter.api.Disabled import org.junit.jupiter.api.Test import java.text.SimpleDateFormat -import java.util.Date +import java.util.* @Suppress("LongMethod") class NodeCrawler { @@ -33,53 +33,35 @@ class NodeCrawler { nodeGroup() } - /** 爬取配置文件数据,并去重写入文件 */ + /** 爬取配置文件数据,并去重写入文件 */ @Test @Disabled fun crawlNodes() { - val subs1 = "$ROOT/pool/subpool".readLines() - val subs2 = "$ROOT/pool/subs".readLines() - // val subs3 = "$SHARE2/tmp".readLines() - val sublist = "$ROOT/pool/sublists".readLines() - val subs3 = - sublist - .map { it.readFromNet() } - .flatMap { it.split("\r\n|\n".toRegex()) } - .distinct() - .also { println("before ${it.size}") } - .filterNot { it.startsWith("#") || it.trim().isEmpty() } - .also { - println(it) - println("after ${it.size}") - } - val subs = (subs1 + subs2 + subs3).toHashSet() - println(subs.size) + val mergeSubs = mergeAllNodesUrl() + println(mergeSubs.size) val prefix = SimpleDateFormat("MMddHH").format(Date()) val countryMap = mutableMapOf() val errorList = mutableListOf() POOL.writeLine() runBlocking { - subs - .filterNot { it.trim().startsWith("#") || it.trim().isEmpty() } - .also { println("共有订阅源:${it.size.also { subCount = it }}") } - .map { sub -> - sub to - async(DISPATCHER) { - runCatching { - val uri = sub - Parser.parseFromSub(uri).also { - println("$uri ${it.size}") - if (it.size == 0) { - errorList.add(uri) - } + mergeSubs.map { sub -> + sub to + async(DISPATCHER) { + runCatching { + val uri = sub + Parser.parseFromSub(uri).also { + println("$uri ${it.size}") + if (it.size == 0) { + errorList.add(uri) } } - .getOrElse { - println("___parse failed $sub ${it.message}") - linkedSetOf() - } } - } + .getOrElse { + println("___parse failed $sub ${it.message}") + linkedSetOf() + } + } + } .map { it.first to it.second.await() } .fold(linkedSetOf()) { acc, linkedHashSet -> maps[linkedHashSet.first] = linkedHashSet.second @@ -142,12 +124,33 @@ class NodeCrawler { return } typeMapper[clazz]?.run { - first.writeLine(data,false).also { + first.writeLine(data, false).also { println("$second${subList.size}".also { nodeInfo.writeLine("- $it") }) } } } + private fun mergeAllNodesUrl(): HashSet { + val sub1 = "$ROOT/pool/subs".readLines() + val sublist = "$ROOT/pool/sublists".readLines() + val sub2 = + sublist + .map { it.readFromNet() } + .flatMap { it.split("\r\n|\n".toRegex()) } + .distinct() + .filterNot { it.startsWith("#") || it.trim().isEmpty() } + .also { + println(it) + println("after ${it.size}") + } + val mergeSubs = (sub1 + sub2) + .filterNot { it.trim().startsWith("#") || it.trim().isEmpty() } + .toHashSet() + .also { println("共有订阅源:${it.size.also { subCount = it }}") } + + return mergeSubs + } + companion object { private val nodeInfo = "$ROOT/info.md" const val CUSTOM_INFO = "防失效github SubCrawler" diff --git a/sub/pool/subpool b/sub/pool/subpool deleted file mode 100644 index 1b744686c38..00000000000 --- a/sub/pool/subpool +++ /dev/null @@ -1,2 +0,0 @@ -https://free.dswang.ga/clash/proxies -#https://proxies.bihai.cf/clash/proxies \ No newline at end of file