mirror of
https://github.com/EasyTier/EasyTier.git
synced 2026-08-06 20:49:46 +00:00
a7ab60e0e4
Android previously treated setTunFd as a single-instance update, and the VpnService plugin could only expose one IPv4 address. That made shared TUN members disable each other or leave only one address configured. Group enabled Android TUN instances by shared dev_name, send the fd to every compatible member, and only disable incompatible TUN users. Build the Android VPN request from the whole running shared group and pass every IPv4 address to VpnService. The shared mobile dispatcher now owns current fd device state on a process-level runtime. New setTunFd calls replace that state even when the raw fd number is reused, and mobile TUN read/write/create failures rebuild with backoff while preserving member registrations. Protect shared member cleanup with per-registration ownership tokens, so old async cleanup cannot unregister a recreated member or remove its source claims. Mobile source addresses are registered in the dispatcher without applying OS ifcfg changes, so Android-originated packets return through the owning instance. When one shared member stops while another remains, notify the frontend to recalculate the VpnService config instead of leaving stale addresses and routes. Serialize Android VpnService config recalculation so stale async events cannot overwrite newer shared-group state. If one shared member is not ready, rebuild from the healthy members and retry the missing member later. If no healthy member remains, stop the Android VPN service instead of keeping stale routes active.
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import { invoke } from '@tauri-apps/api/core'
|
|
|
|
export async function ping(value: string): Promise<string | null> {
|
|
return await invoke<{ value?: string }>('plugin:vpnservice|ping', {
|
|
payload: {
|
|
value,
|
|
},
|
|
}).then((r) => (r.value ? r.value : null));
|
|
}
|
|
|
|
export interface InvokeResponse {
|
|
errorMsg?: string;
|
|
granted?: boolean;
|
|
}
|
|
|
|
export interface StartVpnRequest {
|
|
ipv4Addr?: string;
|
|
ipv4Addrs?: string[];
|
|
routes?: string[];
|
|
dns?: string;
|
|
disallowedApplications?: string[];
|
|
mtu?: number;
|
|
}
|
|
|
|
export interface VpnStatusResponse {
|
|
running: boolean;
|
|
ipv4Addr?: string;
|
|
ipv4Addrs?: string[];
|
|
routes?: string[];
|
|
dns?: string;
|
|
}
|
|
|
|
export async function prepare_vpn(): Promise<InvokeResponse | null> {
|
|
return await invoke<InvokeResponse>('plugin:vpnservice|prepare_vpn', {})
|
|
}
|
|
|
|
export async function start_vpn(request: StartVpnRequest): Promise<InvokeResponse | null> {
|
|
return await invoke<InvokeResponse>('plugin:vpnservice|start_vpn', {
|
|
...request,
|
|
})
|
|
}
|
|
|
|
export async function stop_vpn(): Promise<InvokeResponse | null> {
|
|
return await invoke<InvokeResponse>('plugin:vpnservice|stop_vpn', {})
|
|
}
|
|
|
|
export async function get_vpn_status(): Promise<VpnStatusResponse | null> {
|
|
return await invoke<VpnStatusResponse>('plugin:vpnservice|get_vpn_status', {})
|
|
}
|