mirror of
https://git.mirrors.martin98.com/https://github.com/sub-store-org/Sub-Store.git
synced 2025-08-10 07:09:00 +08:00
feat: 域名解析支持自定义 EDNS(需新版前端)
This commit is contained in:
parent
32dcca4a26
commit
bfe072cbdf
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "sub-store",
|
"name": "sub-store",
|
||||||
"version": "2.14.343",
|
"version": "2.14.344",
|
||||||
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.",
|
||||||
"main": "src/main.js",
|
"main": "src/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -391,7 +391,7 @@ function parseIP4P(IP4P) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const DOMAIN_RESOLVERS = {
|
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 id = hex_md5(`CUSTOM:${url}:${domain}:${type}`);
|
||||||
const cached = resourceCache.get(id);
|
const cached = resourceCache.get(id);
|
||||||
if (!noCache && cached) return cached;
|
if (!noCache && cached) return cached;
|
||||||
@ -400,6 +400,7 @@ const DOMAIN_RESOLVERS = {
|
|||||||
domain,
|
domain,
|
||||||
type: type === 'IPv6' ? 'AAAA' : 'A',
|
type: type === 'IPv6' ? 'AAAA' : 'A',
|
||||||
timeout,
|
timeout,
|
||||||
|
edns,
|
||||||
});
|
});
|
||||||
const { answers } = res;
|
const { answers } = res;
|
||||||
if (!Array.isArray(answers) || answers.length === 0) {
|
if (!Array.isArray(answers) || answers.length === 0) {
|
||||||
@ -412,14 +413,16 @@ const DOMAIN_RESOLVERS = {
|
|||||||
resourceCache.set(id, result);
|
resourceCache.set(id, result);
|
||||||
return 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 id = hex_md5(`GOOGLE:${domain}:${type}`);
|
||||||
const cached = resourceCache.get(id);
|
const cached = resourceCache.get(id);
|
||||||
if (!noCache && cached) return cached;
|
if (!noCache && cached) return cached;
|
||||||
const resp = await $.http.get({
|
const resp = await $.http.get({
|
||||||
url: `https://8.8.4.4/resolve?name=${encodeURIComponent(
|
url: `https://8.8.4.4/resolve?name=${encodeURIComponent(
|
||||||
domain,
|
domain,
|
||||||
)}&type=${type === 'IPv6' ? 'AAAA' : 'A'}`,
|
)}&type=${
|
||||||
|
type === 'IPv6' ? 'AAAA' : 'A'
|
||||||
|
}&edns_client_subnet=${edns}`,
|
||||||
headers: {
|
headers: {
|
||||||
accept: 'application/dns-json',
|
accept: 'application/dns-json',
|
||||||
},
|
},
|
||||||
@ -495,12 +498,12 @@ const DOMAIN_RESOLVERS = {
|
|||||||
resourceCache.set(id, result);
|
resourceCache.set(id, result);
|
||||||
return 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 id = hex_md5(`ALI:${domain}:${type}`);
|
||||||
const cached = resourceCache.get(id);
|
const cached = resourceCache.get(id);
|
||||||
if (!noCache && cached) return cached;
|
if (!noCache && cached) return cached;
|
||||||
const resp = await $.http.get({
|
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,
|
domain,
|
||||||
)}&type=${type === 'IPv6' ? 'AAAA' : 'A'}&short=1`,
|
)}&type=${type === 'IPv6' ? 'AAAA' : 'A'}&short=1`,
|
||||||
headers: {
|
headers: {
|
||||||
@ -519,12 +522,12 @@ const DOMAIN_RESOLVERS = {
|
|||||||
resourceCache.set(id, result);
|
resourceCache.set(id, result);
|
||||||
return 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 id = hex_md5(`TENCENT:${domain}:${type}`);
|
||||||
const cached = resourceCache.get(id);
|
const cached = resourceCache.get(id);
|
||||||
if (!noCache && cached) return cached;
|
if (!noCache && cached) return cached;
|
||||||
const resp = await $.http.get({
|
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'
|
type === 'IPv6' ? 'AAAA' : 'A'
|
||||||
}&dn=${encodeURIComponent(domain)}`,
|
}&dn=${encodeURIComponent(domain)}`,
|
||||||
headers: {
|
headers: {
|
||||||
@ -552,6 +555,7 @@ function ResolveDomainOperator({
|
|||||||
cache,
|
cache,
|
||||||
url,
|
url,
|
||||||
timeout,
|
timeout,
|
||||||
|
edns: _edns,
|
||||||
}) {
|
}) {
|
||||||
if (['IPv6', 'IP4P'].includes(_type) && ['IP-API'].includes(provider)) {
|
if (['IPv6', 'IP4P'].includes(_type) && ['IP-API'].includes(provider)) {
|
||||||
throw new Error(`域名解析服务提供方 ${provider} 不支持 ${_type}`);
|
throw new Error(`域名解析服务提供方 ${provider} 不支持 ${_type}`);
|
||||||
@ -564,7 +568,11 @@ function ResolveDomainOperator({
|
|||||||
if (!resolver) {
|
if (!resolver) {
|
||||||
throw new Error(`找不到域名解析服务提供方: ${provider}`);
|
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 {
|
return {
|
||||||
name: 'Resolve Domain Operator',
|
name: 'Resolve Domain Operator',
|
||||||
func: async (proxies) => {
|
func: async (proxies) => {
|
||||||
@ -592,6 +600,7 @@ function ResolveDomainOperator({
|
|||||||
type,
|
type,
|
||||||
cache === 'disabled',
|
cache === 'disabled',
|
||||||
requestTimeout,
|
requestTimeout,
|
||||||
|
edns,
|
||||||
url,
|
url,
|
||||||
)
|
)
|
||||||
.then((ip) => {
|
.then((ip) => {
|
||||||
|
@ -2,13 +2,7 @@ import $ from '@/core/app';
|
|||||||
import dnsPacket from 'dns-packet';
|
import dnsPacket from 'dns-packet';
|
||||||
import { Buffer } from 'buffer';
|
import { Buffer } from 'buffer';
|
||||||
|
|
||||||
export async function doh({
|
export async function doh({ url, domain, type = 'A', timeout, edns }) {
|
||||||
url,
|
|
||||||
domain,
|
|
||||||
type = 'A',
|
|
||||||
timeout,
|
|
||||||
ip = '223.6.6.6',
|
|
||||||
}) {
|
|
||||||
const buf = dnsPacket.encode({
|
const buf = dnsPacket.encode({
|
||||||
type: 'query',
|
type: 'query',
|
||||||
id: 0,
|
id: 0,
|
||||||
@ -28,7 +22,7 @@ export async function doh({
|
|||||||
options: [
|
options: [
|
||||||
{
|
{
|
||||||
code: 'CLIENT_SUBNET',
|
code: 'CLIENT_SUBNET',
|
||||||
ip,
|
ip: edns,
|
||||||
sourcePrefixLength: 24,
|
sourcePrefixLength: 24,
|
||||||
scopePrefixLength: 0,
|
scopePrefixLength: 0,
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user