ataraxia-local
Advanced tools
Comparing version 0.3.2 to 0.4.0
30
index.js
@@ -9,2 +9,4 @@ 'use strict'; | ||
const eos = require('end-of-stream'); | ||
/** | ||
@@ -25,6 +27,9 @@ * Machine local transport. Uses Unix sockets to connect to peers on the | ||
const connect = () => { | ||
this.leader = leader(id); | ||
this.leader.on('leader', () => { | ||
this.leader = false; | ||
this.net = leader(id); | ||
this.net.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.leader = true; | ||
this.events.emit('leader'); | ||
@@ -39,9 +44,19 @@ }); | ||
this.leader.on('connection', handlePeer); | ||
this.leader.on('client', handlePeer); | ||
this.leader.on('error', err => { | ||
this.net.on('connection', handlePeer); | ||
this.net.on('client', sock => { | ||
if(this.leader) { | ||
eos(sock, err => { | ||
if(err) { | ||
this.debug('Closed with error;', err); | ||
} | ||
}); | ||
} else { | ||
handlePeer(sock); | ||
} | ||
}); | ||
this.net.on('error', err => { | ||
this.debug('Trouble connecting to machine local network;', err); | ||
try { | ||
this.leader.close(); | ||
this.net.close(); | ||
} catch(ex) { | ||
@@ -63,3 +78,3 @@ // Do nothing | ||
stop() { | ||
this.leader.close(); | ||
this.net.close(); | ||
@@ -74,3 +89,4 @@ super.stop(); | ||
// Disconnect does nothing for local transport | ||
this.handleDisconnect(); | ||
} | ||
} |
{ | ||
"name": "ataraxia-local", | ||
"version": "0.3.2", | ||
"version": "0.4.0", | ||
"description": "Machine-local transport for Ataraxia P2P messaging", | ||
@@ -9,6 +9,10 @@ "main": "index.js", | ||
"dependencies": { | ||
"ataraxia": "^0.3.2", | ||
"ataraxia": "^0.4.0", | ||
"debug": "^3.1.0", | ||
"end-of-stream": "^1.4.0", | ||
"unix-socket-leader": "^0.1.2" | ||
}, | ||
"devDependencies": { | ||
"trace": "^3.0.0" | ||
} | ||
} |
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
3851
4
1
4
83
+ Addedend-of-stream@^1.4.0
+ Addedataraxia@0.4.4(transitive)
- Removedataraxia@0.3.2(transitive)
Updatedataraxia@^0.4.0