feat(remoteingress): add remote ingress performance configuration and expose tunnel transport metrics

This commit is contained in:
2026-04-26 12:14:51 +00:00
parent 49ce265d7e
commit ec5374900c
14 changed files with 194 additions and 18 deletions
+1 -1
View File
@@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@serve.zone/dcrouter',
version: '13.21.1',
version: '13.22.0',
description: 'A multifaceted routing service handling mail and SMS delivery functions.'
}
+15 -3
View File
@@ -178,6 +178,8 @@ export interface IDcRouterOptions {
certPath?: string;
keyPath?: string;
};
/** Performance profile and limits for remote ingress hub/edge tunnels. */
performance?: import('../ts_interfaces/data/remoteingress.js').IRemoteIngressPerformanceConfig;
};
/**
@@ -570,12 +572,16 @@ export class DcRouter {
this.referenceResolver,
// Sync routes to RemoteIngressManager whenever routes change,
// then push updated derived ports to the Rust hub binary
(routes) => {
async (routes) => {
if (this.remoteIngressManager) {
this.remoteIngressManager.setRoutes(routes as any[]);
}
if (this.tunnelManager) {
this.tunnelManager.syncAllowedEdges();
try {
await this.tunnelManager.syncAllowedEdges();
} catch (err: unknown) {
logger.log('error', `Failed to sync Remote Ingress allowed edges: ${(err as Error).message}`);
}
}
},
undefined,
@@ -1120,7 +1126,12 @@ export class DcRouter {
// to SmartProxy with PROXY protocol v1 headers to preserve client IPs.
if (this.options.remoteIngressConfig?.enabled) {
smartProxyConfig.acceptProxyProtocol = true;
smartProxyConfig.proxyIPs = ['127.0.0.1'];
if (!smartProxyConfig.proxyIPs) {
smartProxyConfig.proxyIPs = [];
}
if (!smartProxyConfig.proxyIPs.includes('127.0.0.1')) {
smartProxyConfig.proxyIPs.push('127.0.0.1');
}
}
// VPN uses socket mode with PP v2 — SmartProxy must accept proxy protocol from localhost
@@ -2270,6 +2281,7 @@ export class DcRouter {
tunnelPort: riCfg.tunnelPort ?? 8443,
targetHost: '127.0.0.1',
tls: tlsConfig,
performance: riCfg.performance,
});
await this.tunnelManager.start();
+2 -2
View File
@@ -59,7 +59,7 @@ export class RouteConfigManager {
private getHttp3Config?: () => IHttp3Config | undefined,
private getVpnClientIpsForRoute?: (route: IDcRouterRouteConfig, routeId?: string) => TIpAllowEntry[],
private referenceResolver?: ReferenceResolver,
private onRoutesApplied?: (routes: plugins.smartproxy.IRouteConfig[]) => void,
private onRoutesApplied?: (routes: plugins.smartproxy.IRouteConfig[]) => void | Promise<void>,
private getRuntimeRoutes?: () => plugins.smartproxy.IRouteConfig[],
private hydrateStoredRoute?: (storedRoute: IRoute) => plugins.smartproxy.IRouteConfig | undefined,
) {}
@@ -540,7 +540,7 @@ export class RouteConfigManager {
// Notify listeners (e.g. RemoteIngressManager) of the route set
if (this.onRoutesApplied) {
this.onRoutesApplied(enabledRoutes);
await this.onRoutesApplied(enabledRoutes);
}
logger.log('info', `Applied ${enabledRoutes.length} routes to SmartProxy (${this.routes.size} total)`);
+1
View File
@@ -206,6 +206,7 @@ export class ConfigHandler {
hubDomain: riCfg?.hubDomain || null,
tlsMode,
connectedEdgeIps,
performance: riCfg?.performance,
};
return {
@@ -29,6 +29,7 @@ export class RemoteIngressHandler {
...e,
secret: '********', // Never expose secrets via API
effectiveListenPorts: manager.getEffectiveListenPorts(e),
effectiveListenPortsUdp: manager.getEffectiveListenPortsUdp(e),
manualPorts: breakdown.manual,
derivedPorts: breakdown.derived,
};
@@ -133,6 +134,7 @@ export class RemoteIngressHandler {
...edge,
secret: '********',
effectiveListenPorts: manager.getEffectiveListenPorts(edge),
effectiveListenPortsUdp: manager.getEffectiveListenPortsUdp(edge),
manualPorts: breakdown.manual,
derivedPorts: breakdown.derived,
},
+25 -5
View File
@@ -9,6 +9,7 @@ export interface ITunnelManagerConfig {
certPem?: string;
keyPem?: string;
};
performance?: import('../../ts_interfaces/data/remoteingress.js').IRemoteIngressPerformanceConfig;
}
/**
@@ -20,6 +21,7 @@ export class TunnelManager {
private config: ITunnelManagerConfig;
private edgeStatuses: Map<string, IRemoteIngressStatus> = new Map();
private reconcileInterval: ReturnType<typeof setInterval> | null = null;
private syncChain: Promise<void> = Promise.resolve();
constructor(manager: RemoteIngressManager, config: ITunnelManagerConfig = {}) {
this.manager = manager;
@@ -66,7 +68,8 @@ export class TunnelManager {
tunnelPort: this.config.tunnelPort ?? 8443,
targetHost: this.config.targetHost ?? '127.0.0.1',
tls: this.config.tls,
});
...(this.config.performance ? { performance: this.config.performance } : {}),
} as any);
// Send allowed edges to the hub
await this.syncAllowedEdges();
@@ -107,20 +110,23 @@ export class TunnelManager {
if (existing) {
existing.activeTunnels = rustEdge.activeStreams;
existing.lastHeartbeat = Date.now();
this.applyRustStatus(existing, rustEdge);
// Update peer address if available from Rust hub
if (rustEdge.peerAddr) {
existing.publicIp = rustEdge.peerAddr;
}
} else {
// Missed edgeConnected event — add entry
this.edgeStatuses.set(rustEdge.edgeId, {
const status: IRemoteIngressStatus = {
edgeId: rustEdge.edgeId,
connected: true,
publicIp: rustEdge.peerAddr || null,
activeTunnels: rustEdge.activeStreams,
lastHeartbeat: Date.now(),
connectedAt: rustEdge.connectedAt * 1000,
});
};
this.applyRustStatus(status, rustEdge);
this.edgeStatuses.set(rustEdge.edgeId, status);
}
}
@@ -137,8 +143,22 @@ export class TunnelManager {
* Call this after creating/deleting/updating edges.
*/
public async syncAllowedEdges(): Promise<void> {
const edges = this.manager.getAllowedEdges();
await this.hub.updateAllowedEdges(edges);
const run = this.syncChain.catch(() => {}).then(async () => {
const edges = this.manager.getAllowedEdges();
await this.hub.updateAllowedEdges(edges as any);
});
this.syncChain = run;
await run;
}
private applyRustStatus(status: IRemoteIngressStatus, rustEdge: any): void {
status.transportMode = rustEdge.transportMode;
status.fallbackUsed = rustEdge.fallbackUsed;
status.performance = rustEdge.performance;
status.flowControl = rustEdge.flowControl;
status.queues = rustEdge.queues;
status.traffic = rustEdge.traffic;
status.udp = rustEdge.udp;
}
/**