initial
This commit is contained in:
166
ts/smartvpn.interfaces.ts
Normal file
166
ts/smartvpn.interfaces.ts
Normal file
@@ -0,0 +1,166 @@
|
||||
// ============================================================================
|
||||
// Transport options
|
||||
// ============================================================================
|
||||
|
||||
export interface IVpnTransportStdio {
|
||||
transport: 'stdio';
|
||||
}
|
||||
|
||||
export interface IVpnTransportSocket {
|
||||
transport: 'socket';
|
||||
socketPath: string;
|
||||
autoReconnect?: boolean;
|
||||
reconnectBaseDelayMs?: number;
|
||||
reconnectMaxDelayMs?: number;
|
||||
maxReconnectAttempts?: number;
|
||||
}
|
||||
|
||||
export type TVpnTransportOptions = IVpnTransportStdio | IVpnTransportSocket;
|
||||
|
||||
// ============================================================================
|
||||
// Client configuration
|
||||
// ============================================================================
|
||||
|
||||
export interface IVpnClientConfig {
|
||||
/** Server WebSocket URL, e.g. wss://vpn.example.com/tunnel */
|
||||
serverUrl: string;
|
||||
/** Server's static public key (base64) for Noise NK handshake */
|
||||
serverPublicKey: string;
|
||||
/** Optional DNS servers to use while connected */
|
||||
dns?: string[];
|
||||
/** Optional MTU for the TUN device */
|
||||
mtu?: number;
|
||||
/** Keepalive interval in seconds (default: 30) */
|
||||
keepaliveIntervalSecs?: number;
|
||||
}
|
||||
|
||||
export interface IVpnClientOptions {
|
||||
transport: TVpnTransportOptions;
|
||||
config?: IVpnClientConfig;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Server configuration
|
||||
// ============================================================================
|
||||
|
||||
export interface IVpnServerConfig {
|
||||
/** Listen address for WebSocket, e.g. 0.0.0.0:443 */
|
||||
listenAddr: string;
|
||||
/** TLS certificate PEM (optional — can be behind reverse proxy) */
|
||||
tlsCert?: string;
|
||||
/** TLS private key PEM */
|
||||
tlsKey?: string;
|
||||
/** Server's Noise static private key (base64) */
|
||||
privateKey: string;
|
||||
/** Server's Noise static public key (base64) */
|
||||
publicKey: string;
|
||||
/** IP subnet for VPN clients, e.g. 10.8.0.0/24 */
|
||||
subnet: string;
|
||||
/** DNS servers pushed to clients */
|
||||
dns?: string[];
|
||||
/** MTU for TUN device */
|
||||
mtu?: number;
|
||||
/** Keepalive interval in seconds (default: 30) */
|
||||
keepaliveIntervalSecs?: number;
|
||||
/** Enable NAT/masquerade for client traffic */
|
||||
enableNat?: boolean;
|
||||
}
|
||||
|
||||
export interface IVpnServerOptions {
|
||||
transport: TVpnTransportOptions;
|
||||
config?: IVpnServerConfig;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Status and statistics
|
||||
// ============================================================================
|
||||
|
||||
export type TVpnConnectionState =
|
||||
| 'disconnected'
|
||||
| 'connecting'
|
||||
| 'handshaking'
|
||||
| 'connected'
|
||||
| 'reconnecting'
|
||||
| 'error';
|
||||
|
||||
export interface IVpnStatus {
|
||||
state: TVpnConnectionState;
|
||||
assignedIp?: string;
|
||||
serverAddr?: string;
|
||||
connectedSince?: string;
|
||||
lastError?: string;
|
||||
}
|
||||
|
||||
export interface IVpnStatistics {
|
||||
bytesSent: number;
|
||||
bytesReceived: number;
|
||||
packetsSent: number;
|
||||
packetsReceived: number;
|
||||
keepalivesSent: number;
|
||||
keepalivesReceived: number;
|
||||
uptimeSeconds: number;
|
||||
}
|
||||
|
||||
export interface IVpnClientInfo {
|
||||
clientId: string;
|
||||
assignedIp: string;
|
||||
connectedSince: string;
|
||||
bytesSent: number;
|
||||
bytesReceived: number;
|
||||
}
|
||||
|
||||
export interface IVpnServerStatistics extends IVpnStatistics {
|
||||
activeClients: number;
|
||||
totalConnections: number;
|
||||
}
|
||||
|
||||
export interface IVpnKeypair {
|
||||
publicKey: string;
|
||||
privateKey: string;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// IPC Command maps (used by smartrust RustBridge<TCommands>)
|
||||
// ============================================================================
|
||||
|
||||
export type TVpnClientCommands = {
|
||||
connect: { params: { config: IVpnClientConfig }; result: { assignedIp: string } };
|
||||
disconnect: { params: Record<string, never>; result: void };
|
||||
getStatus: { params: Record<string, never>; result: IVpnStatus };
|
||||
getStatistics: { params: Record<string, never>; result: IVpnStatistics };
|
||||
};
|
||||
|
||||
export type TVpnServerCommands = {
|
||||
start: { params: { config: IVpnServerConfig }; result: void };
|
||||
stop: { params: Record<string, never>; result: void };
|
||||
getStatus: { params: Record<string, never>; result: IVpnStatus };
|
||||
getStatistics: { params: Record<string, never>; result: IVpnServerStatistics };
|
||||
listClients: { params: Record<string, never>; result: { clients: IVpnClientInfo[] } };
|
||||
disconnectClient: { params: { clientId: string }; result: void };
|
||||
generateKeypair: { params: Record<string, never>; result: IVpnKeypair };
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
// Installer
|
||||
// ============================================================================
|
||||
|
||||
export type TVpnPlatform = 'linux' | 'macos' | 'windows' | 'unknown';
|
||||
|
||||
export interface IVpnServiceUnit {
|
||||
platform: TVpnPlatform;
|
||||
content: string;
|
||||
installPath: string;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// Events emitted by VpnClient / VpnServer
|
||||
// ============================================================================
|
||||
|
||||
export interface IVpnEventMap {
|
||||
'status': IVpnStatus;
|
||||
'error': { message: string; code?: string };
|
||||
'client-connected': IVpnClientInfo;
|
||||
'client-disconnected': { clientId: string; reason?: string };
|
||||
'exit': { code: number | null; signal: string | null };
|
||||
'reconnected': void;
|
||||
}
|
||||
Reference in New Issue
Block a user