2015-09-23 19:14:29 +01:00
2015-09-21 19:56:42 +01:00
2015-09-23 19:14:29 +01:00
2015-09-23 19:14:29 +01:00
2015-09-14 12:06:19 +01:00
2015-07-08 15:59:25 -07:00
2015-09-23 17:11:32 +01:00
2015-09-21 16:46:04 +01:00

libp2p-swarm Node.js implementation

Build Status

libp2p swarm implementation in Node.js

Description

libp2p-swarm is connection abstraction that is able to leverage several transports and connection upgrades (such as congestion control, encrypt a channel, multiplex several streams in one connection, and more. It does this by bringing protocol multiplexing to the application level (instead of the traditional Port level) using multicodec and multistream.

libp2p-swarm is used by libp2p but it can be also used as a standalone module.

Usage

Install and create a Swarm

libp2p-swarm is available on npm and so, like any other npm module, just:

$ npm install libp2p-swarm --save

And use it on your Node.js code as:

var Swarm = require('libp2p-swarm')

var sw = new Swarm(peerInfoSelf)

peerInfoSelf is a PeerInfo object that represents the peer creating this swarm instance.

Support a transport

libp2p-swarm expects transports that implement abstract-transport. For example libp2p-tcp, a simple shim on top of the net module to make it work with swarm expectations.

sw.addTransport(transport, [options, dialOptions, listenOptions])

Add an connection upgrade

A connection upgrade must be able to receive and return something that implements the abstract-connection interface.

sw.addUpgrade(connUpgrade, [options])

Upgrading a connection to use a Stream Muxer is still considered a upgrade, but a special case since once this connection is applied, the returned obj will implement the abstract-stream-muxer interface.

sw.addStreamMuxer(streamMuxer, [options])

Dial to another peer

sw.dial(PeerInfo, options, protocol)
sw.dial(PeerInfo, options) 

dial uses the best transport (whatever works first, in the future we can have some criteria), and jump starts the connection until the point we have to negotiate the protocol. If a Muxer is available, then drop the muxer onto that connection. Good to warm up connections or to check for connectivity. If we have already a Muxer for that peerInfo, than do nothing.

Accept requests on a specific protocol

sw.handleProtocol(protocol, handlerFunction)
Description
No description provided
Readme 23 MiB
Languages
TypeScript 100%