From bfe072cbdf49726c65bb6b27f27ae5beabc9df79 Mon Sep 17 00:00:00 2001 From: xream Date: Sat, 22 Jun 2024 11:45:37 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9F=9F=E5=90=8D=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=87=AA=E5=AE=9A=E4=B9=89=20EDNS(=E9=9C=80?= =?UTF-8?q?=E6=96=B0=E7=89=88=E5=89=8D=E7=AB=AF)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- .../src/core/proxy-utils/processors/index.js | 25 +++++++++++++------ backend/src/utils/dns.js | 10 ++------ 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/backend/package.json b/backend/package.json index 1086f7c..37d5372 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.343", + "version": "2.14.344", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/core/proxy-utils/processors/index.js b/backend/src/core/proxy-utils/processors/index.js index 6d7ffb0..6acff75 100644 --- a/backend/src/core/proxy-utils/processors/index.js +++ b/backend/src/core/proxy-utils/processors/index.js @@ -391,7 +391,7 @@ function parseIP4P(IP4P) { } const DOMAIN_RESOLVERS = { - Custom: async function (domain, type, noCache, timeout, url) { + Custom: async function (domain, type, noCache, timeout, edns, url) { const id = hex_md5(`CUSTOM:${url}:${domain}:${type}`); const cached = resourceCache.get(id); if (!noCache && cached) return cached; @@ -400,6 +400,7 @@ const DOMAIN_RESOLVERS = { domain, type: type === 'IPv6' ? 'AAAA' : 'A', timeout, + edns, }); const { answers } = res; if (!Array.isArray(answers) || answers.length === 0) { @@ -412,14 +413,16 @@ const DOMAIN_RESOLVERS = { resourceCache.set(id, result); return result; }, - Google: async function (domain, type, noCache, timeout) { + Google: async function (domain, type, noCache, timeout, edns) { const id = hex_md5(`GOOGLE:${domain}:${type}`); const cached = resourceCache.get(id); if (!noCache && cached) return cached; const resp = await $.http.get({ url: `https://8.8.4.4/resolve?name=${encodeURIComponent( domain, - )}&type=${type === 'IPv6' ? 'AAAA' : 'A'}`, + )}&type=${ + type === 'IPv6' ? 'AAAA' : 'A' + }&edns_client_subnet=${edns}`, headers: { accept: 'application/dns-json', }, @@ -495,12 +498,12 @@ const DOMAIN_RESOLVERS = { resourceCache.set(id, result); return result; }, - Ali: async function (domain, type, noCache, timeout) { + Ali: async function (domain, type, noCache, timeout, edns) { const id = hex_md5(`ALI:${domain}:${type}`); const cached = resourceCache.get(id); if (!noCache && cached) return cached; const resp = await $.http.get({ - url: `http://223.6.6.6/resolve?edns_client_subnet=223.6.6.6/24&name=${encodeURIComponent( + url: `http://223.6.6.6/resolve?edns_client_subnet=${edns}/24&name=${encodeURIComponent( domain, )}&type=${type === 'IPv6' ? 'AAAA' : 'A'}&short=1`, headers: { @@ -519,12 +522,12 @@ const DOMAIN_RESOLVERS = { resourceCache.set(id, result); return result; }, - Tencent: async function (domain, type, noCache, timeout) { + Tencent: async function (domain, type, noCache, timeout, edns) { const id = hex_md5(`TENCENT:${domain}:${type}`); const cached = resourceCache.get(id); if (!noCache && cached) return cached; const resp = await $.http.get({ - url: `http://119.28.28.28/d?ip=119.28.28.28&type=${ + url: `http://119.28.28.28/d?ip=${edns}&type=${ type === 'IPv6' ? 'AAAA' : 'A' }&dn=${encodeURIComponent(domain)}`, headers: { @@ -552,6 +555,7 @@ function ResolveDomainOperator({ cache, url, timeout, + edns: _edns, }) { if (['IPv6', 'IP4P'].includes(_type) && ['IP-API'].includes(provider)) { throw new Error(`域名解析服务提供方 ${provider} 不支持 ${_type}`); @@ -564,7 +568,11 @@ function ResolveDomainOperator({ if (!resolver) { throw new Error(`找不到域名解析服务提供方: ${provider}`); } - $.info(`Domain Resolver: [${_type}] ${provider} ${url || ''}`); + let edns = _edns || '223.6.6.6'; + if (!isIP(edns)) throw new Error(`域名解析 EDNS 应为 IP`); + $.info( + `Domain Resolver: [${_type}] ${provider} ${edns || ''} ${url || ''}`, + ); return { name: 'Resolve Domain Operator', func: async (proxies) => { @@ -592,6 +600,7 @@ function ResolveDomainOperator({ type, cache === 'disabled', requestTimeout, + edns, url, ) .then((ip) => { diff --git a/backend/src/utils/dns.js b/backend/src/utils/dns.js index c678057..2321250 100644 --- a/backend/src/utils/dns.js +++ b/backend/src/utils/dns.js @@ -2,13 +2,7 @@ import $ from '@/core/app'; import dnsPacket from 'dns-packet'; import { Buffer } from 'buffer'; -export async function doh({ - url, - domain, - type = 'A', - timeout, - ip = '223.6.6.6', -}) { +export async function doh({ url, domain, type = 'A', timeout, edns }) { const buf = dnsPacket.encode({ type: 'query', id: 0, @@ -28,7 +22,7 @@ export async function doh({ options: [ { code: 'CLIENT_SUBNET', - ip, + ip: edns, sourcePrefixLength: 24, scopePrefixLength: 0, },