You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 7, 2022. It is now read-only.
Run the following code in two different places and they will replicate the contents of the given ARCHIVE_KEY.
varhyperdrive=require('hyperdrive')varhypercore=require('hypercore')varDiscovery=require('hyperdiscovery')vararchive=hyperdrive('./database','ARCHIVE_KEY')vardiscovery=Discovery(archive)discovery.on('connection',function(peer,type){console.log('got',peer,type)console.log('connected to',discovery.connections,'peers')peer.on('close',function(){console.log('peer disconnected')})})// add another archive/feed latervarfeed=hypercore('./feed')discovery.add(feed)// adds this hypercore feed to the same discovery swarm
Will use discovery-swarm to attempt to connect peers. Uses dat-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:
Join the p2p swarm for the given feed. The return object, discovery, is an event emitter that will emit a peer event with the peer information when a peer is found.
discovery.add(archive, [opts])
Add an archive/feed to the discovery swarm. Options will be passed to discovery-swarm. If you pass opts.announce as a falsy value you don't announce your port (discover-only mode).
discovery.totalConnections
Get length of the list of total active connections, across all archives and feeds.
discovery.leave(discoveryKey)
Leave discovery for a specific discovery key.
discovery.rejoin(discoveryKey)
Rejoin discovery for a discovery key (*must be added first using discovery.add).
discovery.close()
Exit the swarm, close all replication streams.
Options
stream: function, replication stream for connection. Default is archive.replicate({live, upload, download}).
upload: bool, upload data to the other peer?
download: bool, download data from the other peer?
port: port for discovery swarm
utp: use utp in discovery swarm
tcp: use tcp in discovery swarm
bootstrap: [string], WebRTC bootstrap signal servers for web
discovery: string, discovery-swarm-stream server for web
Defaults from datland-swarm-defaults can also be overwritten: