feat(rust-core): add adaptive keepalive telemetry, MTU handling, and per-client rate limiting APIs
This commit is contained in:
@@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@push.rocks/smartvpn',
|
||||
version: '1.0.3',
|
||||
version: '1.1.0',
|
||||
description: 'A VPN solution with TypeScript control plane and Rust data plane daemon'
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import type {
|
||||
IVpnClientConfig,
|
||||
IVpnStatus,
|
||||
IVpnStatistics,
|
||||
IVpnConnectionQuality,
|
||||
IVpnMtuInfo,
|
||||
TVpnClientCommands,
|
||||
} from './smartvpn.interfaces.js';
|
||||
|
||||
@@ -65,12 +67,26 @@ export class VpnClient extends plugins.events.EventEmitter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get traffic statistics.
|
||||
* Get traffic statistics (includes connection quality when connected).
|
||||
*/
|
||||
public async getStatistics(): Promise<IVpnStatistics> {
|
||||
return this.bridge.sendCommand('getStatistics', {} as Record<string, never>);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get connection quality metrics (RTT, jitter, loss, link health).
|
||||
*/
|
||||
public async getConnectionQuality(): Promise<IVpnConnectionQuality> {
|
||||
return this.bridge.sendCommand('getConnectionQuality', {} as Record<string, never>);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get MTU information (overhead, effective MTU, oversized packet stats).
|
||||
*/
|
||||
public async getMtuInfo(): Promise<IVpnMtuInfo> {
|
||||
return this.bridge.sendCommand('getMtuInfo', {} as Record<string, never>);
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the daemon bridge.
|
||||
*/
|
||||
|
||||
@@ -7,6 +7,7 @@ import type {
|
||||
IVpnServerStatistics,
|
||||
IVpnClientInfo,
|
||||
IVpnKeypair,
|
||||
IVpnClientTelemetry,
|
||||
TVpnServerCommands,
|
||||
} from './smartvpn.interfaces.js';
|
||||
|
||||
@@ -91,6 +92,35 @@ export class VpnServer extends plugins.events.EventEmitter {
|
||||
return this.bridge.sendCommand('generateKeypair', {} as Record<string, never>);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set rate limit for a specific client.
|
||||
*/
|
||||
public async setClientRateLimit(
|
||||
clientId: string,
|
||||
rateBytesPerSec: number,
|
||||
burstBytes: number,
|
||||
): Promise<void> {
|
||||
await this.bridge.sendCommand('setClientRateLimit', {
|
||||
clientId,
|
||||
rateBytesPerSec,
|
||||
burstBytes,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove rate limit for a specific client (unlimited).
|
||||
*/
|
||||
public async removeClientRateLimit(clientId: string): Promise<void> {
|
||||
await this.bridge.sendCommand('removeClientRateLimit', { clientId });
|
||||
}
|
||||
|
||||
/**
|
||||
* Get telemetry for a specific client.
|
||||
*/
|
||||
public async getClientTelemetry(clientId: string): Promise<IVpnClientTelemetry> {
|
||||
return this.bridge.sendCommand('getClientTelemetry', { clientId });
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the daemon bridge.
|
||||
*/
|
||||
|
||||
@@ -64,6 +64,10 @@ export interface IVpnServerConfig {
|
||||
keepaliveIntervalSecs?: number;
|
||||
/** Enable NAT/masquerade for client traffic */
|
||||
enableNat?: boolean;
|
||||
/** Default rate limit for new clients (bytes/sec). Omit for unlimited. */
|
||||
defaultRateLimitBytesPerSec?: number;
|
||||
/** Default burst size for new clients (bytes). Omit for unlimited. */
|
||||
defaultBurstBytes?: number;
|
||||
}
|
||||
|
||||
export interface IVpnServerOptions {
|
||||
@@ -99,6 +103,7 @@ export interface IVpnStatistics {
|
||||
keepalivesSent: number;
|
||||
keepalivesReceived: number;
|
||||
uptimeSeconds: number;
|
||||
quality?: IVpnConnectionQuality;
|
||||
}
|
||||
|
||||
export interface IVpnClientInfo {
|
||||
@@ -107,6 +112,12 @@ export interface IVpnClientInfo {
|
||||
connectedSince: string;
|
||||
bytesSent: number;
|
||||
bytesReceived: number;
|
||||
packetsDropped: number;
|
||||
bytesDropped: number;
|
||||
lastKeepaliveAt?: string;
|
||||
keepalivesReceived: number;
|
||||
rateLimitBytesPerSec?: number;
|
||||
burstBytes?: number;
|
||||
}
|
||||
|
||||
export interface IVpnServerStatistics extends IVpnStatistics {
|
||||
@@ -119,6 +130,53 @@ export interface IVpnKeypair {
|
||||
privateKey: string;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// QoS: Connection quality
|
||||
// ============================================================================
|
||||
|
||||
export type TVpnLinkHealth = 'healthy' | 'degraded' | 'critical';
|
||||
|
||||
export interface IVpnConnectionQuality {
|
||||
srttMs: number;
|
||||
jitterMs: number;
|
||||
minRttMs: number;
|
||||
maxRttMs: number;
|
||||
lossRatio: number;
|
||||
consecutiveTimeouts: number;
|
||||
linkHealth: TVpnLinkHealth;
|
||||
currentKeepaliveIntervalSecs: number;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// QoS: MTU info
|
||||
// ============================================================================
|
||||
|
||||
export interface IVpnMtuInfo {
|
||||
tunMtu: number;
|
||||
effectiveMtu: number;
|
||||
linkMtu: number;
|
||||
overheadBytes: number;
|
||||
oversizedPacketsDropped: number;
|
||||
icmpTooBigSent: number;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// QoS: Client telemetry (server-side per-client)
|
||||
// ============================================================================
|
||||
|
||||
export interface IVpnClientTelemetry {
|
||||
clientId: string;
|
||||
assignedIp: string;
|
||||
lastKeepaliveAt?: string;
|
||||
keepalivesReceived: number;
|
||||
packetsDropped: number;
|
||||
bytesDropped: number;
|
||||
bytesReceived: number;
|
||||
bytesSent: number;
|
||||
rateLimitBytesPerSec?: number;
|
||||
burstBytes?: number;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// IPC Command maps (used by smartrust RustBridge<TCommands>)
|
||||
// ============================================================================
|
||||
@@ -128,6 +186,8 @@ export type TVpnClientCommands = {
|
||||
disconnect: { params: Record<string, never>; result: void };
|
||||
getStatus: { params: Record<string, never>; result: IVpnStatus };
|
||||
getStatistics: { params: Record<string, never>; result: IVpnStatistics };
|
||||
getConnectionQuality: { params: Record<string, never>; result: IVpnConnectionQuality };
|
||||
getMtuInfo: { params: Record<string, never>; result: IVpnMtuInfo };
|
||||
};
|
||||
|
||||
export type TVpnServerCommands = {
|
||||
@@ -138,6 +198,9 @@ export type TVpnServerCommands = {
|
||||
listClients: { params: Record<string, never>; result: { clients: IVpnClientInfo[] } };
|
||||
disconnectClient: { params: { clientId: string }; result: void };
|
||||
generateKeypair: { params: Record<string, never>; result: IVpnKeypair };
|
||||
setClientRateLimit: { params: { clientId: string; rateBytesPerSec: number; burstBytes: number }; result: void };
|
||||
removeClientRateLimit: { params: { clientId: string }; result: void };
|
||||
getClientTelemetry: { params: { clientId: string }; result: IVpnClientTelemetry };
|
||||
};
|
||||
|
||||
// ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user