ataraxia-local
Advanced tools
Comparing version 0.3.0 to 0.3.2
43
index.js
@@ -22,16 +22,37 @@ 'use strict'; | ||
const id = path.join(os.tmpdir(), options.name + ''); | ||
this.leader = leader(id); | ||
this.leader.on('leader', () => { | ||
// Emit an event when this node becomes the leader | ||
this.events.emit('leader'); | ||
}); | ||
const handlePeer = sock => { | ||
const peer = new LocalPeer(this); | ||
peer.setSocket(sock); | ||
this.addPeer(peer); | ||
const connect = () => { | ||
this.leader = leader(id); | ||
this.leader.on('leader', () => { | ||
// Emit an event when this node becomes the leader | ||
this.debug('This node is now the leader of the machine local network'); | ||
this.events.emit('leader'); | ||
}); | ||
const handlePeer = sock => { | ||
const peer = new LocalPeer(this); | ||
peer.setSocket(sock); | ||
this.addPeer(peer); | ||
}; | ||
this.leader.on('connection', handlePeer); | ||
this.leader.on('client', handlePeer); | ||
this.leader.on('error', err => { | ||
this.debug('Trouble connecting to machine local network;', err); | ||
try { | ||
this.leader.close(); | ||
} catch(ex) { | ||
// Do nothing | ||
} | ||
if(this.started) { | ||
const delay = Math.floor(50 * Math.random() + 100); | ||
this.debug('Retrying connection in ' + delay + 'ms'); | ||
setTimeout(connect, delay); | ||
} | ||
}); | ||
}; | ||
this.leader.on('connection', handlePeer); | ||
this.leader.on('client', handlePeer); | ||
connect(); | ||
} | ||
@@ -38,0 +59,0 @@ |
{ | ||
"name": "ataraxia-local", | ||
"version": "0.3.0", | ||
"version": "0.3.2", | ||
"description": "Machine-local transport for Ataraxia P2P messaging", | ||
@@ -9,3 +9,3 @@ "main": "index.js", | ||
"dependencies": { | ||
"ataraxia": "^0.3.0", | ||
"ataraxia": "^0.3.2", | ||
"debug": "^3.1.0", | ||
@@ -12,0 +12,0 @@ "unix-socket-leader": "^0.1.2" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5049
123
Updatedataraxia@^0.3.2