@wirelineio/hyperswarm-network-memory

0.2.17 • Public • Published

Wireline Hyperswarm Network Memory

Description

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

Usage

Example

import network from '@wirelineio/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.

Readme

Keywords

none

Package Sidebar

Install

npm i @wirelineio/hyperswarm-network-memory

Weekly Downloads

2

Version

0.2.17

License

GPL-3.0

Unpacked Size

32.3 kB

Total Files

15

Last publish

Collaborators

  • dboreham
  • telackey
  • egorgripasov
  • richburdon
  • ashwinp