dwswarm-network
The low level networking guts of the Hyperswarm stack.
npm install dwswarm-network
Usage
const network =const nw =nw
API
net = network([options])
Create a new network instance.
Options include:
{// called when the network is bound}{// called when the network is fully closed}{// called when an incoming socket is received}// Optionally overwrite the default set of bootstrap serversbootstrap: addresses// Set to false if this is a long running instance on a server// When running in ephemeral mode (default) you don't join the// DHT but just query it instead.ephemeral: true
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