1.0.0-beta.119 • Published 3 years ago

@dxos/hyperswarm-network-memory v1.0.0-beta.119

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

DXOS Hyperswarm Network Memory

Description

A minimal implementation of the hyperswarm-network to simulate and test multiple connections in memory.

Usage

Example

import network from '@dxos/hyperswarm-network-memory';

const net = network();

net.join(Buffer.from('someTopic'));

net.leave(Buffer.from('someTopic'));

net.on('connection', (connection, details) => {});
net.on('disconnection', (connection, details) => {});

API

net = new Network()

It creates a new Network instance. Each peer should have a Network instance.

net.join(topic)

Join the swarm for the given topic. This will cause peers to be discovered for the topic. Connections will automatically be created to those peers ('connection' event).

Parameters:

  • topic. Buffer. The identifier of the peer-group to list under.

net.leave(topic)

Leave the swarm for the given topic.

Parameters:

  • topic. Buffer. The identifier of the peer-group to list under.

net.on('connection', (socket, details) => {})

A new connection has been created. You should handle this event by using the socket.

  • socket. DuplexStreamMock. The established TCP connection representation.
  • details. Object describing the connection.
  • type. String. Should be either 'tcp' or 'utp'.
  • client. Boolean. If true, the connection was initiated by this node.
  • peer. Object describing the peer. Will be null if client === false.
    • topic. Buffer. The identifier which this peer was discovered under.

net.on('disconnection', (socket, details) => {})

Detect a disconnection from a peer.

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.112

4 years ago

1.0.0-beta.113

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