mirror of
https://github.com/MetaCubeX/metacubexd.git
synced 2024-11-10 05:15:35 +08:00
fix: proxy group ipv6 test failed (#996)
This commit is contained in:
parent
1ed63e94fe
commit
c43b84b114
@ -1,8 +1,7 @@
|
|||||||
import { useProxies } from '~/signals'
|
import { useProxies } from '~/signals'
|
||||||
import { proxyIPv6SupportMap } from '~/signals/ipv6'
|
|
||||||
|
|
||||||
export const IPv6Support = (props: { name?: string }) => {
|
export const IPv6Support = (props: { name?: string }) => {
|
||||||
const { getNowProxyNodeName } = useProxies()
|
const { getNowProxyNodeName, proxyIPv6SupportMap } = useProxies()
|
||||||
|
|
||||||
const support = createMemo(() => {
|
const support = createMemo(() => {
|
||||||
return proxyIPv6SupportMap()[getNowProxyNodeName(props.name || '')]
|
return proxyIPv6SupportMap()[getNowProxyNodeName(props.name || '')]
|
||||||
|
@ -1,71 +0,0 @@
|
|||||||
import { makePersisted } from '@solid-primitives/storage'
|
|
||||||
import { proxyGroupLatencyTestAPI, proxyLatencyTestAPI } from '~/apis'
|
|
||||||
import {
|
|
||||||
latencyQualityMap,
|
|
||||||
latencyTestTimeoutDuration,
|
|
||||||
urlForIPv6SupportTest,
|
|
||||||
} from './config'
|
|
||||||
|
|
||||||
export const [proxyIPv6SupportMap, setProxyIPv6SupportMap] = makePersisted(
|
|
||||||
createSignal<Record<string, boolean>>({}),
|
|
||||||
{
|
|
||||||
name: 'proxyIPv6SupportMap',
|
|
||||||
storage: localStorage,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
export const proxyIPv6SupportTest = async (
|
|
||||||
proxyName: string,
|
|
||||||
provider: string,
|
|
||||||
) => {
|
|
||||||
const urlForTest = urlForIPv6SupportTest()
|
|
||||||
|
|
||||||
if (!urlForTest || urlForTest.length === 0) {
|
|
||||||
setProxyIPv6SupportMap({})
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
let support = false
|
|
||||||
try {
|
|
||||||
const { delay } = await proxyLatencyTestAPI(
|
|
||||||
proxyName,
|
|
||||||
provider,
|
|
||||||
urlForTest,
|
|
||||||
latencyTestTimeoutDuration(),
|
|
||||||
)
|
|
||||||
support = delay > latencyQualityMap().NOT_CONNECTED
|
|
||||||
} catch {
|
|
||||||
support = false
|
|
||||||
}
|
|
||||||
setProxyIPv6SupportMap((supportMap) => ({
|
|
||||||
...supportMap,
|
|
||||||
[proxyName]: support,
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
export const proxyGroupIPv6SupportTest = async (proxyGroupName: string) => {
|
|
||||||
const urlForTest = urlForIPv6SupportTest()
|
|
||||||
|
|
||||||
if (!urlForTest || urlForTest.length === 0) {
|
|
||||||
setProxyIPv6SupportMap({})
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const newLatencyMap = await proxyGroupLatencyTestAPI(
|
|
||||||
proxyGroupName,
|
|
||||||
urlForTest,
|
|
||||||
latencyTestTimeoutDuration(),
|
|
||||||
)
|
|
||||||
const newSupportMap = Object.fromEntries(
|
|
||||||
Object.entries(newLatencyMap).map(([k, v]) => [
|
|
||||||
k,
|
|
||||||
v > latencyQualityMap().NOT_CONNECTED,
|
|
||||||
]),
|
|
||||||
)
|
|
||||||
setProxyIPv6SupportMap((supportMap) => ({
|
|
||||||
...supportMap,
|
|
||||||
...newSupportMap,
|
|
||||||
}))
|
|
||||||
}
|
|
@ -1,3 +1,4 @@
|
|||||||
|
import { makePersisted } from '@solid-primitives/storage'
|
||||||
import {
|
import {
|
||||||
closeSingleConnectionAPI,
|
closeSingleConnectionAPI,
|
||||||
fetchProxiesAPI,
|
fetchProxiesAPI,
|
||||||
@ -19,12 +20,6 @@ import {
|
|||||||
urlForLatencyTest,
|
urlForLatencyTest,
|
||||||
} from '~/signals'
|
} from '~/signals'
|
||||||
import type { Proxy, ProxyNode, ProxyProvider } from '~/types'
|
import type { Proxy, ProxyNode, ProxyProvider } from '~/types'
|
||||||
import {
|
|
||||||
proxyGroupIPv6SupportTest,
|
|
||||||
proxyIPv6SupportMap,
|
|
||||||
proxyIPv6SupportTest,
|
|
||||||
setProxyIPv6SupportMap,
|
|
||||||
} from './ipv6'
|
|
||||||
|
|
||||||
type ProxyInfo = {
|
type ProxyInfo = {
|
||||||
name: string
|
name: string
|
||||||
@ -66,6 +61,14 @@ const [proxyNodeMap, setProxyNodeMap] = createSignal<Record<string, ProxyInfo>>(
|
|||||||
{},
|
{},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const [proxyIPv6SupportMap, setProxyIPv6SupportMap] = makePersisted(
|
||||||
|
createSignal<Record<string, boolean>>({}),
|
||||||
|
{
|
||||||
|
name: 'proxyIPv6SupportMap',
|
||||||
|
storage: localStorage,
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
const getLatencyFromProxy = (
|
const getLatencyFromProxy = (
|
||||||
proxy: Pick<Proxy, 'extra' | 'history'>,
|
proxy: Pick<Proxy, 'extra' | 'history'>,
|
||||||
url: string,
|
url: string,
|
||||||
@ -217,6 +220,75 @@ export const useProxies = () => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const proxyIPv6SupportTest = async (proxyName: string, provider: string) => {
|
||||||
|
const urlForTest = urlForIPv6SupportTest()
|
||||||
|
|
||||||
|
if (!urlForTest || urlForTest.length === 0) {
|
||||||
|
setProxyIPv6SupportMap({})
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
let support = false
|
||||||
|
try {
|
||||||
|
const { delay } = await proxyLatencyTestAPI(
|
||||||
|
proxyName,
|
||||||
|
provider,
|
||||||
|
urlForTest,
|
||||||
|
latencyTestTimeoutDuration(),
|
||||||
|
)
|
||||||
|
support = delay > latencyQualityMap().NOT_CONNECTED
|
||||||
|
} catch {
|
||||||
|
support = false
|
||||||
|
}
|
||||||
|
setProxyIPv6SupportMap((supportMap) => ({
|
||||||
|
...supportMap,
|
||||||
|
[proxyName]: support,
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
const proxyGroupIPv6SupportTest = async (proxyGroupName: string) => {
|
||||||
|
const urlForTest = urlForIPv6SupportTest()
|
||||||
|
|
||||||
|
if (!urlForTest || urlForTest.length === 0) {
|
||||||
|
setProxyIPv6SupportMap({})
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const newLatencyMap = await proxyGroupLatencyTestAPI(
|
||||||
|
proxyGroupName,
|
||||||
|
urlForTest,
|
||||||
|
latencyTestTimeoutDuration(),
|
||||||
|
)
|
||||||
|
|
||||||
|
const newSupportMap = Object.fromEntries(
|
||||||
|
Object.entries(newLatencyMap).map(([nodeName, latency]) => [
|
||||||
|
getNowProxyNodeName(nodeName),
|
||||||
|
latency > latencyQualityMap().NOT_CONNECTED,
|
||||||
|
]),
|
||||||
|
)
|
||||||
|
setProxyIPv6SupportMap((supportMap) => ({
|
||||||
|
...supportMap,
|
||||||
|
...newSupportMap,
|
||||||
|
}))
|
||||||
|
} catch {
|
||||||
|
const allNodes = proxies().find((p) => p.name === proxyGroupName)?.all
|
||||||
|
|
||||||
|
if (!allNodes) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
setProxyIPv6SupportMap((proxyIPv6SupportMap) => ({
|
||||||
|
...proxyIPv6SupportMap,
|
||||||
|
...Object.fromEntries(
|
||||||
|
allNodes.map((name) => [getNowProxyNodeName(name), false]),
|
||||||
|
),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const updateProviderByProviderName = (providerName: string) =>
|
const updateProviderByProviderName = (providerName: string) =>
|
||||||
setUpdatingMap(providerName, async () => {
|
setUpdatingMap(providerName, async () => {
|
||||||
try {
|
try {
|
||||||
@ -305,5 +377,6 @@ export const useProxies = () => {
|
|||||||
getNowProxyNodeName,
|
getNowProxyNodeName,
|
||||||
getLatencyByName,
|
getLatencyByName,
|
||||||
isProxyGroup,
|
isProxyGroup,
|
||||||
|
proxyIPv6SupportMap,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user