Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ataraxia-local

Package Overview
Dependencies
Maintainers
1
Versions
29
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ataraxia-local - npm Package Compare versions

Comparing version 0.5.2 to 0.6.0

5

example.js

@@ -8,3 +8,2 @@ 'use strict';

net.addTransport(new LocalTransport());
net.start();

@@ -19,1 +18,5 @@ net.on('node:available', node => {

});
net.start()
.then(() => console.log('Network has started'))
.catch(err => console.error(err));

84

index.js

@@ -6,4 +6,4 @@ 'use strict';

const leader = require('unix-socket-leader');
const { AbstractTransport, Peer } = require('ataraxia/transport');
const { LowLevelNetwork } = require('local-machine-network');
const { AbstractTransport, StreamingPeer, addPeer, events } = require('ataraxia/transport');

@@ -19,31 +19,19 @@ const eos = require('end-of-stream');

super('local');
this.leader = false;
}
start(options) {
super.start(options);
return super.start(options)
.then(started => {
if(! started) return false;
const id = path.join(os.tmpdir(), options.name + '');
const id = path.join(os.tmpdir(), options.name + '');
const connect = () => {
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');
});
const handlePeer = sock => {
const peer = new LocalPeer(this);
peer.setSocket(sock);
peer.negotiate();
this.addPeer(peer);
};
this.net.on('connection', handlePeer);
this.net.on('client', sock => {
if(this.leader) {
eos(sock, err => {
this.net = new LowLevelNetwork({
path: id
});
this.net.on('leader', serverSocket => {
// Emit an event when this node becomes the leader
eos(serverSocket, err => {
if(err) {

@@ -53,30 +41,30 @@ 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.net.close();
} catch(ex) {
// Do nothing
}
this.debug('This node is now the leader of the machine local network');
this[events].emit('leader');
});
if(this.started) {
const delay = Math.floor(50 * Math.random() + 100);
this.debug('Retrying connection in ' + delay + 'ms');
setTimeout(connect, delay);
}
});
};
const handlePeer = sock => {
const peer = new LocalPeer(this);
peer.setSocket(sock);
peer.negotiate();
this[addPeer](peer);
};
connect();
this.net.on('connection', handlePeer);
this.net.on('connected', handlePeer);
return this.net.connect();
})
.then(() => true);
}
stop() {
this.net.close();
return super.stop()
.then(stopped => {
if(! stopped) return false;
super.stop();
return this.net.disconnect();
})
.then(() => true);
}

@@ -86,3 +74,3 @@ };

class LocalPeer extends Peer {
class LocalPeer extends StreamingPeer {
disconnect() {

@@ -89,0 +77,0 @@ // Disconnect does nothing for local transport

{
"name": "ataraxia-local",
"version": "0.5.2",
"version": "0.6.0",
"description": "Machine-local transport for Ataraxia P2P messaging",

@@ -9,6 +9,6 @@ "main": "index.js",

"dependencies": {
"ataraxia": "^0.5.2",
"ataraxia": "^0.6.0",
"debug": "^3.1.0",
"end-of-stream": "^1.4.0",
"unix-socket-leader": "^0.1.2"
"end-of-stream": "^1.4.1",
"local-machine-network": "^0.1.0"
},

@@ -15,0 +15,0 @@ "devDependencies": {

# ataraxia-local
[![npm version](https://badge.fury.io/js/ataraxia-local.svg)](https://badge.fury.io/js/ataraxia-local)
[![Dependencies](https://david-dm.org/aholstenson/ataraxia-local.svg)](https://david-dm.org/aholstenson/ataraxia-local)
Machine-local transport for [Ataraxia](https://github.com/aholstenson/ataraxia).

@@ -21,3 +24,6 @@ This transport connects together instances on the same machine via a Unix

net.addTransport(new LocalTransport());
net.start();
net.start()
.then(...)
.catch(...);
```

@@ -45,3 +51,6 @@

net.addTransport(local);
net.start();
net.start()
.then(...)
.catch(...);
```
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc