Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
worker.prototype.connect = function Connect(callback) {
var self = this;
this.connection = new nssocket.NsSocket();
this.connection.on('error', function(e) {
self._connected = false;
self.connection.destroy();
// Any callbacks expecting result will be called with error
for(var callback_id in self.CALLBACKS) {
self.CALLBACKS[callback_id].call(self, e, null);
delete self.CALLBACKS[callback_id];
}
self.emit('disconnect');
setTimeout(function() {
self.connect();
}, 100);
});
this.connection.connect(this.config.port, this.config.host, function() {
self._connected = true;
Bind.call(self);
async function _connect() {
let socket = new nssocket.NsSocket();
socket.connect(6785);
return new Promise(function(resolve, reject) {
log.trace("Attempting to connect to the hub's heartbeat port");
async function onClose(err) {
// When a container is starting up and hasn't yet internally
// started listening on a port, Docker trolls us by accepting the
// connection, but then immediately closing the connection.
// So, if it was closed with no error, just try again.
if (!err) {
await timeout(50);
resolve(_connect());
}
}
function sendAction(proc, next) {
var socket = new nssocket.NsSocket();
function onMessage(data) {
//
// Cleanup the socket.
//
socket.undata([action, 'ok'], onMessage);
socket.undata([action, 'error'], onMessage);
socket.end();
//
// Messages are only sent back from error cases. The event
// calling context is available from `nssocket`.
//
var message = data && data.message,
type = this.event.slice().pop();
function Node(port) {
events.EventEmitter.call(this);
this.nsclient = new nssocket.NsSocket();
this.nodes = {};
this.sortedIds = [];
var thisNode = this;
this.nsclient.data('id', function (id) {
this.id = id;
getPublicIP(function (ip) {
if (ip) {
this.nsclient.send('ip', ip, port);
}
else {
this.nsclient.send('ip');
}
}.bind(this));
}.bind(this));
Node.prototype.addPeer = function(address, port) {
this.logger.trace('Trying to add peer at "'+address+':'+port+'"')
var socket = new nssocket.NsSocket();
socket.on('error', function(e) {
this.logger.error('An error occured while establishing connection to new peer at "'+address+':'+port+'"', e)
}.bind(this))
socket.connect(port, address, function() {
this.logger.trace('sending handshake to "'+address+':'+port+'"')
socket.send(['smoke', 'handshake'], {id: this.id})
socket.data(['smoke', 'handshake ack'], this.onHandshakeAck.bind(this, socket))
}.bind(this))
}
var NsSocket = exports.Nssocket = function (options) {
options = options || {};
this.name = 'nssocket';
this.logEvent = options.logEvent || ['log'];
this.socket = new nssocket.NsSocket(options.socket || {
reconnect: true
});
this.socket.connect(options.host, options.port);
};
function sendAction(proc, next) {
var socket = new nssocket.NsSocket();
socket.connect(proc.socket, function (err) {
if (err) {
next(err);
}
socket.dataOnce([action, 'ok'], function (data) {
next();
socket.end();
});
socket.send([action]);
});
socket.on('error', function (err) {
next(err);
this.options.seeds.forEach(function(seed) {
if(seed.port == this.options.port && seed.address == this.options.address) return this.logger.info('I seem to be a seed')
this.logger.info('Trying to enter network through seed "'+seed.address+':'+seed.port+'"')
var socket = new nssocket.NsSocket();
socket.on('error', function(e) {
this.logger.error('An error occured while trying to enter netork through seed "'+seed.address+':'+seed.port+'"', e)
}.bind(this))
socket.connect(seed.port, seed.address, function() {
socket.send(['smoke', 'peer request'], {
id: this.id
, remoteAddress: this.options.address
, remotePort: this.options.port
})
}.bind(this))
}.bind(this))
}