mirror of
https://github.com/MetaCubeX/metacubexd.git
synced 2024-11-24 09:45:35 +08:00
chores for proxy latency check (#290)
* chore: update compatibility * chore: fix proxy related type declarations * chore: update latency test timeout
This commit is contained in:
parent
ce3065e22e
commit
173e2e228b
@ -131,9 +131,11 @@ export const updateProxyProviderAPI = (providerName: string) => {
|
|||||||
export const proxyProviderHealthCheckAPI = (providerName: string) => {
|
export const proxyProviderHealthCheckAPI = (providerName: string) => {
|
||||||
const request = useRequest()
|
const request = useRequest()
|
||||||
|
|
||||||
return request.get(`providers/proxies/${providerName}/healthcheck`, {
|
return request
|
||||||
timeout: 20 * 1000,
|
.get(`providers/proxies/${providerName}/healthcheck`, {
|
||||||
|
timeout: 5 * 1000,
|
||||||
})
|
})
|
||||||
|
.json<Record<string, number>>()
|
||||||
}
|
}
|
||||||
|
|
||||||
export const selectProxyInGroupAPI = (groupName: string, proxyName: string) => {
|
export const selectProxyInGroupAPI = (groupName: string, proxyName: string) => {
|
||||||
@ -148,11 +150,18 @@ export const selectProxyInGroupAPI = (groupName: string, proxyName: string) => {
|
|||||||
|
|
||||||
export const proxyLatencyTestAPI = (
|
export const proxyLatencyTestAPI = (
|
||||||
proxyName: string,
|
proxyName: string,
|
||||||
|
provider: string,
|
||||||
url: string,
|
url: string,
|
||||||
timeout: number,
|
timeout: number,
|
||||||
) => {
|
) => {
|
||||||
const request = useRequest()
|
const request = useRequest()
|
||||||
|
|
||||||
|
if (provider !== '') {
|
||||||
|
return proxyProviderHealthCheckAPI(provider).then((latencyMap) => ({
|
||||||
|
delay: latencyMap[proxyName],
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
return request
|
return request
|
||||||
.get(`proxies/${proxyName}/delay`, {
|
.get(`proxies/${proxyName}/delay`, {
|
||||||
searchParams: {
|
searchParams: {
|
||||||
|
@ -49,7 +49,7 @@ export const ProxyNodeCard = (props: {
|
|||||||
onClick={(e) => {
|
onClick={(e) => {
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
|
|
||||||
void proxyLatencyTest(proxyName)
|
void proxyLatencyTest(proxyName, proxyNode().provider)
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
@ -127,7 +127,7 @@ export const tableSizeClassName = (size: TAILWINDCSS_SIZE) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const [latencyTestTimeoutDuration, setLatencyTestTimeoutDuration] =
|
export const [latencyTestTimeoutDuration, setLatencyTestTimeoutDuration] =
|
||||||
makePersisted(createSignal(2000), {
|
makePersisted(createSignal(5000), {
|
||||||
name: 'latencyTestTimeoutDuration',
|
name: 'latencyTestTimeoutDuration',
|
||||||
storage: localStorage,
|
storage: localStorage,
|
||||||
})
|
})
|
||||||
|
@ -26,8 +26,12 @@ type ProxyInfo = {
|
|||||||
now: string
|
now: string
|
||||||
xudp: boolean
|
xudp: boolean
|
||||||
type: string
|
type: string
|
||||||
|
provider: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ProxyWithProvider = Proxy & { provider?: string }
|
||||||
|
export type ProxyNodeWithProvider = ProxyNode & { provider?: string }
|
||||||
|
|
||||||
const { map: collapsedMap, set: setCollapsedMap } = useStringBooleanMap()
|
const { map: collapsedMap, set: setCollapsedMap } = useStringBooleanMap()
|
||||||
const {
|
const {
|
||||||
map: proxyLatencyTestingMap,
|
map: proxyLatencyTestingMap,
|
||||||
@ -46,29 +50,29 @@ const { map: updatingMap, setWithCallback: setUpdatingMap } =
|
|||||||
const [isAllProviderUpdating, setIsAllProviderUpdating] = createSignal(false)
|
const [isAllProviderUpdating, setIsAllProviderUpdating] = createSignal(false)
|
||||||
|
|
||||||
// these signals should be global state
|
// these signals should be global state
|
||||||
const [proxies, setProxies] = createSignal<Proxy[]>([])
|
const [proxies, setProxies] = createSignal<ProxyWithProvider[]>([])
|
||||||
const [proxyProviders, setProxyProviders] = createSignal<ProxyProvider[]>([])
|
const [proxyProviders, setProxyProviders] = createSignal<
|
||||||
|
(ProxyProvider & { proxies: ProxyNodeWithProvider[] })[]
|
||||||
|
>([])
|
||||||
|
|
||||||
const [latencyMap, setLatencyMap] = createSignal<Record<string, number>>({})
|
const [latencyMap, setLatencyMap] = createSignal<Record<string, number>>({})
|
||||||
const [proxyNodeMap, setProxyNodeMap] = createSignal<Record<string, ProxyInfo>>(
|
const [proxyNodeMap, setProxyNodeMap] = createSignal<Record<string, ProxyInfo>>(
|
||||||
{},
|
{},
|
||||||
)
|
)
|
||||||
|
|
||||||
const setProxiesInfo = (proxies: (Proxy | ProxyNode)[]) => {
|
const setProxiesInfo = (
|
||||||
|
proxies: (ProxyWithProvider | ProxyNodeWithProvider)[],
|
||||||
|
) => {
|
||||||
const newProxyNodeMap = { ...proxyNodeMap() }
|
const newProxyNodeMap = { ...proxyNodeMap() }
|
||||||
const newLatencyMap = { ...latencyMap() }
|
const newLatencyMap = { ...latencyMap() }
|
||||||
|
|
||||||
proxies.forEach((proxy) => {
|
proxies.forEach((proxy) => {
|
||||||
|
const { udp, xudp, type, now, name, provider = '' } = proxy
|
||||||
|
|
||||||
const latency =
|
const latency =
|
||||||
proxy.history.at(-1)?.delay || latencyQualityMap().NOT_CONNECTED
|
proxy.history.at(-1)?.delay || latencyQualityMap().NOT_CONNECTED
|
||||||
|
|
||||||
newProxyNodeMap[proxy.name] = {
|
newProxyNodeMap[proxy.name] = { udp, xudp, type, now, name, provider }
|
||||||
udp: proxy.udp,
|
|
||||||
xudp: proxy.xudp,
|
|
||||||
type: proxy.type,
|
|
||||||
now: proxy.now,
|
|
||||||
name: proxy.name,
|
|
||||||
}
|
|
||||||
newLatencyMap[proxy.name] = latency
|
newLatencyMap[proxy.name] = latency
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -96,9 +100,17 @@ export const useProxies = () => {
|
|||||||
(provider) =>
|
(provider) =>
|
||||||
provider.name !== 'default' && provider.vehicleType !== 'Compatible',
|
provider.name !== 'default' && provider.vehicleType !== 'Compatible',
|
||||||
)
|
)
|
||||||
const allProxies: (Proxy | ProxyNode)[] = [
|
|
||||||
|
const allProxies = [
|
||||||
...Object.values(proxies),
|
...Object.values(proxies),
|
||||||
...sortedProviders.flatMap((provider) => provider.proxies),
|
...sortedProviders.flatMap((provider) =>
|
||||||
|
provider.proxies
|
||||||
|
.filter((proxy) => !(proxy.name in proxies))
|
||||||
|
.map((proxy) => ({
|
||||||
|
...proxy,
|
||||||
|
provider: provider.name,
|
||||||
|
})),
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
batch(() => {
|
batch(() => {
|
||||||
@ -132,10 +144,11 @@ export const useProxies = () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const proxyLatencyTest = (proxyName: string) =>
|
const proxyLatencyTest = (proxyName: string, provider: string) =>
|
||||||
setProxyLatencyTestingMap(proxyName, async () => {
|
setProxyLatencyTestingMap(proxyName, async () => {
|
||||||
const { delay } = await proxyLatencyTestAPI(
|
const { delay } = await proxyLatencyTestAPI(
|
||||||
proxyName,
|
proxyName,
|
||||||
|
provider,
|
||||||
urlForLatencyTest(),
|
urlForLatencyTest(),
|
||||||
latencyTestTimeoutDuration(),
|
latencyTestTimeoutDuration(),
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user