5.0.0 • Published 3 years ago
multiserver-dht v5.0.0
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 unlesskeys
is present), a string identifying the channel to be used as address.keys
(REQUIRED unlesskey
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: 8007id
a string identifying this specific DHT peer. Default: something random
Returns a multiserver plugin.
5.0.0
3 years ago
4.4.0
5 years ago
4.3.0
5 years ago
5.0.0-rc.3
5 years ago
5.0.0-rc.2
5 years ago
4.2.0
5 years ago
4.1.1
5 years ago
4.1.0
5 years ago
5.0.0-rc.1
6 years ago
4.0.0
6 years ago
3.3.1
6 years ago
3.3.0
6 years ago
3.2.0
6 years ago
3.1.0
6 years ago
3.0.0
6 years ago
2.4.0
6 years ago
2.3.1
6 years ago
2.3.0
6 years ago
2.2.0
6 years ago
2.1.2
6 years ago
2.1.1
6 years ago
2.1.0
6 years ago
2.0.0
6 years ago
1.0.2
6 years ago
1.0.1
6 years ago
1.0.0
6 years ago