Skip to content

Commit

Permalink
feat: add support for IPv6 check
Browse files Browse the repository at this point in the history
feat: w
  • Loading branch information
arkxfly committed Oct 21, 2023
1 parent f5509c0 commit c3a3318
Show file tree
Hide file tree
Showing 8 changed files with 125 additions and 19 deletions.
15 changes: 15 additions & 0 deletions src/components/IPv6Support.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Show, createMemo } from 'solid-js'
import { useProxies } from '~/signals'

export const IPv6Support = (props: { name?: string }) => {
const { proxyIPv6SupportMap } = useProxies()
const support = createMemo(() => proxyIPv6SupportMap()[props.name!] === true)

return (
<Show when={support()}>
<span class="badge badge-sm p-px">
<span class="scale-75">IPv6</span>
</span>
</Show>
)
}
12 changes: 12 additions & 0 deletions src/components/ProxiesSettingsModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
setProxiesOrderingType,
setProxiesPreviewType,
setUrlForLatencyTest,
setUrlIPv6SupportTest,
urlForIPv6SupportTest,
urlForLatencyTest,
} from '~/signals'

Expand Down Expand Up @@ -68,6 +70,16 @@ export const ProxiesSettingsModal: Component<{
/>
</div>

<div class="flex flex-col">
<ConfigTitle withDivider>{t('urlForIPv6SupportTest')}</ConfigTitle>

<input
class="input input-bordered w-full"
value={urlForIPv6SupportTest()}
onChange={(e) => setUrlIPv6SupportTest(e.target.value?.trim())}
/>
</div>

<div>
<ConfigTitle withDivider>{t('proxiesSorting')}</ConfigTitle>

Expand Down
37 changes: 20 additions & 17 deletions src/components/ProxyNodeCard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { IconBrandSpeedtest } from '@tabler/icons-solidjs'
import { createMemo, Show } from 'solid-js'
import { twMerge } from 'tailwind-merge'
import { Button, Latency } from '~/components'
import { Button, IPv6Support, Latency } from '~/components'
import { filterSpecialProxyType, formatProxyType } from '~/helpers'
import { useProxies } from '~/signals'

Expand Down Expand Up @@ -36,23 +36,26 @@ export const ProxyNodeCard = (props: {
<div class="flex items-center justify-between gap-2">
<span class="text-left text-sm">{proxyName}</span>

<Button
class="btn-circle btn-ghost h-auto min-h-0 w-auto"
icon={
<IconBrandSpeedtest
size={20}
class={twMerge(
proxyLatencyTestingMap()[proxyName] &&
'animate-pulse text-success',
)}
/>
}
onClick={(e) => {
e.stopPropagation()
<span class="flex items-center gap-1">
<IPv6Support name={props.proxyName} />
<Button
class="btn-circle btn-ghost h-auto min-h-0 w-auto"
icon={
<IconBrandSpeedtest
size={20}
class={twMerge(
proxyLatencyTestingMap()[proxyName] &&
'animate-pulse text-success',
)}
/>
}
onClick={(e) => {
e.stopPropagation()

void proxyLatencyTest(proxyName, proxyNode().provider)
}}
/>
void proxyLatencyTest(proxyName, proxyNode().provider)
}}
/>
</span>
</div>

<div class="flex items-center justify-between gap-1">
Expand Down
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export * from './ConfigTitle'
export * from './ConnectionsSettingsModal'
export * from './ConnectionsTableDetailsModal'
export * from './Header'
export * from './IPv6Support'
export * from './Latency'
export * from './LogoText'
export * from './LogsSettingsModal'
Expand Down
1 change: 1 addition & 0 deletions src/i18n/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default {
auto: 'Auto',
off: 'Off',
proxiesPreviewType: 'Proxies preview type',
urlForIPv6SupportTest: 'url for IPv6 support test',
urlForLatencyTest: 'URL for latency test',
autoCloseConns: 'Automatically Close connections',
useTwemoji: 'Use Twemoji Mozilla Font',
Expand Down
1 change: 1 addition & 0 deletions src/i18n/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default {
auto: '自适应',
off: '关闭',
proxiesPreviewType: '节点组预览样式',
urlForIPv6SupportTest: 'IPv6 支持测试链接',
urlForLatencyTest: '测速链接',
autoCloseConns: '自动断开连接',
useTwemoji: '使用 Twemoji Mozilla 字体',
Expand Down
6 changes: 6 additions & 0 deletions src/signals/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ export const [urlForLatencyTest, setUrlForLatencyTest] = makePersisted(
createSignal('https://www.gstatic.com/generate_204'),
{ name: 'urlForLatencyTest', storage: localStorage },
)

export const [urlForIPv6SupportTest, setUrlIPv6SupportTest] = makePersisted(
createSignal('https://api-ipv6.ip.sb/ip'),
{ name: 'urlForIPv6SupportTest', storage: localStorage },
)

export const [autoCloseConns, setAutoCloseConns] = makePersisted(
createSignal(false),
{ name: 'autoCloseConns', storage: localStorage },
Expand Down
71 changes: 69 additions & 2 deletions src/signals/proxies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
latencyTestTimeoutDuration,
latestConnectionMsg,
restructRawMsgToConnection,
urlForIPv6SupportTest,
urlForLatencyTest,
} from '~/signals'
import type { Proxy, ProxyNode, ProxyProvider } from '~/types'
Expand Down Expand Up @@ -56,6 +57,9 @@ const [proxyProviders, setProxyProviders] = createSignal<
>([])

const [latencyMap, setLatencyMap] = createSignal<Record<string, number>>({})
const [proxyIPv6SupportMap, setProxyIPv6SupportMap] = createSignal<
Record<string, boolean>
>({})
const [proxyNodeMap, setProxyNodeMap] = createSignal<Record<string, ProxyInfo>>(
{},
)
Expand All @@ -65,20 +69,29 @@ const setProxiesInfo = (
) => {
const newProxyNodeMap = { ...proxyNodeMap() }
const newLatencyMap = { ...latencyMap() }
const newProxyIPv6SupportMap = { ...proxyIPv6SupportMap() }

proxies.forEach((proxy) => {
const { udp, xudp, type, now, name, provider = '' } = proxy

const latency =
proxy.history.at(-1)?.delay || latencyQualityMap().NOT_CONNECTED

const urlForIPv6Support = urlForIPv6SupportTest()
const proxyIPv6Support =
((
proxy.extra?.[urlForIPv6Support] as Array<{ delay: number }> | undefined
)?.at(-1)?.delay ?? 0) > 0

newProxyNodeMap[proxy.name] = { udp, xudp, type, now, name, provider }
newLatencyMap[proxy.name] = latency
newProxyIPv6SupportMap[proxy.name] = proxyIPv6Support
})

batch(() => {
setProxyNodeMap(newProxyNodeMap)
setLatencyMap(newLatencyMap)
setProxyIPv6SupportMap(newProxyIPv6SupportMap)
})
}

Expand Down Expand Up @@ -144,7 +157,56 @@ export const useProxies = () => {
}
}

const proxyLatencyTest = (proxyName: string, provider: string) =>
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 > 0
} catch {
support = false
}
setProxyIPv6SupportMap((supportMap) => ({
...supportMap,
[proxyName]: support,
}))
}
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 > 0]),
)
setProxyIPv6SupportMap((supportMap) => ({
...supportMap,
...newSupportMap,
}))
}

const proxyLatencyTest = async (proxyName: string, provider: string) => {
setProxyLatencyTestingMap(proxyName, async () => {
const { delay } = await proxyLatencyTestAPI(
proxyName,
Expand All @@ -158,8 +220,10 @@ export const useProxies = () => {
[proxyName]: delay,
}))
})
await proxyIPv6SupportTest(proxyName, provider)
}

const proxyGroupLatencyTest = (proxyGroupName: string) =>
const proxyGroupLatencyTest = async (proxyGroupName: string) => {
setProxyGroupLatencyTestingMap(proxyGroupName, async () => {
const newLatencyMap = await proxyGroupLatencyTestAPI(
proxyGroupName,
Expand All @@ -174,6 +238,8 @@ export const useProxies = () => {

await fetchProxies()
})
await proxyGroupIPv6SupportTest(proxyGroupName)
}

const updateProviderByProviderName = (providerName: string) =>
setUpdatingMap(providerName, async () => {
Expand Down Expand Up @@ -206,6 +272,7 @@ export const useProxies = () => {
return {
collapsedMap,
setCollapsedMap,
proxyIPv6SupportMap,
proxyLatencyTestingMap,
proxyGroupLatencyTestingMap,
proxyProviderLatencyTestingMap,
Expand Down

0 comments on commit c3a3318

Please sign in to comment.