diff --git a/lib/pool.js b/lib/pool.js index 030c468..5c08be0 100644 --- a/lib/pool.js +++ b/lib/pool.js @@ -268,6 +268,8 @@ var pool = module.exports = function pool(options, authorizeFn){ emitLog('client', "Client '"+client.workerName+"' disconnected!"); }).on('unknownStratumMethod', function(fullMessage) { emitLog('client', "Client '"+client.workerName+"' has sent us an unknown stratum method: "+fullMessage.method); + }).on('socketFlooded', function(){ + emitWarningLog('client', 'Detected socket flooding and purged buffer'); }); }); } diff --git a/lib/stratum.js b/lib/stratum.js index 377f48f..524b740 100644 --- a/lib/stratum.js +++ b/lib/stratum.js @@ -161,6 +161,11 @@ var StratumClient = function(options){ socket.setEncoding('utf8'); socket.on('data', function(d){ dataBuffer += d; + if (Buffer.byteLength(dataBuffer, 'utf8') > 1024){ + dataBuffer = ''; + _this.emit('socketFlooded'); + return; + } if (dataBuffer.slice(-1) === '\n'){ var messages = dataBuffer.split('\n'); messages.forEach(function(message){