Skip to content

Commit

Permalink
fix: 域名解析修复; 结果增加 _IP4P 字段
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Jul 18, 2024
1 parent fea9de4 commit a0c1bbb
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 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.349",
"version": "2.14.350",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
"main": "src/main.js",
"scripts": {
Expand Down
36 changes: 22 additions & 14 deletions backend/src/core/proxy-utils/processors/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,10 @@ function ScriptOperator(script, targetPlatform, $arguments, source) {
};
}

function parseIP4P(ip) {
function parseIP4P(IP4P) {
let server;
let port;
try {
const IP4P = new ipAddress.Address6(ip).correctForm();
if (!/^2001::[^:]+:[^:]+:[^:]+$/.test(IP4P)) {
throw new Error(`Invalid IP4P: ${IP4P}`);
}
let array = IP4P.split(':');

port = parseInt(array[2], 16);
Expand Down Expand Up @@ -623,26 +619,38 @@ function ResolveDomainOperator({
if (!p['_no-resolve']) {
if (results[p.server]) {
p._resolved_ips = results[p.server];
const ip = Array.isArray(results[p.server])
let ip = Array.isArray(results[p.server])
? results[p.server][
Math.floor(
Math.random() * results[p.server].length,
)
]
: results[p.server];
if (type === 'IPv6' && isIPv6(ip)) {
const { server, port } = parseIP4P(ip);
if (server && port) {
ip = new ipAddress.Address6(ip).correctForm();
if (/^2001::[^:]+:[^:]+:[^:]+$/.test(ip)) {
const { server, port } = parseIP4P(ip);
if (server && port) {
p._domain = p.server;
p.server = server;
p.port = port;
p.resolved = true;
p._IPv4 = p.server;
p._IP4P = ip;
if (!isIP(p._IP)) {
p._IP = p.server;
}
} else if (!p.resolved) {
p.resolved = false;
}
} else {
p._domain = p.server;
p.server = server;
p.port = port;
p.server = ip;
p.resolved = true;
p._IPv4 = p.server;
p[`_${type}`] = p.server;
if (!isIP(p._IP)) {
p._IP = p.server;
}
} else {
p.resolved = false;
}
} else {
p._domain = p.server;
Expand All @@ -653,7 +661,7 @@ function ResolveDomainOperator({
p._IP = p.server;
}
}
} else {
} else if (!p.resolved) {
p.resolved = false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function operator(proxies = [], targetPlatform, context) {
// 0. 结构大致参考了 Clash.Meta(mihomo), 可参考 mihomo 的文档, 例如 `xudp`, `smux` 都可以自己设置. 但是有私货, 下面是我能想起来的一些私货
// 1. `_no-resolve` 为不解析域名
// 2. 域名解析后 会多一个 `_resolved` 字段, 表示是否解析成功
// 3. 域名解析后会有`_IPv4`, `_IPv6`, `_IP`(若有多个步骤, 只取第一次成功的 v4 或 v6 数据), `_domain` 字段, `_resolved_ips` 为解析出的所有 IP
// 3. 域名解析后会有`_IPv4`, `_IPv6`, `_IP`(若有多个步骤, 只取第一次成功的 v4 或 v6 数据), `_IP4P`(若解析类型为 IPv6 且符合 IP4P 类型, 将自动转换), `_domain` 字段, `_resolved_ips` 为解析出的所有 IP
// 4. 节点字段 `exec` 为 `ssr-local` 路径, 默认 `/usr/local/bin/ssr-local`; 端口从 10000 开始递增(暂不支持配置)
// 5. `_subName` 为单条订阅名
// 6. `_collectionName` 为组合订阅名
Expand Down

0 comments on commit a0c1bbb

Please sign in to comment.