|
@@ -1,44 +1,57 @@
|
|
|
import { task } from './trace';
|
|
import { task } from './trace';
|
|
|
-import { fetchRemoteTextByLine } from './lib/fetch-text-by-line';
|
|
|
|
|
-import { HostnameSmolTrie } from './lib/trie';
|
|
|
|
|
import { SHARED_DESCRIPTION } from './constants/description';
|
|
import { SHARED_DESCRIPTION } from './constants/description';
|
|
|
import { createMemoizedPromise } from './lib/memo-promise';
|
|
import { createMemoizedPromise } from './lib/memo-promise';
|
|
|
-import { extractDomainsFromFelixDnsmasq } from './lib/parse-dnsmasq';
|
|
|
|
|
import { RulesetOutput } from './lib/rules/ruleset';
|
|
import { RulesetOutput } from './lib/rules/ruleset';
|
|
|
-import { appendArrayInPlace } from './lib/append-array-in-place';
|
|
|
|
|
|
|
+import Worktank from 'worktank';
|
|
|
|
|
|
|
|
-const PROBE_DOMAINS = ['.microsoft.com', '.windows.net', '.windows.com', '.windowsupdate.com', '.windowssearch.com', '.office.net'];
|
|
|
|
|
|
|
+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
|
|
|
|
|
+ getMicrosoftCdnRuleset: async function (importMetaUrl: string): Promise<[domains: string[], domainSuffixes: string[]]> {
|
|
|
|
|
+ // 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 DOMAINS = [
|
|
|
|
|
- 'res.cdn.office.net',
|
|
|
|
|
- 'res-1.cdn.office.net',
|
|
|
|
|
- 'statics.teams.cdn.office.net'
|
|
|
|
|
-];
|
|
|
|
|
-const DOMAIN_SUFFIXES = ['download.prss.microsoft.com'];
|
|
|
|
|
|
|
+ const { HostnameSmolTrie } = __require('./lib/trie');
|
|
|
|
|
+ const { PROBE_DOMAINS, DOMAINS, DOMAIN_SUFFIXES, BLACKLIST } = __require('./constants/microsoft-cdn') as typeof import('./constants/microsoft-cdn');
|
|
|
|
|
+ const { fetchRemoteTextByLine } = __require('./lib/fetch-text-by-line') as typeof import('./lib/fetch-text-by-line');
|
|
|
|
|
+ const { appendArrayInPlace } = __require('./lib/append-array-in-place') as typeof import('./lib/append-array-in-place');
|
|
|
|
|
+ const { extractDomainsFromFelixDnsmasq } = __require('./lib/parse-dnsmasq') as typeof import('./lib/parse-dnsmasq');
|
|
|
|
|
|
|
|
-const BLACKLIST = [
|
|
|
|
|
- 'www.microsoft.com',
|
|
|
|
|
- 'windowsupdate.com'
|
|
|
|
|
-];
|
|
|
|
|
|
|
+ const trie = new HostnameSmolTrie();
|
|
|
|
|
|
|
|
-export const getMicrosoftCdnRulesetPromise = createMemoizedPromise<[domains: string[], domainSuffixes: string[]]>(async () => {
|
|
|
|
|
- // First trie is to find the microsoft domains that matches probe domains
|
|
|
|
|
- const trie = new HostnameSmolTrie();
|
|
|
|
|
|
|
+ for await (const line of await fetchRemoteTextByLine('https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/accelerated-domains.china.conf')) {
|
|
|
|
|
+ const domain = extractDomainsFromFelixDnsmasq(line);
|
|
|
|
|
+ if (domain) {
|
|
|
|
|
+ trie.add(domain);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // remove blacklist domain from trie, to prevent them from being included in the later dump
|
|
|
|
|
+ BLACKLIST.forEach(black => trie.whitelist(black));
|
|
|
|
|
+
|
|
|
|
|
+ const domains: string[] = DOMAINS;
|
|
|
|
|
+ const domainSuffixes = appendArrayInPlace(PROBE_DOMAINS.flatMap(domain => trie.find(domain)), DOMAIN_SUFFIXES);
|
|
|
|
|
|
|
|
- for await (const line of await fetchRemoteTextByLine('https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/accelerated-domains.china.conf')) {
|
|
|
|
|
- const domain = extractDomainsFromFelixDnsmasq(line);
|
|
|
|
|
- if (domain) {
|
|
|
|
|
- trie.add(domain);
|
|
|
|
|
|
|
+ return [domains, domainSuffixes] as const;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+});
|
|
|
|
|
|
|
|
- // remove blacklist domain from trie, to prevent them from being included in the later dump
|
|
|
|
|
- BLACKLIST.forEach(black => trie.whitelist(black));
|
|
|
|
|
-
|
|
|
|
|
- const domains: string[] = DOMAINS;
|
|
|
|
|
- const domainSuffixes = appendArrayInPlace(PROBE_DOMAINS.flatMap(domain => trie.find(domain)), DOMAIN_SUFFIXES);
|
|
|
|
|
|
|
+export const getMicrosoftCdnRulesetPromise = createMemoizedPromise<[domains: string[], domainSuffixes: string[]]>(async () => {
|
|
|
|
|
+ const res = await pool.exec(
|
|
|
|
|
+ 'getMicrosoftCdnRuleset',
|
|
|
|
|
+ [import.meta.url]
|
|
|
|
|
+ );
|
|
|
|
|
+ pool.terminate();
|
|
|
|
|
|
|
|
- return [domains, domainSuffixes] as const;
|
|
|
|
|
|
|
+ return res;
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
export const buildMicrosoftCdn = task(require.main === module, __filename)(async (span) => {
|
|
export const buildMicrosoftCdn = task(require.main === module, __filename)(async (span) => {
|