Skip to content

Commit

Permalink
feat: 调整了 dns 解析的参数
Browse files Browse the repository at this point in the history
  • Loading branch information
geekdada committed Dec 11, 2020
1 parent 879080b commit b7aa7eb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 3 additions & 1 deletion docs/guide/custom-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,9 @@ Clash 规则中的 `interval`。
- 类型: `boolean`
- 默认值: `false`

是否丢弃无法解析出域名 IP 地址的节点。无法解析出域名的节点有可能会导致 Clash 的 `url-test` 模式抛出异常而中止,丢弃这些节点可以避免这个问题。如果不是用公共 DNS 解析节点域名,或者有其它机制,可以关闭此项检测。
是否丢弃无法解析出域名 IP 地址的节点。无法解析出域名的节点有可能会导致 Clash 的 `url-test` 模式抛出异常而中止,丢弃这些节点可以避免这个问题。

某些机场的节点域名 TTL 非常小,在某些情况下可能会导致 DNS 回溯解析超时,这样会导致节点本身可用但是被抛弃,所以建议谨慎开启该选项。

### flags <Badge text="v2.5.0" vertical="middle" />

Expand Down
12 changes: 7 additions & 5 deletions lib/utils/constant.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// istanbul ignore file

import ms from 'ms';

export const NETWORK_TIMEOUT = process.env.SURGIO_NETWORK_TIMEOUT
? Number(process.env.SURGIO_NETWORK_TIMEOUT)
: 5000;
: ms('5s');

export const NETWORK_RESOLVE_TIMEOUT = process.env
.SURGIO_NETWORK_RESOLVE_TIMEOUT
? Number(process.env.SURGIO_NETWORK_RESOLVE_TIMEOUT)
: 3000;
: ms('10s');

export const NETWORK_CONCURRENCY = process.env.SURGIO_NETWORK_CONCURRENCY
? Number(process.env.SURGIO_NETWORK_CONCURRENCY)
Expand All @@ -26,7 +28,7 @@ export const OBFS_UA =

export const PROXY_TEST_URL = 'http://cp.cloudflare.com/generate_204';

export const PROXY_TEST_INTERVAL = 1200;
export const PROXY_TEST_INTERVAL = 1200; // 1200s

export const CLASH_SUPPORTED_RULE: ReadonlyArray<string> = [
'DOMAIN-SUFFIX',
Expand Down Expand Up @@ -83,12 +85,12 @@ export const MELLOW_UNSUPPORTED_RULE: ReadonlyArray<string> = [
export const REMOTE_SNIPPET_CACHE_MAXAGE: number = process.env
.SURGIO_REMOTE_SNIPPET_CACHE_MAXAGE
? Number(process.env.SURGIO_REMOTE_SNIPPET_CACHE_MAXAGE)
: 1000 * 60 * 60 * 12; // 12h
: ms('12h');

export const PROVIDER_CACHE_MAXAGE: number = process.env
.SURGIO_PROVIDER_CACHE_MAXAGE
? Number(process.env.SURGIO_PROVIDER_CACHE_MAXAGE)
: 10 * 60 * 1000; // 10min
: ms('10m');

export const CATEGORIES = {
SNIPPET: 'Snippet',
Expand Down
9 changes: 7 additions & 2 deletions lib/utils/dns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { NETWORK_RESOLVE_TIMEOUT } from './constant';
const Resolver = dns.Resolver;
const resolver = new Resolver();
const DomainCache = new LRU<string, ReadonlyArray<string>>({
max: 1000,
max: 5000,
});
const logger = createLogger({ service: 'surgio:utils:dns' });

Expand All @@ -29,11 +29,16 @@ export const resolveDomain = async (
}

logger.debug(`try to resolve domain ${domain}`);
const now = Date.now();
const records = await Bluebird.race<ReadonlyArray<RecordWithTtl>>([
resolve4And6(domain),
Bluebird.delay(timeout).then(() => []),
]);
logger.debug(`resolved domain ${domain}: ${JSON.stringify(records)}`);
logger.debug(
`resolved domain ${domain}: ${JSON.stringify(records)} ${
Date.now() - now
}ms`
);

if (records.length) {
const address = records.map((item) => item.address);
Expand Down

0 comments on commit b7aa7eb

Please sign in to comment.