hyperdrive-archive-swarm-browserify v4.1.6
hyperdrive-archive-swarm
Join a hyperdrive archive's & hypercore feed's p2p swarm in the client and server.
npm install hyperdrive-archive-swarmUsage
Run the following code in two different places and they will replicate the contents of the given ARCHIVE_KEY.
var hyperdrive = require('hyperdrive')
var memdb = require('memdb')
var swarm = require('hyperdrive-archive-swarm')
var drive = hyperdrive(memdb())
var archive = drive.createArchive('ARCHIVE_KEY')
var sw = swarm(archive)
sw.on('connection', function (peer, type) {
console.log('got', peer, type) // type is 'webrtc-swarm' or 'discovery-swarm'
console.log('connected to', sw.connections, 'peers')
peer.on('close', function () {
console.log('peer disconnected')
})
})Will use discovery-swarm, and webrtc-swarm whenever available to attempt to connect peers. Uses datland-swarm-defaults for peer introduction defaults on the server side, which can be overwritten (see below).
The module can also create and join a swarm for a hypercore feed:
var hypercore = require('hypercore')
var memdb = require('memdb')
var swarm = require('hyperdrive-archive-swarm')
var core = hypercore(memdb())
var feed = core.createFeed()
var sw = swarm(feed)API
var sw = swarm(archive, opts)
Join the p2p swarm for the given hyperdrive archive. The return object, sw, is an event emitter that will emit a peer event with the peer information when a peer is found.
Get number of currently active connections with sw.connections.
Options
signalhub: the url of the signalhub.signalhubPrefix: the prefix for the archive's signalhub keywrtc: a webrtc instance, e.g. electron-webrtc, if not natively supportedupload: bool, upload data to the other peer?download: bool, download data from the other peer?port: port for discovery swarmutp: use utp in discovery swarmtcp: use tcp in discovery swarm
Defaults from datland-swarm-defaults can also be overwritten:
dns.server: DNS serverdns.domain: DNS domaindht.bootstrap: distributed hash table bootstrapping nodes
9 years ago