Socket
Socket
Sign inDemoInstall

multiserver-dht

Package Overview
Dependencies
122
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    multiserver-dht

A multiserver plugin that uses a Distributed Hash Table


Version published
Weekly downloads
4
decreased by-20%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

multiserver-dht

A multiserver plugin that uses a Distributed Hash Table and channel keys as addresses

npm install --save multiserver-dht

This module is a multiserver plugin that joins a Distributed Hash Table (DHT) and uses channel keys as "addresses" where peers communicate as clients and as servers.

Usage

As client:

var pull = require('pull-stream');
var Pushable = require('pull-pushable');
var MultiServer = require('multiserver');
var Dht = require('multiserver-dht');

var ms = MultiServer([Dht({ key: 'japan' })]);

ms.client('dht:japan', function(err, stream) {
  var pushable = Pushable();
  pull(
    pushable,
    stream,
    pull.drain(x => {
      console.log(buf.toString('utf-8'));
      // ALICE
      // BOB
    }),
  );
  pushable.push('alice');
  pushable.push('bob');
});

As server:

var pull = require('pull-stream');
var MultiServer = require('multiserver');
var Dht = require('multiserver-dht');

var ms = MultiServer([Dht({ key: 'japan' })]);

ms.server(function(stream) {
  pull(
    stream,
    pull.map(buf => buf.toString('utf-8')),
    pull.map(s => s.toUpperCase()),
    pull.map(str => Buffer.from(str, 'utf-8')),
    stream,
  );
});

API

Dht(opts)

Joins a global Distributed Hash Table on the Internet under the channel opts.key as the address. The opts may include:

  • key (REQUIRED unless keys is present), a string identifying the channel to be used as address.
  • keys (REQUIRED unless key is present), a pull-stream of arrays of strings that identify all the channels where servers are hosted.
  • port, the port on which to listen for connections in the DHT. Default: 8007
  • id a string identifying this specific DHT peer. Default: something random

Returns a multiserver plugin.

FAQs

Last updated on 27 Jan 2021

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc