Intro
Installable via npm install --save libp2p
, it can also be used directly in the browser.
Download
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')
In the Browser
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
Libp2p
Parameters
_options: any
:
instance
Libp2p.prototype.emit
emit(eventName: string, args: ...any): void
Overrides EventEmitter.emit to conditionally emit errors if there is a handler. If not, errors will be logged.
Parameters
eventName: string
:args: ...any
:
Returns
void
Libp2p.prototype.start
start(callback: function (Error)): void
Starts the libp2p node and all sub services
Parameters
callback: function (Error) (=()=>{})
:
Returns
void
Libp2p.prototype.stop
stop(callback: function (Error)): void
Stop the libp2p node by closing its listeners and open connections
Parameters
callback: function (Error) (=()=>{})
:
Returns
void
Libp2p.prototype.dial
dial(peer: (PeerInfo | PeerId | Multiaddr | string), callback: function (Error)): void
Dials to the provided peer. If successful, the PeerInfo
of the
peer will be added to the nodes PeerBook
Parameters
Returns
void
Libp2p.prototype.dialProtocol
dialProtocol(peer: (PeerInfo | PeerId | Multiaddr | string), protocol: string, callback: function (Error, Connection)): 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
Parameters
Returns
void
createLibp2p
Like new Libp2p(options)
except it will create a PeerInfo
instance if one is not provided in options.
Returns
void
findPeer
Iterates over all peer routers in series to find the given peer.
Parameters
id: String
:The id of the peer to find
Returns
void
findProviders
Iterates over all content routers in series to find providers of the given key. Once a content router succeeds, iteration will stop.
Parameters
Returns
void
provide
Iterates over all content routers in parallel to notify it is a provider of the given key.
Parameters
key: CID
:The CID key of the content to findcallback: function (Error)
:
Returns
void