🎈 perf: ts type

This commit is contained in:
m1m1sha 2024-05-08 18:58:17 +08:00
parent c3df9ea7fa
commit da0777293f
4 changed files with 105 additions and 20 deletions

View File

@ -1,4 +1,6 @@
<script setup lang="ts">
import type { NodeInfo } from '~/types/network'
const props = defineProps<{
instanceId?: string
}>()
@ -92,7 +94,7 @@ function lossRate(info: any) {
const myNodeInfo = computed(() => {
if (!curNetworkInst.value)
return {}
return {} as NodeInfo
return curNetworkInst.value.detail?.my_node_info
})
@ -233,7 +235,7 @@ onUnmounted(() => {
})
const dialogVisible = ref(false)
const dialogContent = ref('')
const dialogContent = ref<any>('')
function showVpnPortalConfig() {
const my_node_info = myNodeInfo.value

View File

@ -1,22 +1,18 @@
import { invoke } from '@tauri-apps/api/tauri'
import type { NetworkConfig } from '~/types/network'
import type { NetworkConfig, NetworkInstanceRunningInfo } from '~/types/network'
export async function parseNetworkConfig(cfg: NetworkConfig): Promise<string> {
const ret: string = await invoke('parse_network_config', { cfg: JSON.stringify(cfg) })
return ret
return await invoke('parse_network_config', { cfg: JSON.stringify(cfg) })
}
export async function runNetworkInstance(cfg: NetworkConfig) {
const ret: string = await invoke('run_network_instance', { cfg: JSON.stringify(cfg) })
return ret
export async function runNetworkInstance(cfg: NetworkConfig): Promise<string> {
return await invoke<string>('run_network_instance', { cfg: JSON.stringify(cfg) })
}
export async function retainNetworkInstance(instanceIds: Array<string>) {
const ret: string = await invoke('retain_network_instance', { instanceIds: JSON.stringify(instanceIds) })
return ret
export async function retainNetworkInstance(instanceIds: string[]): Promise<string> {
return await invoke<string>('retain_network_instance', { instanceIds: JSON.stringify(instanceIds) })
}
export async function collectNetworkInfos() {
const ret: string = await invoke('collect_network_infos', {})
return JSON.parse(ret)
export async function collectNetworkInfos(): Promise<Record<string, NetworkInstanceRunningInfo>> {
return JSON.parse(await invoke<string>('collect_network_infos'))
}

View File

@ -1,4 +1,4 @@
import type { NetworkConfig, NetworkInstance } from '~/types/network'
import type { NetworkConfig, NetworkInstance, NetworkInstanceRunningInfo } from '~/types/network'
import { DEFAULT_NETWORK_CONFIG } from '~/types/network'
export const useNetworkStore = defineStore('networkStore', {
@ -13,7 +13,7 @@ export const useNetworkStore = defineStore('networkStore', {
// uuid -> instance
instances: {} as Record<string, NetworkInstance>,
networkInfos: {} as Record<string, any>,
networkInfos: {} as Record<string, NetworkInstanceRunningInfo>,
}
},
@ -56,18 +56,18 @@ export const useNetworkStore = defineStore('networkStore', {
instance_id: instanceId,
running: false,
error_msg: '',
detail: {},
detail: {} as NetworkInstanceRunningInfo,
}
},
updateWithNetworkInfos(networkInfos: Record<string, any>) {
updateWithNetworkInfos(networkInfos: Record<string, NetworkInstanceRunningInfo>) {
this.networkInfos = networkInfos
for (const [instanceId, info] of Object.entries(networkInfos)) {
if (this.instances[instanceId] === undefined)
this.addNetworkInstance(instanceId)
this.instances[instanceId].running = info.running
this.instances[instanceId].error_msg = info.error_msg
this.instances[instanceId].error_msg = info.error_msg || ''
this.instances[instanceId].detail = info
}
},

View File

@ -68,5 +68,92 @@ export interface NetworkInstance {
running: boolean
error_msg: string
detail: any
detail: NetworkInstanceRunningInfo
}
export interface NetworkInstanceRunningInfo {
my_node_info: NodeInfo
events: Record<string, any>
node_info: NodeInfo
routes: Route[]
peers: PeerInfo[]
peer_route_pairs: PeerRoutePair[]
running: boolean
error_msg?: string
}
export interface NodeInfo {
virtual_ipv4: string
ips: {
public_ipv4: string
interface_ipv4s: string[]
public_ipv6: string
interface_ipv6s: string[]
listeners: {
serialization: string
scheme_end: number
username_end: number
host_start: number
host_end: number
host: any
port?: number
path_start: number
query_start?: number
fragment_start?: number
}[]
}
stun_info: StunInfo
listeners: string[]
vpn_portal_cfg?: string
}
export interface StunInfo {
udp_nat_type: number
tcp_nat_type: number
last_update_time: number
}
export interface Route {
peer_id: number
ipv4_addr: string
next_hop_peer_id: number
cost: number
proxy_cidrs: string[]
hostname: string
stun_info?: StunInfo
inst_id: string
}
export interface PeerInfo {
peer_id: number
conns: PeerConnInfo[]
}
export interface PeerConnInfo {
conn_id: string
my_peer_id: number
peer_id: number
features: string[]
tunnel?: TunnelInfo
stats?: PeerConnStats
loss_rate: number
}
export interface PeerRoutePair {
route: Route
peer?: PeerInfo
}
export interface TunnelInfo {
tunnel_type: string
local_addr: string
remote_addr: string
}
export interface PeerConnStats {
rx_bytes: number
tx_bytes: number
rx_packets: number
tx_packets: number
latency_us: number
}