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

ataraxia

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ataraxia

P2P messaging over mesh networks

  • 0.7.2
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

ataraxia

npm version Dependencies

Mesh networking with peer-to-peer messaging for NodeJS. Ataraxia connects different NodeJS instances together and allows messages to be passed between these instances. Some instances may act as routers for other instances to create a mesh network.

For support for services with RPC and events see ataraxia-services.

Installation

npm install ataraxia

Also install one or more transports:

Example with TCP transport

const Network = require('ataraxia');
const TCPTransport = require('ataraxia-tcp');

const net = new Network({ name: 'name-of-your-app-or-network' });
net.addTransport(new TCPTransport());

net.on('node:available', node => {
  console.log('A new node is available:', node.id);
  node.send('hello');
});

net.on('message', msg => {
  console.log('A message was received', msg.type, 'with data', msg.data, 'from', msg.returnPath.id);
});

net.start()
  .then(...)
  .catch(...);

Example with machine-local transport and TCP transport

This example creates a network where instances on the same machine connect to each other locally first and then elects one instance to handle connections to other machines on the same network.

const Network = require('ataraxia');
const LocalTransport = require('ataraxia-local');
const TCPTransport = require('ataraxia-tcp');

const net = new Network({ name: 'name-of-your-app-or-network' });

const local = new LocalTransport();
local.on('leader', () => {
  /*
   * The leader event is emitted when this instance becomes the leader
   * of the machine-local network. This instance will now handle
   * connections to other machines in the network.
   */
  net.addTransport(new TCPTransport());
});
net.addTransport(local);

net.start()
  .then(...)
  .catch(...);

API

Network

  • new Network(options) - create a new network using the given options. Options may be:
    • name - Required. The name of the network, should be short and describe the app or library.
    • endpoint - Request that the local node is an endpoint that should not perform routing.
  • start() - start the network and its transports
  • stop() - stop the network and its transports
  • addTransport(transport) - add a transport that should be used
  • on('node:available', node => ...) - a node has been found and messages can now be sent and received to/from it
  • on('node:unavailable', node => ...) - a node is no longer available
  • on('message', ({ returnPath, type, data }) => ...) - a message has been received from a node

Node

  • id - get the id of the node
  • available - get if the node is reachable
  • on('unavailable', () => ...) - node is no longer available
  • send(type, data) - send a message of the given type with the specified data to the node
  • on('message', ({ returnPath, type, data }) => ...) - a message has been received from this node

Keywords

FAQs

Package last updated on 05 Dec 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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