Giter Site home page Giter Site logo

hyperdrive-archive-swarm's Introduction

hyperdrive-archive-swarm

Join a hyperdrive archive's & hypercore feed's p2p swarm in the client and server.

npm install hyperdrive-archive-swarm

Usage

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 key
  • wrtc: a webrtc instance, e.g. electron-webrtc, if not natively supported
  • 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

Defaults from datland-swarm-defaults can also be overwritten:

  • dns.server: DNS server
  • dns.domain: DNS domain
  • dht.bootstrap: distributed hash table bootstrapping nodes

hyperdrive-archive-swarm's People

Contributors

okdistribute avatar karissa avatar juliangruber avatar joehand avatar mafintosh avatar pfrazee avatar lukeburns avatar

Watchers

James Cloos avatar Mike Vegeto avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.