1.0.0-beta.119 • Published 3 years ago

@dxos/discovery-swarm-memory v1.0.0-beta.119

Weekly downloads
-
License
GPL-3.0
Repository
github
Last release
3 years ago

DXOS Discovery Swarm Memory

Description

A minimal implementation of the discovery-swarm to simulate and test multiple connections in memory.

Usage

Example

import swarm from '@dxos/discovery-swarm-memory';

const sw = swarm();

sw.listen(1000)
sw.join('ubuntu-14.04') // can be any id/name/hash

sw.on('connection', function (connection) {
  console.log('found + connected to peer')
})

API

var sw = swarm(opts)

Create a new swarm. Options include:

{
  id: crypto.randomBytes(32), // peer-id for user
  stream: stream // stream to replicate across peers
}

sw.join(key, [opts], [cb])

Join a channel specified by key (usually a name, hash or id, must be a Buffer or a string). After joining will immediately search for peers advertising this key.

sw.leave(key)

Leave the channel specified key

sw.on('connection', function(connection, info) { ... })

Emitted when you have fully connected to another peer. Info is an object that contains info about the connection.

info

{
  initiator: true, // whether we initiated the connection or someone else did.
  channel: Buffer('...'), // the channel this connection was initiated on. only set if initiator === true.
  id: Buffer('...') // the remote peer's peer-id.
}

sw.on('connection-closed', function(connection, info) { ... })

Emitted when you've disconnected from a peer. Info is an object that contains info about the connection.

sw.listen(port)

Listen on a specific port. Should be called before join

1.0.0-beta.119

3 years ago

1.0.0-beta.116

3 years ago

1.0.0-beta.117

3 years ago

1.0.0-beta.115

3 years ago

1.0.0-beta.113

4 years ago

1.0.0-beta.112

4 years ago

1.0.0-beta.111

4 years ago

1.0.0-beta.109

4 years ago

1.0.0-beta.110

4 years ago

1.0.0-beta.108

4 years ago

1.0.0-beta.107

4 years ago

1.0.0-beta.106

4 years ago

1.0.0-beta.105

4 years ago

1.0.0-beta.104

4 years ago

1.0.0-beta.103

4 years ago

1.0.0-beta.102

4 years ago