npm install resilient-swarm
ResilientSwarm is an efficient, secure, and reliable WebRTC swarm. The
goal is to not rely on any single point of failure and to resist
hostile networks.
The goal is also to be performant when some peers have poor network conditions by using the closest peer as a relay similar to how Skype's "Super Nodes."
Any peer can connect to the swarm given the public key of any node in the network.
let node1 = new Swarm()
let node2 = new Swarm()
let node3 = new Swarm()
// This will print 6 times, as each peer connects to both other peers.
node1.on('peer', peer => console.log('peer1 got', peer.publicKey))
node2.on('peer', peer => console.log('peer2 got', peer.publicKey))
node3.on('peer', peer => console.log('peer3 got', peer.publicKey))
node1.call(node2.publicKey) // connect peers 1 and 2 together
node3.call(node1.publicKey) // connect peers 3 and 1 together
// This will end up connecting all three
// nodes together even though only two
// call each other through signal exchange.
Swarm instance generates an ECDH public/private keypair for its node.
SimplePeer) the data channel is
multiplexed. The substeams are keyed with a type.db is a pouchdb database replication stream. Once established
bi-directional replication is setup between each node's internal pouchdb
instance.dnode is an rpc steam for communication between peers using dnode.relay Used to proxy data from one peer to another when the intermediate
peer has better connectivity. The publicKey used to setup a
Cipher stream so that the relaying node cannot read the traffic.