|
@@ -5,25 +5,42 @@ import { onBlackFound } from './shared';
|
|
|
|
|
|
|
|
const rSpace = /\s+/;
|
|
const rSpace = /\s+/;
|
|
|
|
|
|
|
|
-function hostsLineCb(line: string, set: string[], includeAllSubDomain: boolean, meta: string) {
|
|
|
|
|
- const _domain = line.split(rSpace, 3)[1]?.trim();
|
|
|
|
|
|
|
+function hostsLineCb(line: string, set: string[], meta: string) {
|
|
|
|
|
+ const _domain = line.split(rSpace, 3)[1];
|
|
|
if (!_domain) {
|
|
if (!_domain) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- const domain = fastNormalizeDomainWithoutWww(_domain);
|
|
|
|
|
|
|
+ const domain = fastNormalizeDomainWithoutWww(_domain.trim());
|
|
|
if (!domain) {
|
|
if (!domain) {
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
onBlackFound(domain, meta);
|
|
onBlackFound(domain, meta);
|
|
|
|
|
|
|
|
- set.push(includeAllSubDomain ? `.${domain}` : domain);
|
|
|
|
|
|
|
+ set.push(domain);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+function hostsLineCbIncludeAllSubdomain(line: string, set: string[], meta: string) {
|
|
|
|
|
+ const _domain = line.split(rSpace, 3)[1];
|
|
|
|
|
+ if (!_domain) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+ const domain = fastNormalizeDomainWithoutWww(_domain.trim());
|
|
|
|
|
+ if (!domain) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ onBlackFound(domain, meta);
|
|
|
|
|
+
|
|
|
|
|
+ set.push('.' + domain);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
export function processHosts(
|
|
export function processHosts(
|
|
|
span: Span,
|
|
span: Span,
|
|
|
hostsUrl: string, mirrors: string[] | null, includeAllSubDomain = false
|
|
hostsUrl: string, mirrors: string[] | null, includeAllSubDomain = false
|
|
|
) {
|
|
) {
|
|
|
|
|
+ const cb = includeAllSubDomain ? hostsLineCbIncludeAllSubdomain : hostsLineCb;
|
|
|
|
|
+
|
|
|
return span.traceChildAsync(`process hosts: ${hostsUrl}`, async (span) => {
|
|
return span.traceChildAsync(`process hosts: ${hostsUrl}`, async (span) => {
|
|
|
const filterRules = await span.traceChild('download').traceAsyncFn(() => fetchAssets(hostsUrl, mirrors, true));
|
|
const filterRules = await span.traceChild('download').traceAsyncFn(() => fetchAssets(hostsUrl, mirrors, true));
|
|
|
|
|
|
|
@@ -31,7 +48,7 @@ export function processHosts(
|
|
|
|
|
|
|
|
span.traceChild('parse hosts').traceSyncFn(() => {
|
|
span.traceChild('parse hosts').traceSyncFn(() => {
|
|
|
for (let i = 0, len = filterRules.length; i < len; i++) {
|
|
for (let i = 0, len = filterRules.length; i < len; i++) {
|
|
|
- hostsLineCb(filterRules[i], domainSets, includeAllSubDomain, hostsUrl);
|
|
|
|
|
|
|
+ cb(filterRules[i], domainSets, hostsUrl);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
@@ -41,6 +58,7 @@ export function processHosts(
|
|
|
|
|
|
|
|
export function processHostsWithPreload(hostsUrl: string, mirrors: string[] | null, includeAllSubDomain = false) {
|
|
export function processHostsWithPreload(hostsUrl: string, mirrors: string[] | null, includeAllSubDomain = false) {
|
|
|
const downloadPromise = fetchAssets(hostsUrl, mirrors, true);
|
|
const downloadPromise = fetchAssets(hostsUrl, mirrors, true);
|
|
|
|
|
+ const cb = includeAllSubDomain ? hostsLineCbIncludeAllSubdomain : hostsLineCb;
|
|
|
|
|
|
|
|
return (span: Span) => span.traceChildAsync(`process hosts: ${hostsUrl}`, async (span) => {
|
|
return (span: Span) => span.traceChildAsync(`process hosts: ${hostsUrl}`, async (span) => {
|
|
|
const filterRules = await span.traceChild('download').tracePromise(downloadPromise);
|
|
const filterRules = await span.traceChild('download').tracePromise(downloadPromise);
|
|
@@ -49,7 +67,7 @@ export function processHostsWithPreload(hostsUrl: string, mirrors: string[] | nu
|
|
|
|
|
|
|
|
span.traceChild('parse hosts').traceSyncFn(() => {
|
|
span.traceChild('parse hosts').traceSyncFn(() => {
|
|
|
for (let i = 0, len = filterRules.length; i < len; i++) {
|
|
for (let i = 0, len = filterRules.length; i < len; i++) {
|
|
|
- hostsLineCb(filterRules[i], domainSets, includeAllSubDomain, hostsUrl);
|
|
|
|
|
|
|
+ cb(filterRules[i], domainSets, hostsUrl);
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|