ソースを参照

Update China IPv4

SukkaW 1 年間 前
コミット
8e2644ac6c
2 ファイル変更38 行追加21 行削除
  1. 19 9
      Build/build-chn-cidr.ts
  2. 19 12
      Build/constants/cidr.ts

+ 19 - 9
Build/build-chn-cidr.ts

@@ -2,32 +2,42 @@ import { fetchRemoteTextByLine } from './lib/fetch-text-by-line';
 import { processLineFromReadline } from './lib/process-line';
 import { processLineFromReadline } from './lib/process-line';
 import { task } from './trace';
 import { task } from './trace';
 
 
-import { contains, exclude } from 'fast-cidr-tools';
+import { contains as containsCidr, exclude as excludeCidr } from 'fast-cidr-tools';
 import { createMemoizedPromise } from './lib/memo-promise';
 import { createMemoizedPromise } from './lib/memo-promise';
-import { CN_CIDR_NOT_INCLUDED_IN_CHNROUTE, NON_CN_CIDR_INCLUDED_IN_CHNROUTE } from './constants/cidr';
+import { CN_CIDR_MISSING_IN_CHNROUTE, NON_CN_CIDR_INCLUDED_IN_CHNROUTE } from './constants/cidr';
 import { appendArrayInPlace } from './lib/append-array-in-place';
 import { appendArrayInPlace } from './lib/append-array-in-place';
 import { IPListOutput } from './lib/create-file';
 import { IPListOutput } from './lib/create-file';
 import { cachedOnlyFail } from './lib/fs-memo';
 import { cachedOnlyFail } from './lib/fs-memo';
 
 
-const PROBE_CHN_CIDR = [
+const PROBE_CHN_CIDR_V4 = [
   // NetEase Hangzhou
   // NetEase Hangzhou
-  '223.252.196.38'
+  '223.252.196.38',
+  // Aliyun ShenZhen
+  '120.78.92.171'
 ];
 ];
 
 
 export const getChnCidrPromise = createMemoizedPromise(cachedOnlyFail(
 export const getChnCidrPromise = createMemoizedPromise(cachedOnlyFail(
   async function getChnCidr() {
   async function getChnCidr() {
-    const [cidr4, cidr6] = await Promise.all([
+    const [_cidr4, cidr6] = await Promise.all([
       fetchRemoteTextByLine('https://raw.githubusercontent.com/misakaio/chnroutes2/master/chnroutes.txt').then(processLineFromReadline),
       fetchRemoteTextByLine('https://raw.githubusercontent.com/misakaio/chnroutes2/master/chnroutes.txt').then(processLineFromReadline),
       fetchRemoteTextByLine('https://gaoyifan.github.io/china-operator-ip/china6.txt').then(processLineFromReadline)
       fetchRemoteTextByLine('https://gaoyifan.github.io/china-operator-ip/china6.txt').then(processLineFromReadline)
     ]);
     ]);
 
 
-    appendArrayInPlace(cidr4, CN_CIDR_NOT_INCLUDED_IN_CHNROUTE);
+    const cidr4 = excludeCidr(
+      appendArrayInPlace(_cidr4, CN_CIDR_MISSING_IN_CHNROUTE),
+      NON_CN_CIDR_INCLUDED_IN_CHNROUTE,
+      true
+    );
 
 
-    if (!contains(cidr4, PROBE_CHN_CIDR)) {
-      throw new TypeError('chnroutes missing probe IP');
+    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 [exclude(cidr4, NON_CN_CIDR_INCLUDED_IN_CHNROUTE, true), cidr6] as const;
+    return [cidr4, cidr6] as const;
   },
   },
   {
   {
     serializer: JSON.stringify,
     serializer: JSON.stringify,

+ 19 - 12
Build/constants/cidr.ts

@@ -25,7 +25,8 @@ export const NON_CN_CIDR_INCLUDED_IN_CHNROUTE = [
 ];
 ];
 
 
 // https://github.com/misakaio/chnroutes2/issues/46
 // https://github.com/misakaio/chnroutes2/issues/46
-export const CN_CIDR_NOT_INCLUDED_IN_CHNROUTE = [
+// https://github.com/misakaio/chnroutes2/issues/48
+export const CN_CIDR_MISSING_IN_CHNROUTE = [
   // Baidu Public DNS
   // Baidu Public DNS
   '180.76.76.0/24',
   '180.76.76.0/24',
   // Ali Public DNS
   // Ali Public DNS
@@ -44,19 +45,25 @@ export const CN_CIDR_NOT_INCLUDED_IN_CHNROUTE = [
   '101.198.198.0/24',
   '101.198.198.0/24',
   '101.198.199.0/24',
   '101.198.199.0/24',
 
 
-  '211.99.96.0/19', // wy.com.cn
+  // Aliyun Shenzhen
+  '120.78.0.0/16',
 
 
-  '40.72.0.0/15', // AS58593, Azure China, Shanghai
-  '42.159.0.0/16', // AS58593, Azure China, Shanghai
-  '52.130.0.0/17', // AS58593, Azure China, Shanghai
-  '52.131.0.0/16', // AS58593, Azure China, Beijing
-  '103.9.8.0/22', // AS58593, Azure China, Backbone
-  '139.217.0.0/16', // AS58593, Azure China, Shanghai
-  '139.219.0.0/16', // AS58593, Azure China, Shanghai
-  '143.64.0.0/16', // AS58593, Azure China, Beijing
-  '159.27.0.0/16', // AS58593, Azure China, Beijing
-  '163.228.0.0/16', // AS58593, Azure China, Beijing
+  // 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
   // NetEase
+  '223.252.194.0/24',
   '223.252.196.0/24'
   '223.252.196.0/24'
 ];
 ];