flâneur

holepunchto/hyperswarm: A distributed networking stack for connecting peers. ·

github.com · 1,137 words · saved by 1 readers

Start discovering and connecting to peers sharing a common topic. As new peers are connected to, they will be emitted from the swarm as connection events. topic must be a 32-byte Buffer opts can include: Returns a PeerDiscovery object. In Hyperswarm, there are two ways for peers to join the swarm: client mode and server mode. If you've previously used Hyperswarm v2, these were called "lookup" and "announce", but we now think "client" and "server" are more descriptive. When you join a topic as a server, the swarm will start accepting incoming connections from clients (peers that have joined the same topic in client mode). Server mode will announce your keypair to the DHT, so that other peers can discover your server. When server connections are emitted, they are not associated with a specific topic -- the server only knows it received an incoming connection. When you join a topic as a client, the swarm will do a query to discover available servers, and will eagerly connect to them. As w

See the full API docs at docs.pears.com A high-level API for finding and connecting to peers who are interested in a "topic." Installation npm install hyperswarm Usage const Hyperswarm = require('hyperswarm') const swarm = new Hyperswarm() swarm1.on('connection', (conn) => { // swarm1 will receive server connections conn.write('this is a server connection') conn.end() }) const discoveryKey = Buffer.alloc(32).fill('hello world') // must be 32 bytes // join the swarm, others will find you swarm2.join(discoveryKey, { server: true, client: true }) Hyperswarm API const swarm = new…

saved by

related reading