This commit is contained in:
Juergen Kunz
2025-07-22 10:35:39 +00:00
parent b6d8b73599
commit a459d77b6f
7 changed files with 362 additions and 52 deletions

View File

@@ -5,6 +5,7 @@ import { connectionLogDeduplicator } from '../../core/utils/log-deduplicator.js'
import { LifecycleComponent } from '../../core/utils/lifecycle-component.js';
import { cleanupSocket } from '../../core/utils/socket-utils.js';
import { WrappedSocket } from '../../core/models/wrapped-socket.js';
import { ProtocolDetector } from '../../detection/index.js';
import type { SmartProxy } from './smart-proxy.js';
/**
@@ -323,6 +324,18 @@ export class ConnectionManager extends LifecycleComponent {
this.smartProxy.metricsCollector.removeConnection(record.id);
}
// Clean up protocol detection fragments
const context = ProtocolDetector.createConnectionContext({
sourceIp: record.remoteIP,
sourcePort: record.incoming?.remotePort || 0,
destIp: record.incoming?.localAddress || '',
destPort: record.localPort,
socketId: record.id
});
// Clean up any pending detection fragments for this connection
ProtocolDetector.cleanupConnection(context);
if (record.cleanupTimer) {
clearTimeout(record.cleanupTimer);
record.cleanupTimer = undefined;

View File

@@ -303,18 +303,18 @@ export class RouteConnectionHandler {
// Handler for processing initial data (after potential PROXY protocol)
const processInitialData = async (chunk: Buffer) => {
// Use ProtocolDetector to identify protocol
const connectionId = ProtocolDetector.createConnectionId({
// Create connection context for protocol detection
const context = ProtocolDetector.createConnectionContext({
sourceIp: record.remoteIP,
sourcePort: socket.remotePort,
destIp: socket.localAddress,
destPort: socket.localPort,
sourcePort: socket.remotePort || 0,
destIp: socket.localAddress || '',
destPort: socket.localPort || 0,
socketId: record.id
});
const detectionResult = await ProtocolDetector.detectWithConnectionTracking(
const detectionResult = await ProtocolDetector.detectWithContext(
chunk,
connectionId,
context,
{ extractFullHeaders: false } // Only extract essential info for routing
);