Added socket buffer flooding detection
This commit is contained in:
parent
d38b332f81
commit
d5fdc519e5
@ -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');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -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){
|
||||
|
||||
Loading…
Reference in New Issue
Block a user