@hyperswarm/network
The networking guts of Hyperswarm
Last updated 5 years ago by mafintosh .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install @hyperswarm/network 
SYNC missed versions from official npm registry.

@hyperswarm/network

The low level networking guts of the Hyperswarm stack.

npm install @hyperswarm/network

Usage

const network = require('@hyperswarm/network')()

const nw = network()

nw.bind(function () {
  // topic should be a 32 byte buffer
  nw.lookupOne(topic, function (err, peer) {
    if (err) throw err
    nw.connect(peer, function (err, socket) {
      if (err) throw err
      socket.write('Hello World!')
    })
  })
})

API

net = network([options])

Create a new network instance.

Options include:

{
  bind () {
    // called when the network is bound
  },
  close () {
    // called when the network is fully closed
  },
  socket (socket) {
    // called when an incoming socket is received
  },
  // Optionally overwrite the default set of bootstrap servers
  bootstrap: [addresses],
  // Set to false if this is a long running instance on a server
  // When running in ephemeral mode you don't join the DHT but just 
  // query it instead. If unset, or set to a non-boolean (default undefined)
  // then the node will start in short-lived (ephemeral) mode and switch 
  // to long-lived (non-ephemeral) mode after a certain period of uptime
  ephemeral: undefined
}

nw.bind([preferredPort], [callback])

Bind to a preferred port. Must be called before connecting.

Safe to call multiple times. If already bound or binding it will call the callback when fully bound.

nw.close([callback])

Fully close the network.

Safe to call multiple times.

nw.connect(peer, callback)

Connect to a peer. Will do UDP holepunching.

Callback is called with (err, socket, isTCP). If the underlying socket is a TCP socket isTCP will be true, if it is a UTP socket it will be false.

announcer = nw.announce(topic)

Start announcing the network on the Hyperswarm discovery network.

lookup = nw.lookup(topic)

Start doing a lookup on the Hyperswarm discovery network.

nw.lookupOne(topic, callback)

Lookup a single peer on the Hyperswarm discovery network.

License

MIT

Current Tags

  • 2.1.0                                ...           latest (4 years ago)

22 Versions

  • 2.1.0                                ...           4 years ago
  • 2.0.0                                ...           4 years ago
  • 1.5.1                                ...           4 years ago
  • 1.5.0                                ...           4 years ago
  • 1.4.0                                ...           4 years ago
  • 1.3.2                                ...           5 years ago
  • 1.3.1                                ...           5 years ago
  • 1.3.0                                ...           5 years ago
  • 1.2.0                                ...           5 years ago
  • 1.1.3                                ...           5 years ago
  • 1.1.2                                ...           5 years ago
  • 1.1.1                                ...           5 years ago
  • 1.1.0                                ...           5 years ago
  • 1.0.3                                ...           5 years ago
  • 1.0.2                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           5 years ago
  • 0.0.4                                ...           6 years ago
  • 0.0.3                                ...           6 years ago
  • 0.0.2                                ...           6 years ago
  • 0.0.1                                ...           6 years ago
  • 0.0.0                                ...           6 years ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (3)
Dev Dependencies (5)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |