Skip to content

Commit

Permalink
feat: 域名解析新增 _resolved_ips 为解析出的所有 IP
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Jun 20, 2024
1 parent 91aab3c commit 2b3b917
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.14.341",
"version": "2.14.342",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {
Expand Down
48 changes: 36 additions & 12 deletions backend/src/core/proxy-utils/processors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,10 +406,13 @@ const DOMAIN_RESOLVERS = {
throw new Error(`Status is ${body['Status']}`);
}
const answers = body['Answer'];
if (answers.length === 0) {
if (!Array.isArray(answers) || answers.length === 0) {
throw new Error('No answers');
}
const result = answers.map((i) => i?.data).filter((i) => i);
if (result.length === 0) {
throw new Error('No answers');
}
const result = answers[answers.length - 1].data;
resourceCache.set(id, result);
return result;
},
Expand All @@ -429,7 +432,13 @@ const DOMAIN_RESOLVERS = {
if (body['status'] !== 'success') {
throw new Error(`Status is ${body['status']}`);
}
const result = body.query;
if (!body.query || body.query === 0) {
throw new Error('No answers');
}
const result = [body.query];
if (result.length === 0) {
throw new Error('No answers');
}
resourceCache.set(id, result);
return result;
},
Expand All @@ -450,10 +459,13 @@ const DOMAIN_RESOLVERS = {
throw new Error(`Status is ${body['Status']}`);
}
const answers = body['Answer'];
if (answers.length === 0) {
if (!Array.isArray(answers) || answers.length === 0) {
throw new Error('No answers');
}
const result = answers.map((i) => i?.data).filter((i) => i);
if (result.length === 0) {
throw new Error('No answers');
}
const result = answers[answers.length - 1].data;
resourceCache.set(id, result);
return result;
},
Expand All @@ -470,10 +482,13 @@ const DOMAIN_RESOLVERS = {
},
});
const answers = JSON.parse(resp.body);
if (answers.length === 0) {
if (!Array.isArray(answers) || answers.length === 0) {
throw new Error('No answers');
}
const result = answers;
if (result.length === 0) {
throw new Error('No answers');
}
const result = answers[answers.length - 1];
resourceCache.set(id, result);
return result;
},
Expand All @@ -493,7 +508,10 @@ const DOMAIN_RESOLVERS = {
if (answers.length === 0 || String(answers) === '0') {
throw new Error('No answers');
}
const result = answers[answers.length - 1];
const result = answers;
if (result.length === 0) {
throw new Error('No answers');
}
resourceCache.set(id, result);
return result;
},
Expand Down Expand Up @@ -550,10 +568,16 @@ function ResolveDomainOperator({ provider, type: _type, filter, cache }) {
proxies.forEach((p) => {
if (!p['_no-resolve']) {
if (results[p.server]) {
p._resolved_ips = results[p.server];
const ip = Array.isArray(results[p.server])
? results[p.server][
Math.floor(
Math.random() * results[p.server].length,
)
]
: results[p.server];
if (_type === 'IP4P') {
const { server, port } = parseIP4P(
results[p.server],
);
const { server, port } = parseIP4P(ip);
if (server && port) {
p._domain = p.server;
p.server = server;
Expand All @@ -568,7 +592,7 @@ function ResolveDomainOperator({ provider, type: _type, filter, cache }) {
}
} else {
p._domain = p.server;
p.server = results[p.server];
p.server = ip;
p.resolved = true;
p[`_${type}`] = p.server;
if (!isIP(p._IP)) {
Expand Down
9 changes: 7 additions & 2 deletions scripts/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,16 @@ function operator(proxies = [], targetPlatform, context) {
// 结构大致参考了 Clash.Meta(mihomo) 有私货
// 可在预览界面点击节点查看 JSON 结构 或查看 `target=JSON` 的通用订阅
// 1. `_no-resolve` 为不解析域名
// 2. 域名解析后 会多一个 `_resolved` 字段
// 3. 域名解析后会有`_IPv4`, `_IPv6`, `_IP`(若有多个步骤, 只取第一次成功的 v4 或 v6 数据), `_domain` 字段
// 2. 域名解析后 会多一个 `_resolved` 字段, 表示是否解析成功
// 3. 域名解析后会有`_IPv4`, `_IPv6`, `_IP`(若有多个步骤, 只取第一次成功的 v4 或 v6 数据), `_domain` 字段, `_resolved_ips` 为解析出的所有 IP
// 4. 节点字段 `exec` 为 `ssr-local` 路径, 默认 `/usr/local/bin/ssr-local`; 端口从 10000 开始递增(暂不支持配置)
// 5. `_subName` 为单条订阅名
// 6. `_collectionName` 为组合订阅名
// 7. `tls-fingerprint` 为 tls 指纹
// 8. `underlying-proxy` 为前置代理
// 9. `trojan`, `tuic`, `hysteria`, `hysteria2`, `juicity` 会在解析时设置 `tls`: true (会使用 tls 类协议的通用逻辑), 输出时删除
// 10. `sni` 在某些协议里会自动与 `servername` 转换
// 11. 读取节点的 ca-str 和 _ca (后端文件路径) 字段, 自动计算 fingerprint (参考 https://t.me/zhetengsha/1512)

// $arguments 为传入的脚本参数

Expand Down

0 comments on commit 2b3b917

Please sign in to comment.