Home Guides Protocol Install Awesome Hacks
Guides Modules Hyperswarm

Hyperswarm

API Docs https://github.com/hyperswarm/hyperswarm
Depends On nothing
Used By hyperspace, hyperbeam

While Hypercores can be replicated over any Node stream, most people want to share them over a peer-to-peer network. Hyperswarm is the DHT (Distributed Hash Table) we developed for discovering and connecting to other peers, primarily for P2P Hypercore replication.

It supports a distributed UDP hole-punching algorithm that makes it especially suitable for home networks.

const hyperswarm = require('hyperswarm')

const swarm = hyperswarm()
swarm.join(blake2s('my-hyperswarm-dkey'), {
lookup: true, // find & connect to peers
announce: true // optional- announce self as a connection target
})

swarm.on('connection', (socket, details) => {
console.log('new connection!', details)

// you can now use the socket as a stream, eg:
// process.stdin.pipe(socket).pipe(process.stdout)
})

Hyperswarm is often used to discover and share peers for Hypercore replication, but it can also be used for more general P2P applications. As an example, hyperbeam uses Hyperswarm to establish E2E-encrypted "pipes" between two peers.