Intro
Installable via npm install --save libp2p
, it can also be used directly in the browser.
Libp2p
Parameters
_options: any
:
instance
Libp2p.prototype.emit
emit(eventName: string, args: ...any): void
Overrides EventEmitter.emit to conditionally emit errors + + +
+ Libp2p +
+ + + + src/index.js + + ++ Extends + + EventEmitter + +
+ + + + + + + + + + +(any)
+
+ 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
+ Starts the libp2p node and all sub services
+ +(function (Error)
+ = ()=>{}
)
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+Stop the libp2p node by closing its listeners and open connections
+ +(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. + +
+ + + + + + + + + + + +((PeerInfo | PeerId | Multiaddr | string))
+ The peer to dial
+
+ (function (Error))
+
+ 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
-Libp2p.prototype.dialFSM
dialFSM(peer: (PeerInfo | PeerId | Multiaddr | string), protocol: string, callback: function (Error, ConnectionFSM)): void
Similar to dial
and dialProtocol
, but the callback will contain a
+
+
((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.
Parameters
Returns
void
-createLibp2p
Like new Libp2p(options)
except it will create a PeerInfo
+
+
((PeerInfo | PeerId | Multiaddr | string))
+ The peer to dial
+
+ (string)
+
+ (function (Error, ConnectionFSM))
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + createLibp2p +
+ + + + src/index.js + + +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. + +
(object)
+ Libp2p configuration options
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + findPeer +
+ + + + src/peer-routing.js + + +Iterates over all peer routers in series to find the given peer.
+ +(String)
+ The id of the peer to find
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
++ findProviders +
+ + + + src/content-routing.js + + +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 + +
(CID)
+ The CID key of the content to find
+
+ void
:
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ + provide +
+ + + + src/content-routing.js + + +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 find -callback: function (Error)
:
Returns
void
-