0.26.0
Installable via npm install --save libp2p
, it can also be used directly in the browser.
The source is available for download from GitHub. Alternatively, you can install using npm:
$ npm install --save libp2p
You can then require()
libp2p as normal:
const libp2P = require('libp2p')
Libp2p should work in any ES2015 environment out of the box.
Usage:
<script type="text/javascript" src="index.js"></script>
The portable versions of libp2p, including index.js
and index.min.js
, are included in the /dist
folder. Libp2p can also be found on unpkg.com under
Extends EventEmitter
(any)
Dials to the provided peer. If successful, the PeerInfo
of the
peer will be added to the nodes PeerBook
void
:
Dials to the provided peer and handshakes with the given protocol.
If successful, the PeerInfo
of the peer will be added to the nodes PeerBook
,
and the Connection
will be sent in the callback
((PeerInfo | PeerId | Multiaddr | string))
The peer to dial
(string)
(function (Error, Connection))
void
:
Similar to dial
and dialProtocol
, but the callback will contain a
Connection State Machine.
((PeerInfo | PeerId | Multiaddr | string))
The peer to dial
(string)
(function (Error, ConnectionFSM))
void
:
Disconnects from the given peer
void
:
Like new Libp2p(options)
except it will create a PeerInfo
instance if one is not provided in options.
void
:
Iterates over all peer routers in series to find the given peer.
(String)
The id of the peer to find
void
:
Iterates over all content routers in series to find providers of the given key. Once a content router succeeds, iteration will stop.
(CID)
The CID key of the content to find
void
:
Iterates over all content routers in parallel to notify it is a provider of the given key.
(CID)
The CID key of the content to find
(function (Error))
void
:
Subscribe the given handler to a pubsub topic
(string)
(function)
The handler to subscribe
((object | null)?)
(function?)
An optional callback
(Promise | void)
:
A promise is returned if no callback is provided
Subscribe a handler to a topic
// `null` must be passed for options until subscribe is no longer using promisify
const handler = (message) => { }
await libp2p.subscribe(topic, handler, null)
Use a callback instead of the Promise api
// `options` may be passed or omitted when supplying a callback
const handler = (message) => { }
libp2p.subscribe(topic, handler, callback)
Unsubscribes from a pubsub topic
(string)
((function | null))
The handler to unsubscribe from
(function?)
An optional callback
(Promise | void)
:
A promise is returned if no callback is provided
Unsubscribe a topic for all handlers
// `null` must be passed until unsubscribe is no longer using promisify
await libp2p.unsubscribe(topic, null)
Unsubscribe a topic for 1 handler
await libp2p.unsubscribe(topic, handler)
Use a callback instead of the Promise api
libp2p.unsubscribe(topic, handler, callback)