mirror of https://github.com/BTCPrivate/z-nomp.git
Blocknotify listener errors are logged and don't crash the system.
This commit is contained in:
parent
db99f49ec0
commit
abcf97d34f
|
@ -17,27 +17,34 @@ var listener = module.exports = function listener(options){
|
||||||
}
|
}
|
||||||
|
|
||||||
var blockNotifyServer = net.createServer(function(c) {
|
var blockNotifyServer = net.createServer(function(c) {
|
||||||
|
|
||||||
emitLog('Block listener has incoming connection');
|
emitLog('Block listener has incoming connection');
|
||||||
var data = '';
|
var data = '';
|
||||||
c.on('data', function(d){
|
try {
|
||||||
emitLog('Block listener received blocknotify data');
|
c.on('data', function (d) {
|
||||||
data += d;
|
emitLog('Block listener received blocknotify data');
|
||||||
if (data.slice(-1) === '\n'){
|
data += d;
|
||||||
c.end();
|
if (data.slice(-1) === '\n') {
|
||||||
}
|
c.end();
|
||||||
});
|
}
|
||||||
c.on('end', function() {
|
});
|
||||||
|
c.on('end', function () {
|
||||||
|
|
||||||
emitLog('Block listener connection ended');
|
emitLog('Block listener connection ended');
|
||||||
|
|
||||||
var message = JSON.parse(data);
|
var message = JSON.parse(data);
|
||||||
if (message.password === options.password){
|
if (message.password === options.password) {
|
||||||
_this.emit('hash', message);
|
_this.emit('hash', message);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
emitLog('Block listener received notification with incorrect password');
|
emitLog('Block listener received notification with incorrect password');
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch(e){
|
||||||
|
emitLog('Block listener failed to parse message ' + data);
|
||||||
|
}
|
||||||
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
blockNotifyServer.listen(options.port, function() {
|
blockNotifyServer.listen(options.port, function() {
|
||||||
emitLog('Block notify listener server started on port ' + options.port)
|
emitLog('Block notify listener server started on port ' + options.port)
|
||||||
|
|
Loading…
Reference in New Issue