Added socket buffer flooding detection

This commit is contained in:
Matthew Little 2014-01-17 14:21:18 -07:00
parent d38b332f81
commit d5fdc519e5
2 changed files with 7 additions and 0 deletions

View File

@ -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');
});
});
}

View File

@ -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){