update
This commit is contained in:
@ -453,6 +453,44 @@ export class SessionManager implements ISessionManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace socket mapping for STARTTLS upgrades
|
||||
* @param oldSocket - Original plain socket
|
||||
* @param newSocket - New TLS socket
|
||||
* @returns Whether the replacement was successful
|
||||
*/
|
||||
public replaceSocket(oldSocket: plugins.net.Socket | plugins.tls.TLSSocket, newSocket: plugins.net.Socket | plugins.tls.TLSSocket): boolean {
|
||||
const socketKey = this.socketIds.get(oldSocket);
|
||||
if (!socketKey) {
|
||||
SmtpLogger.warn('Cannot replace socket - original socket not found in session manager');
|
||||
return false;
|
||||
}
|
||||
|
||||
const session = this.sessions.get(socketKey);
|
||||
if (!session) {
|
||||
SmtpLogger.warn('Cannot replace socket - session not found for socket key');
|
||||
return false;
|
||||
}
|
||||
|
||||
// Remove old socket mapping
|
||||
this.socketIds.delete(oldSocket);
|
||||
|
||||
// Add new socket mapping
|
||||
this.socketIds.set(newSocket, socketKey);
|
||||
|
||||
// Set socket timeout for new socket
|
||||
newSocket.setTimeout(this.options.socketTimeout);
|
||||
|
||||
SmtpLogger.info(`Socket replaced for session ${session.id} (STARTTLS upgrade)`, {
|
||||
sessionId: session.id,
|
||||
remoteAddress: session.remoteAddress,
|
||||
oldSocketType: oldSocket.constructor.name,
|
||||
newSocketType: newSocket.constructor.name
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a unique key for a socket
|
||||
* @param socket - Client socket
|
||||
@ -462,4 +500,23 @@ export class SessionManager implements ISessionManager {
|
||||
const details = getSocketDetails(socket);
|
||||
return `${details.remoteAddress}:${details.remotePort}-${Date.now()}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clean up resources
|
||||
*/
|
||||
public destroy(): void {
|
||||
// Clear the cleanup timer
|
||||
if (this.cleanupTimer) {
|
||||
clearInterval(this.cleanupTimer);
|
||||
this.cleanupTimer = null;
|
||||
}
|
||||
|
||||
// Clear all sessions
|
||||
this.clearAllSessions();
|
||||
|
||||
// Clear event listeners
|
||||
this.eventListeners = {};
|
||||
|
||||
SmtpLogger.debug('SessionManager destroyed');
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user