mirror of
https://github.com/SukkaW/Surge.git
synced 2025-12-12 17:20:35 +08:00
Refactor: move China IPv4 to https://github.com/SukkaW/chnroutes2-optimized
This commit is contained in:
parent
331ea5a403
commit
f957795396
@ -1,41 +1,15 @@
|
||||
import { fetchRemoteTextByLine } from './lib/fetch-text-by-line';
|
||||
import { task } from './trace';
|
||||
|
||||
import { contains as containsCidr, exclude as excludeCidr } from 'fast-cidr-tools';
|
||||
import { createMemoizedPromise } from './lib/memo-promise';
|
||||
import { CN_CIDR_MISSING_IN_CHNROUTE, NON_CN_CIDR_INCLUDED_IN_CHNROUTE } from './constants/cidr';
|
||||
import { appendArrayInPlace } from 'foxts/append-array-in-place';
|
||||
import { IPListOutput } from './lib/rules/ip';
|
||||
import { createFileDescription } from './constants/description';
|
||||
|
||||
const PROBE_CHN_CIDR_V4 = [
|
||||
// NetEase Hangzhou
|
||||
'223.252.196.38',
|
||||
// Aliyun ShenZhen
|
||||
'120.78.92.171'
|
||||
];
|
||||
|
||||
export const getChnCidrPromise = createMemoizedPromise(async function getChnCidr() {
|
||||
const [_cidr4, cidr6] = await Promise.all([
|
||||
fetchRemoteTextByLine('https://raw.githubusercontent.com/misakaio/chnroutes2/master/chnroutes.txt', true).then(Array.fromAsync<string>),
|
||||
return Promise.all([
|
||||
fetchRemoteTextByLine('https://chnroutes2.cdn.skk.moe/chnroutes.txt', true).then(Array.fromAsync<string>),
|
||||
fetchRemoteTextByLine('https://gaoyifan.github.io/china-operator-ip/china6.txt', true).then(Array.fromAsync<string>)
|
||||
]);
|
||||
|
||||
const cidr4 = excludeCidr(
|
||||
appendArrayInPlace(_cidr4, CN_CIDR_MISSING_IN_CHNROUTE),
|
||||
NON_CN_CIDR_INCLUDED_IN_CHNROUTE,
|
||||
true
|
||||
);
|
||||
|
||||
for (const probeIp of PROBE_CHN_CIDR_V4) {
|
||||
if (!containsCidr(cidr4, PROBE_CHN_CIDR_V4)) {
|
||||
const err = new TypeError('chnroutes missing probe IP');
|
||||
err.cause = probeIp;
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
|
||||
return [cidr4, cidr6] as const;
|
||||
});
|
||||
|
||||
export const buildChnCidr = task(require.main === module, __filename)(async (span) => {
|
||||
|
||||
@ -6,11 +6,12 @@ import fsp from 'node:fs/promises';
|
||||
|
||||
const DEPRECATED_FILES = [
|
||||
['non_ip/global_plus', 'This file has been merged with non_ip/global'],
|
||||
['domainset/reject_sukka', 'This file has been merged with domainset/reject']
|
||||
['domainset/reject_sukka', 'This file has been merged with domainset/reject'],
|
||||
['Internal/reversed-chn-cidr.txt', 'This file has been replaced by https://chnroutes2.cdn.skk.moe/reversed-chnroutes.txt']
|
||||
];
|
||||
|
||||
const REMOVED_FILES = [
|
||||
'Internal/cdn.txt',
|
||||
'Internal/chnroutes.txt',
|
||||
'List/internal/appprofile.php',
|
||||
'Clash/domainset/steam.txt',
|
||||
'Clash/non_ip/clash_fake_ip_filter.txt',
|
||||
|
||||
@ -1,60 +0,0 @@
|
||||
import { task } from './trace';
|
||||
|
||||
import { getChnCidrPromise } from './build-chn-cidr';
|
||||
import Worktank from 'worktank';
|
||||
|
||||
const pool = new Worktank({
|
||||
name: 'build-internal-reverse-chn-cidr',
|
||||
size: 1,
|
||||
timeout: 10000, // The maximum number of milliseconds to wait for the result from the worker, if exceeded the worker is terminated and the execution promise rejects
|
||||
warmup: true,
|
||||
autoterminate: 30000, // The interval of milliseconds at which to check if the pool can be automatically terminated, to free up resources, workers will be spawned up again if needed
|
||||
env: {},
|
||||
methods: {
|
||||
// eslint-disable-next-line object-shorthand -- workertank
|
||||
getreversedCidr: async function (cidr: string[], importMetaUrl: string): Promise<void> {
|
||||
// TODO: createRequire is a temporary workaround for https://github.com/nodejs/node/issues/51956
|
||||
const { default: module } = await import('node:module');
|
||||
const __require = module.createRequire(importMetaUrl);
|
||||
const path = __require('node:path') as typeof import('node:path');
|
||||
const fs = __require('fs') as typeof import('fs');
|
||||
|
||||
const { OUTPUT_INTERNAL_DIR } = __require('./constants/dir') as typeof import('./constants/dir');
|
||||
const { exclude, merge } = __require('fast-cidr-tools') as typeof import('fast-cidr-tools');
|
||||
const { RESERVED_IPV4_CIDR, NON_CN_CIDR_INCLUDED_IN_CHNROUTE } = __require('./constants/cidr') as typeof import('./constants/cidr');
|
||||
const { appendArrayInPlace } = __require('foxts/append-array-in-place') as typeof import('foxts/append-array-in-place');
|
||||
const { fastStringArrayJoin } = __require('foxts/fast-string-array-join') as typeof import('foxts/fast-string-array-join');
|
||||
|
||||
const outputFile = path.join(OUTPUT_INTERNAL_DIR, 'reversed-chn-cidr.txt');
|
||||
|
||||
fs.mkdirSync(OUTPUT_INTERNAL_DIR, { recursive: true });
|
||||
|
||||
const result = merge(
|
||||
appendArrayInPlace(
|
||||
exclude(
|
||||
['0.0.0.0/0'],
|
||||
RESERVED_IPV4_CIDR.concat(cidr),
|
||||
true
|
||||
),
|
||||
// https://github.com/misakaio/chnroutes2/issues/25
|
||||
NON_CN_CIDR_INCLUDED_IN_CHNROUTE
|
||||
),
|
||||
true
|
||||
);
|
||||
|
||||
fs.writeFileSync(outputFile, fastStringArrayJoin(result, '\n') + '\n', { encoding: 'utf-8' });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export const buildInternalReverseChnCIDR = task(require.main === module, __filename)(async (span) => {
|
||||
const [cidr] = await span.traceChildPromise('download chnroutes2', getChnCidrPromise());
|
||||
|
||||
return span.traceChildAsync(
|
||||
'build reversed chn cidr',
|
||||
async () => pool.exec(
|
||||
'getreversedCidr',
|
||||
[cidr, import.meta.url]
|
||||
).finally(() => pool.terminate())
|
||||
);
|
||||
});
|
||||
@ -1,89 +0,0 @@
|
||||
// https://en.wikipedia.org/wiki/Reserved_IP_addresses
|
||||
export const RESERVED_IPV4_CIDR = [
|
||||
'0.0.0.0/8',
|
||||
'10.0.0.0/8',
|
||||
'100.64.0.0/10',
|
||||
'127.0.0.0/8',
|
||||
'169.254.0.0/16',
|
||||
'172.16.0.0/12',
|
||||
'192.0.0.0/24',
|
||||
'192.0.2.0/24',
|
||||
// 192.88.99.0 // is currently being broadcast by HE and Comcast
|
||||
'192.168.0.0/16',
|
||||
'198.18.0.0/15',
|
||||
'198.51.100.0/24',
|
||||
'203.0.113.0/24',
|
||||
'224.0.0.0/4',
|
||||
'233.252.0.0/24',
|
||||
'240.0.0.0/4'
|
||||
];
|
||||
|
||||
export const NON_CN_CIDR_INCLUDED_IN_CHNROUTE = [
|
||||
// https://github.com/misakaio/chnroutes2/issues/25
|
||||
'223.118.0.0/15',
|
||||
'223.120.0.0/15',
|
||||
// https://github.com/misakaio/chnroutes2/issues/50
|
||||
'123.254.104.0/21',
|
||||
// https://github.com/misakaio/chnroutes2/issues/49
|
||||
'45.147.48.0/23',
|
||||
'45.80.188.0/24',
|
||||
'45.80.190.0/24',
|
||||
// https://github.com/misakaio/chnroutes2/issues/52
|
||||
'137.220.128.0/17',
|
||||
|
||||
// Cloudie.hk commonly used in GFW DNS Poison target
|
||||
'103.246.246.0/23',
|
||||
|
||||
'45.199.166.0/24',
|
||||
'45.199.167.0/24'
|
||||
];
|
||||
|
||||
// https://github.com/misakaio/chnroutes2/issues/46
|
||||
// https://github.com/misakaio/chnroutes2/issues/48
|
||||
export const CN_CIDR_MISSING_IN_CHNROUTE = [
|
||||
// ChinaTelecom
|
||||
'103.7.141.0/24', // Hubei
|
||||
|
||||
// Aliyun Shenzhen
|
||||
'120.78.0.0/16',
|
||||
|
||||
// wy.com.cn
|
||||
'211.99.96.0/19',
|
||||
|
||||
// AS58593, Azure China
|
||||
'40.72.0.0/15', // Shanghai
|
||||
'42.159.0.0/16', // Shanghai
|
||||
'52.130.0.0/17', // Shanghai
|
||||
'52.131.0.0/16', // Beijing
|
||||
'103.9.8.0/22', // Backbone
|
||||
'139.217.0.0/16', // Shanghai
|
||||
'139.219.0.0/16', // Shanghai
|
||||
'143.64.0.0/16', // Beijing
|
||||
'159.27.0.0/16', // Beijing
|
||||
'163.228.0.0/16', // Beijing
|
||||
|
||||
// NetEase
|
||||
'223.252.194.0/24',
|
||||
'223.252.196.0/24',
|
||||
|
||||
// Xiamen Kuaikuai
|
||||
'180.188.36.0/22', // no route globally
|
||||
|
||||
// Baidu Public DNS
|
||||
'180.76.76.0/24',
|
||||
// Ali Public DNS
|
||||
'223.5.5.0/24',
|
||||
'223.6.6.0/24',
|
||||
// Tencent DNSPod Public DNS
|
||||
'119.29.29.0/24',
|
||||
'119.28.28.0/24',
|
||||
'120.53.53.0/24',
|
||||
'1.12.12.0/24',
|
||||
'1.12.34.0/24',
|
||||
// ByteDance Public DNS
|
||||
'180.184.1.0/24',
|
||||
'180.184.2.0/24',
|
||||
// 360 Public DNS
|
||||
'101.198.198.0/24',
|
||||
'101.198.199.0/24'
|
||||
];
|
||||
@ -11,7 +11,6 @@ import { buildRejectDomainSet } from './build-reject-domainset';
|
||||
import { buildTelegramCIDR } from './build-telegram-cidr';
|
||||
import { buildChnCidr } from './build-chn-cidr';
|
||||
import { buildSpeedtestDomainSet } from './build-speedtest-domainset';
|
||||
import { buildInternalReverseChnCIDR } from './build-internal-reverse-chn-cidr';
|
||||
import { buildDomesticRuleset } from './build-domestic-direct-lan-ruleset-dns-mapping-module';
|
||||
import { buildStreamService } from './build-stream-service';
|
||||
|
||||
@ -92,7 +91,6 @@ const buildFinishedLock = path.join(ROOT_DIR, '.BUILD_FINISHED');
|
||||
downloadPreviousBuildPromise.then(() => buildTelegramCIDR(rootSpan)),
|
||||
downloadPreviousBuildPromise.then(() => buildChnCidr(rootSpan)),
|
||||
downloadPreviousBuildPromise.then(() => buildSpeedtestDomainSet(rootSpan)),
|
||||
buildInternalReverseChnCIDR(rootSpan),
|
||||
downloadPreviousBuildPromise.then(() => buildDomesticRuleset(rootSpan)),
|
||||
downloadPreviousBuildPromise.then(() => buildRedirectModule(rootSpan)),
|
||||
downloadPreviousBuildPromise.then(() => buildAlwaysRealIPModule(rootSpan)),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user