add ping timeout option
This commit is contained in:
@@ -91,6 +91,7 @@ class WTVIRC {
|
|||||||
this.awaylen = this.irc_config.away_len || 200;
|
this.awaylen = this.irc_config.away_len || 200;
|
||||||
this.enable_tls = this.irc_config.enable_ssl || false;
|
this.enable_tls = this.irc_config.enable_ssl || false;
|
||||||
this.maxtargets = this.irc_config.max_targets || 4;
|
this.maxtargets = this.irc_config.max_targets || 4;
|
||||||
|
this.socket_timeout = this.irc_config.socket_timeout || 120000; // Default socket timeout to 120 seconds
|
||||||
this.server_hello = this.irc_config.server_hello || `zefIRCd v${this.version} IRC server powered by minisrv`;
|
this.server_hello = this.irc_config.server_hello || `zefIRCd v${this.version} IRC server powered by minisrv`;
|
||||||
this.enable_eval = this.debug || false; // Enable eval in debug mode only
|
this.enable_eval = this.debug || false; // Enable eval in debug mode only
|
||||||
this.serverId = this.irc_config.server_id || '00A'; // Default server ID, can be overridden in config
|
this.serverId = this.irc_config.server_id || '00A'; // Default server ID, can be overridden in config
|
||||||
@@ -138,6 +139,7 @@ class WTVIRC {
|
|||||||
}
|
}
|
||||||
this.server_start_time = this.getDate();
|
this.server_start_time = this.getDate();
|
||||||
this.server = net.createServer(async socket => {
|
this.server = net.createServer(async socket => {
|
||||||
|
socket.timeout = this.socket_timeout;
|
||||||
// Detect SSL handshake and wrap socket if needed
|
// Detect SSL handshake and wrap socket if needed
|
||||||
socket.once('data', async firstChunk => {
|
socket.once('data', async firstChunk => {
|
||||||
this.totalConnections++;
|
this.totalConnections++;
|
||||||
@@ -147,6 +149,10 @@ class WTVIRC {
|
|||||||
this.debugLog('error', `Socket error: ${err.message}`);
|
this.debugLog('error', `Socket error: ${err.message}`);
|
||||||
this.terminateSession(socket, true);
|
this.terminateSession(socket, true);
|
||||||
});
|
});
|
||||||
|
socket.on('timeout', () => {
|
||||||
|
this.debugLog('warn', `Socket timeout for ${socket.remoteAddress}`);
|
||||||
|
this.terminateSession(socket, true);
|
||||||
|
});
|
||||||
// Check if the first byte indicates SSL/TLS handshake (0x16 for TLS Handshake)
|
// Check if the first byte indicates SSL/TLS handshake (0x16 for TLS Handshake)
|
||||||
if (Buffer.isBuffer(firstChunk) ? firstChunk[0] === 0x16 : firstChunk.charCodeAt(0) === 0x16) {
|
if (Buffer.isBuffer(firstChunk) ? firstChunk[0] === 0x16 : firstChunk.charCodeAt(0) === 0x16) {
|
||||||
if (!this.enable_tls) {
|
if (!this.enable_tls) {
|
||||||
@@ -265,11 +271,18 @@ class WTVIRC {
|
|||||||
socket.timestamp = this.getDate();
|
socket.timestamp = this.getDate();
|
||||||
socket.uniqueId = `${this.serverId}${this.generateUniqueId(socket)}`;
|
socket.uniqueId = `${this.serverId}${this.generateUniqueId(socket)}`;
|
||||||
}
|
}
|
||||||
|
socket.timeout = this.socket_timeout;
|
||||||
socket.secure = secure;
|
socket.secure = secure;
|
||||||
socket.upgrading_to_tls = false;
|
socket.upgrading_to_tls = false;
|
||||||
socket.error_count = 0;
|
socket.error_count = 0;
|
||||||
await this.doInitialHandshake(socket);
|
await this.doInitialHandshake(socket);
|
||||||
|
|
||||||
|
socket.on('timeout', () => {
|
||||||
|
this.debugLog('warn', `Socket timeout for ${socket.remoteAddress}`);
|
||||||
|
this.broadcastUser(socket.nickname, `:${socket.nickname}!${socket.username}@${socket.host} QUIT :Ping Timeout (${this.socket_timeout / 1000} seconds)\r\n`);
|
||||||
|
this.terminateSession(socket, true);
|
||||||
|
});
|
||||||
|
|
||||||
socket.on('data', async data => {
|
socket.on('data', async data => {
|
||||||
await this.processSocketData(socket, data);
|
await this.processSocketData(socket, data);
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user