libp2p-websocket-star-multi

Allows to listen on multiple websocket-star-rendezvous servers while ignoring offline ones

No longer supported for js-libp2p0.27.0 or later
Last updated 6 years ago by mkg20001 .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install libp2p-websocket-star-multi 
SYNC missed versions from official npm registry.

libp2p-websocket-star

Build Status

Allows to listen on multiple websocket-star-rendezvous servers while ignoring offline ones

Description

libp2p-websocket-star-multi allows to listen on multiple websocket-star-rendezvous servers while ignoring offline ones

Note: This module uses pull-streams for all stream based interfaces.

Usage

Installation

> npm install libp2p-websocket-star

API

Example

'use strict'

const Libp2p = require('libp2p')
const Id = require('peer-id')
const Info = require('peer-info')
const multiaddr = require('multiaddr')
const pull = require('pull-stream')

const WSStarMulti = require('libp2p-websocket-star-multi')

Id.create((err, id) => {
  if (err) throw err

  const peerInfo = new Info(id)
  peerInfo.multiaddrs.add(multiaddr('/p2p-websocket-star')) // will get replaced to the multiaddr of the individual servers
  const ws = new WSStarMulti({
    servers: [ // servers are Multiaddr[]
      '/dnsaddr/ws-star-signal-1.servep2p.com/tcp/443/wss/p2p-websocket-star',
      '/dnsaddr/ws-star-signal-2.servep2p.com/tcp/443/wss/p2p-websocket-star',
      '/dnsaddr/ws-star-signal-3.servep2p.com/tcp/443/wss/p2p-websocket-star',
      '/dnsaddr/ws-star-signal-4.servep2p.com/tcp/443/wss/p2p-websocket-star',
      '/dnsaddr/ws-star.discovery.libp2p.io/tcp/443/wss/p2p-websocket-star',
      '/dns4/localhost/tcp/80/ws/p2p-websocket-star'
    ],
    // ignore_no_online: true, // enable this to prevent wstar-multi from returning a listen error if no servers are online
    id // the id is required for the crypto challenge
  })

  const modules = {
    transport: [
      ws
    ],
    discovery: [
      ws.discovery
    ]
  }

  const node = new Libp2p(modules, peerInfo)

  node.handle('/test/1.0.0', (protocol, conn) => {
    pull(
      pull.values(['hello']),
      conn,
      pull.map((s) => s.toString()),
      pull.log()
    )
  })

  node.start((err) => {
    if (err) {
      throw err
    }

    node.dial(peerInfo, '/test/1.0.0', (err, conn) => {
      if (err) {
        throw err
      }

      pull(
        pull.values(['hello from the other side']),
        conn,
        pull.map((s) => s.toString()),
        pull.log()
      )
    })
  })
})

Outputs:

hello
hello from the other side

This module uses pull-streams

We expose a streaming interface based on pull-streams, rather then on the Node.js core streams implementation (aka Node.js streams). pull-streams offers us a better mechanism for error handling and flow control guarantees. If you would like to know more about why we did this, see the discussion at this issue.

You can learn more about pull-streams at:

Converting pull-streams to Node.js Streams

If you are a Node.js streams user, you can convert a pull-stream to a Node.js stream using the module pull-stream-to-stream, giving you an instance of a Node.js stream that is linked to the pull-stream. For example:

const pullToStream = require('pull-stream-to-stream')

const nodeStreamInstance = pullToStream(pullStreamInstance)
// nodeStreamInstance is an instance of a Node.js Stream

To learn more about this utility, visit https://pull-stream.github.io/#pull-stream-to-stream.

LICENSE MIT

Current Tags

  • 0.4.4                                ...           latest (6 years ago)

11 Versions

  • 0.4.4 [deprecated]           ...           6 years ago
  • 0.4.3 [deprecated]           ...           6 years ago
  • 0.4.0 [deprecated]           ...           6 years ago
  • 0.3.2 [deprecated]           ...           7 years ago
  • 0.3.1 [deprecated]           ...           7 years ago
  • 0.3.0 [deprecated]           ...           7 years ago
  • 0.2.1 [deprecated]           ...           7 years ago
  • 0.2.0 [deprecated]           ...           7 years ago
  • 0.1.1 [deprecated]           ...           7 years ago
  • 0.1.0 [deprecated]           ...           7 years ago
  • 0.0.1 [deprecated]           ...           7 years ago
Maintainers (2)
Downloads
Total 7
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (6)
Dev Dependencies (5)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE