Skip to content

Commit

Permalink
feat: discard domains not resolvable
Browse files Browse the repository at this point in the history
  • Loading branch information
proletarius101 committed Aug 1, 2020
1 parent c53923e commit 71a26a8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
7 changes: 7 additions & 0 deletions docs/guide/custom-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,3 +271,10 @@ Clash 规则中的 `interval`。
1. 全局模板变量的用法和 Artifact 中定义的模板变量相同,相关文档请查阅 [这里](/guide/custom-artifact.md#customparams)
2. 在合并全局、局部模板变量和面板 URL 参数时的优先级为:URL 参数 > 局部 > 全局;
:::

### checkHostname

- 类型: `boolean`
- 默认值: `false`

是否丢弃无法解析出域名 IP 地址的节点。无法解析出域名的节点有可能会导致 Clash 的 `url-test` 模式抛出异常而中止,丢弃这些节点可以避免这个问题。如果不是用公共 DNS 解析节点域名,或者有其它机制,可以关闭此项检测。
13 changes: 13 additions & 0 deletions lib/generator/artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,19 @@ export class Artifact extends EventEmitter {
nodeConfig.mptcp = provider.mptcp;
}

// check whether the hostname resolves in case of blocking clash's node heurestic
if (
config?.checkHostname &&
!isIp(nodeConfig.hostname)
) {
try {
await resolveDomain(nodeConfig.hostname);
} catch (err) /* istanbul ignore next */ {
logger.warn(`${nodeConfig.hostname} 无法解析,将忽略该节点`);
return undefined;
}
}

if (
config?.surgeConfig?.resolveHostname &&
!isIp(nodeConfig.hostname) &&
Expand Down
1 change: 1 addition & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface CommandConfig {
readonly templateDir: string;
readonly configDir: string;
readonly analytics?: boolean;
readonly checkHostname?: boolean;
readonly upload?: {
readonly prefix: string;
readonly region: string;
Expand Down
1 change: 1 addition & 0 deletions lib/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const normalizeConfig = (cwd: string, userConfig: Partial<CommandConfig>)
},
proxyTestUrl: PROXY_TEST_URL,
proxyTestInterval: PROXY_TEST_INTERVAL,
checkHostname: false,
};
const config: CommandConfig = _.defaultsDeep(userConfig, defaultConfig);

Expand Down

0 comments on commit 71a26a8

Please sign in to comment.