2018-02-07 08:40:53 +00:00
<!doctype html>
2019-07-31 09:47:22 +02:00
< html >
< head >
< meta charset = 'utf-8' >
2019-08-06 12:27:39 +02:00
< title > libp2p 0.26.0-rc.3 | Documentation< / title >
2019-07-31 09:47:22 +02:00
< meta name = 'description' content = 'JavaScript implementation of libp2p, a modular peer to peer network stack' >
< meta name = 'viewport' content = 'width=device-width,initial-scale=1' >
< link href = 'assets/bass.css' rel = 'stylesheet' >
< link href = 'assets/style.css' rel = 'stylesheet' >
< link href = 'assets/github.css' rel = 'stylesheet' >
< link href = 'assets/split.css' rel = 'stylesheet' >
< / head >
< body class = 'documentation m0' >
< div class = 'flex' >
< div id = 'split-left' class = 'overflow-auto fs0 height-viewport-100' >
< div class = 'py1 px2' >
< h3 class = 'mb0 no-anchor' > libp2p< / h3 >
2019-08-06 12:27:39 +02:00
< div class = 'mb1' > < code > 0.26.0-rc.3< / code > < / div >
2019-07-31 09:47:22 +02:00
< input
placeholder='Filter'
id='filter-input'
class='col12 block input'
type='text' />
< div id = 'toc' >
< ul class = 'list-reset h5 py1-ul' >
< li > < a
href='#intro'
class="h5 bold black caps">
Intro
< / a >
< / li >
< li > < a
href='#libp2p'
class=" toggle-sibling">
Libp2p
< span class = 'icon' > ▸< / span >
< / a >
< div class = 'toggle-target display-none' >
< ul class = 'list-reset py1-ul pl1' >
< li class = 'h5' > < span > Instance members< / span > < / li >
< li > < a
href='#libp2pemit'
class='regular pre-open'>
#emit
< / a > < / li >
< li > < a
href='#libp2pstart'
class='regular pre-open'>
#start
< / a > < / li >
< li > < a
href='#libp2pstop'
class='regular pre-open'>
#stop
< / a > < / li >
< li > < a
href='#libp2pdial'
class='regular pre-open'>
#dial
< / a > < / li >
< li > < a
href='#libp2pdialprotocol'
class='regular pre-open'>
#dialProtocol
< / a > < / li >
< li > < a
href='#libp2pdialfsm'
class='regular pre-open'>
#dialFSM
< / a > < / li >
2019-08-06 12:27:39 +02:00
< li > < a
href='#libp2phangup'
class='regular pre-open'>
#hangUp
< / a > < / li >
< li > < a
href='#libp2pping'
class='regular pre-open'>
#ping
< / a > < / li >
2019-07-31 09:47:22 +02:00
< / ul >
< / div >
< / li >
< li > < a
href='#createlibp2p'
class="">
createLibp2p
< / a >
< / li >
< li > < a
href='#findpeer'
class="">
findPeer
< / a >
< / li >
< li > < a
href='#findproviders'
class="">
findProviders
< / a >
< / li >
< li > < a
href='#provide'
class="">
provide
< / a >
< / li >
< li > < a
href='#subscribe'
class="">
subscribe
< / a >
< / li >
< li > < a
href='#unsubscribe'
class="">
unsubscribe
< / a >
< / li >
< / ul >
< / div >
< div class = 'mt1 h6 quiet' >
< a href = 'https://documentation.js.org/reading-documentation.html' > Need help reading this?< / a >
< / div >
< / div >
< / div >
< div id = 'split-right' class = 'relative overflow-auto height-viewport-100' >
< div class = 'keyline-top-not py2' > < section class = 'py2 clearfix' >
< h2 id = 'intro' class = 'mt0' >
Intro
< / h2 >
< p > Installable via < code > npm install --save libp2p< / code > , it can also be used directly in the browser.< / p >
2018-02-07 08:40:53 +00:00
< h2 > Download< / h2 >
< p > The source is available for download from < a href = "https://github.com/libp2p/js-libp2p.git" > GitHub< / a > . Alternatively, you can install using npm:< / p >
< pre class = 'hljs' > $ npm install --save libp2p< / pre >
< p > You can then < code > require()< / code > libp2p as normal:< / p >
< pre class = 'hljs' > < span class = "hljs-keyword" > const< / span > libp2P = < span class = "hljs-built_in" > require< / span > (< span class = "hljs-string" > 'libp2p'< / span > )< / pre >
< h2 > In the Browser< / h2 >
< p > Libp2p should work in any ES2015 environment out of the box.< / p >
< p > Usage:< / p >
2019-06-07 17:10:19 +02:00
< pre class = 'hljs' > < span class = "hljs-tag" > < < span class = "hljs-name" > script< / span > < span class = "hljs-attr" > type< / span > =< span class = "hljs-string" > "text/javascript"< / span > < span class = "hljs-attr" > src< / span > =< span class = "hljs-string" > "index.js"< / span > > < / span > < span class = "hljs-tag" > < /< span class = "hljs-name" > script< / span > > < / span > < / pre >
2018-11-16 14:12:15 +01:00
< p > The portable versions of libp2p, including < code > index.js< / code > and < code > index.min.js< / code > , are included in the < code > /dist< / code > folder. Libp2p can also be found on < a href = "https://unpkg.com" > unpkg.com< / a > under< / p >
2018-02-07 08:40:53 +00:00
< ul >
< li > < a href = "https://unpkg.com/libp2p/dist/index.min.js" > https://unpkg.com/libp2p/dist/index.min.js< / a > < / li >
< li > < a href = "https://unpkg.com/libp2p/dist/index.js" > https://unpkg.com/libp2p/dist/index.js< / a > < / li >
< / ul >
2019-07-31 09:47:22 +02:00
< / section > < / div >
< section class = 'p2 mb2 clearfix bg-white minishadow' >
< div class = 'clearfix' >
< h3 class = 'fl m0' id = 'libp2p' >
Libp2p
< / h3 >
2019-08-06 12:27:39 +02:00
< a class = 'fr fill-darken0 round round pad1x quiet h5' href = 'https://github.com/libp2p/js-libp2p/blob/0489972b4b0fba30c2348ff1a6035151f48a0748/src/index.js#L47-L570' >
2019-07-31 09:47:22 +02:00
< span > src/index.js< / span >
< / a >
< / div >
< div class = 'pre p1 fill-light mt0' > new Libp2p(_options: any)< / div >
< p >
Extends
EventEmitter
< / p >
< div class = 'py1 quiet mt1 prose-big' > Parameters< / div >
< div class = 'prose' >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > _options< / span > < code class = 'quiet' > (any)< / code >
< / div >
< / div >
< / div >
< div class = 'py1 quiet mt1 prose-big' > Instance Members< / div >
< div class = "clearfix" >
< div class = 'border-bottom' id = 'libp2pemit' >
< div class = "clearfix small pointer toggle-sibling" >
< div class = "py1 contain" >
< a class = 'icon pin-right py1 dark-link caret-right' > ▸< / a >
< span class = 'code strong strong truncate' > emit(eventName, args)< / span >
< / div >
< / div >
< div class = "clearfix display-none toggle-target" >
< section class = 'p2 mb2 clearfix bg-white minishadow' >
< div class = 'clearfix' >
2019-08-06 12:27:39 +02:00
< a class = 'fr fill-darken0 round round pad1x quiet h5' href = 'https://github.com/libp2p/js-libp2p/blob/0489972b4b0fba30c2348ff1a6035151f48a0748/src/index.js#L204-L210' >
2019-07-31 09:47:22 +02:00
< span > src/index.js< / span >
< / a >
< / div >
< p > Overrides EventEmitter.emit to conditionally emit errors
2018-11-16 14:12:15 +01:00
if there is a handler. If not, errors will be logged.< / p >
2019-07-31 09:47:22 +02:00
< div class = 'pre p1 fill-light mt0' > emit(eventName: < a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String" > string< / a > , args: ...any): void< / div >
< div class = 'py1 quiet mt1 prose-big' > Parameters< / div >
< div class = 'prose' >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > eventName< / span > < code class = 'quiet' > (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String" > string< / a > )< / code >
< / div >
< / div >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > args< / span > < code class = 'quiet' > (...any)< / code >
< / div >
< / div >
< / div >
< div class = 'py1 quiet mt1 prose-big' > Returns< / div >
< code > void< / code > :
< / section >
< / div >
< / div >
< div class = 'border-bottom' id = 'libp2pstart' >
< div class = "clearfix small pointer toggle-sibling" >
< div class = "py1 contain" >
< a class = 'icon pin-right py1 dark-link caret-right' > ▸< / a >
< span class = 'code strong strong truncate' > start(callback)< / span >
< / div >
< / div >
< div class = "clearfix display-none toggle-target" >
< section class = 'p2 mb2 clearfix bg-white minishadow' >
< div class = 'clearfix' >
2019-08-06 12:27:39 +02:00
< a class = 'fr fill-darken0 round round pad1x quiet h5' href = 'https://github.com/libp2p/js-libp2p/blob/0489972b4b0fba30c2348ff1a6035151f48a0748/src/index.js#L218-L221' >
2019-07-31 09:47:22 +02:00
< span > src/index.js< / span >
< / a >
< / div >
< p > Starts the libp2p node and all sub services< / p >
< div class = 'pre p1 fill-light mt0' > start(callback: function (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error" > Error< / a > )): void< / div >
< div class = 'py1 quiet mt1 prose-big' > Parameters< / div >
< div class = 'prose' >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > callback< / span > < code class = 'quiet' > (function (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error" > Error< / a > )
= < code > ()=> {}< / code > )< / code >
< / div >
< / div >
< / div >
< div class = 'py1 quiet mt1 prose-big' > Returns< / div >
< code > void< / code > :
< / section >
< / div >
< / div >
< div class = 'border-bottom' id = 'libp2pstop' >
< div class = "clearfix small pointer toggle-sibling" >
< div class = "py1 contain" >
< a class = 'icon pin-right py1 dark-link caret-right' > ▸< / a >
< span class = 'code strong strong truncate' > stop(callback)< / span >
< / div >
< / div >
< div class = "clearfix display-none toggle-target" >
< section class = 'p2 mb2 clearfix bg-white minishadow' >
< div class = 'clearfix' >
2019-08-06 12:27:39 +02:00
< a class = 'fr fill-darken0 round round pad1x quiet h5' href = 'https://github.com/libp2p/js-libp2p/blob/0489972b4b0fba30c2348ff1a6035151f48a0748/src/index.js#L229-L232' >
2019-07-31 09:47:22 +02:00
< span > src/index.js< / span >
< / a >
< / div >
< p > Stop the libp2p node by closing its listeners and open connections< / p >
< div class = 'pre p1 fill-light mt0' > stop(callback: function (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error" > Error< / a > )): void< / div >
< div class = 'py1 quiet mt1 prose-big' > Parameters< / div >
< div class = 'prose' >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > callback< / span > < code class = 'quiet' > (function (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error" > Error< / a > )
= < code > ()=> {}< / code > )< / code >
< / div >
< / div >
< / div >
< div class = 'py1 quiet mt1 prose-big' > Returns< / div >
< code > void< / code > :
< / section >
< / div >
< / div >
< div class = 'border-bottom' id = 'libp2pdial' >
< div class = "clearfix small pointer toggle-sibling" >
< div class = "py1 contain" >
< a class = 'icon pin-right py1 dark-link caret-right' > ▸< / a >
< span class = 'code strong strong truncate' > dial(peer, callback)< / span >
< / div >
< / div >
< div class = "clearfix display-none toggle-target" >
< section class = 'p2 mb2 clearfix bg-white minishadow' >
< div class = 'clearfix' >
2019-08-06 12:27:39 +02:00
< a class = 'fr fill-darken0 round round pad1x quiet h5' href = 'https://github.com/libp2p/js-libp2p/blob/0489972b4b0fba30c2348ff1a6035151f48a0748/src/index.js#L246-L248' >
2019-07-31 09:47:22 +02:00
< span > src/index.js< / span >
< / a >
< / div >
< p > Dials to the provided peer. If successful, the < code > PeerInfo< / code > of the
2018-11-16 14:12:15 +01:00
peer will be added to the nodes < code > PeerBook< / code > < / p >
2019-07-31 09:47:22 +02:00
< div class = 'pre p1 fill-light mt0' > dial(peer: (PeerInfo | PeerId | Multiaddr | < a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String" > string< / a > ), callback: function (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error" > Error< / a > )): void< / div >
< div class = 'py1 quiet mt1 prose-big' > Parameters< / div >
< div class = 'prose' >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > peer< / span > < code class = 'quiet' > ((PeerInfo | PeerId | Multiaddr | < a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String" > string< / a > ))< / code >
The peer to dial
< / div >
< / div >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > callback< / span > < code class = 'quiet' > (function (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error" > Error< / a > ))< / code >
< / div >
< / div >
< / div >
< div class = 'py1 quiet mt1 prose-big' > Returns< / div >
< code > void< / code > :
< / section >
< / div >
< / div >
< div class = 'border-bottom' id = 'libp2pdialprotocol' >
< div class = "clearfix small pointer toggle-sibling" >
< div class = "py1 contain" >
< a class = 'icon pin-right py1 dark-link caret-right' > ▸< / a >
< span class = 'code strong strong truncate' > dialProtocol(peer, protocol, callback)< / span >
< / div >
< / div >
< div class = "clearfix display-none toggle-target" >
< section class = 'p2 mb2 clearfix bg-white minishadow' >
< div class = 'clearfix' >
2019-08-06 12:27:39 +02:00
< a class = 'fr fill-darken0 round round pad1x quiet h5' href = 'https://github.com/libp2p/js-libp2p/blob/0489972b4b0fba30c2348ff1a6035151f48a0748/src/index.js#L260-L275' >
2019-07-31 09:47:22 +02:00
< span > src/index.js< / span >
< / a >
< / div >
< p > Dials to the provided peer and handshakes with the given protocol.
2018-11-16 14:12:15 +01:00
If successful, the < code > PeerInfo< / code > of the peer will be added to the nodes < code > PeerBook< / code > ,
and the < code > Connection< / code > will be sent in the callback< / p >
2019-07-31 09:47:22 +02:00
< div class = 'pre p1 fill-light mt0' > dialProtocol(peer: (PeerInfo | PeerId | Multiaddr | < a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String" > string< / a > ), protocol: < a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String" > string< / a > , callback: function (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error" > Error< / a > , Connection)): void< / div >
< div class = 'py1 quiet mt1 prose-big' > Parameters< / div >
< div class = 'prose' >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > peer< / span > < code class = 'quiet' > ((PeerInfo | PeerId | Multiaddr | < a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String" > string< / a > ))< / code >
The peer to dial
< / div >
< / div >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > protocol< / span > < code class = 'quiet' > (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String" > string< / a > )< / code >
< / div >
< / div >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > callback< / span > < code class = 'quiet' > (function (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error" > Error< / a > , Connection))< / code >
< / div >
< / div >
< / div >
< div class = 'py1 quiet mt1 prose-big' > Returns< / div >
< code > void< / code > :
< / section >
< / div >
< / div >
< div class = 'border-bottom' id = 'libp2pdialfsm' >
< div class = "clearfix small pointer toggle-sibling" >
< div class = "py1 contain" >
< a class = 'icon pin-right py1 dark-link caret-right' > ▸< / a >
< span class = 'code strong strong truncate' > dialFSM(peer, protocol, callback)< / span >
< / div >
< / div >
< div class = "clearfix display-none toggle-target" >
< section class = 'p2 mb2 clearfix bg-white minishadow' >
< div class = 'clearfix' >
2019-08-06 12:27:39 +02:00
< a class = 'fr fill-darken0 round round pad1x quiet h5' href = 'https://github.com/libp2p/js-libp2p/blob/0489972b4b0fba30c2348ff1a6035151f48a0748/src/index.js#L286-L301' >
2019-07-31 09:47:22 +02:00
< span > src/index.js< / span >
< / a >
< / div >
< p > Similar to < code > dial< / code > and < code > dialProtocol< / code > , but the callback will contain a
2018-11-16 14:12:15 +01:00
Connection State Machine.< / p >
2019-07-31 09:47:22 +02:00
< div class = 'pre p1 fill-light mt0' > dialFSM(peer: (PeerInfo | PeerId | Multiaddr | < a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String" > string< / a > ), protocol: < a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String" > string< / a > , callback: function (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error" > Error< / a > , ConnectionFSM)): void< / div >
< div class = 'py1 quiet mt1 prose-big' > Parameters< / div >
< div class = 'prose' >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > peer< / span > < code class = 'quiet' > ((PeerInfo | PeerId | Multiaddr | < a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String" > string< / a > ))< / code >
The peer to dial
< / div >
< / div >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > protocol< / span > < code class = 'quiet' > (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String" > string< / a > )< / code >
< / div >
< / div >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > callback< / span > < code class = 'quiet' > (function (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error" > Error< / a > , ConnectionFSM))< / code >
< / div >
< / div >
< / div >
< div class = 'py1 quiet mt1 prose-big' > Returns< / div >
< code > void< / code > :
2019-08-06 12:27:39 +02:00
< / section >
< / div >
< / div >
< div class = 'border-bottom' id = 'libp2phangup' >
< div class = "clearfix small pointer toggle-sibling" >
< div class = "py1 contain" >
< a class = 'icon pin-right py1 dark-link caret-right' > ▸< / a >
< span class = 'code strong strong truncate' > hangUp(peer, callback)< / span >
< / div >
< / div >
< div class = "clearfix display-none toggle-target" >
< section class = 'p2 mb2 clearfix bg-white minishadow' >
< div class = 'clearfix' >
< a class = 'fr fill-darken0 round round pad1x quiet h5' href = 'https://github.com/libp2p/js-libp2p/blob/0489972b4b0fba30c2348ff1a6035151f48a0748/src/index.js#L310-L316' >
< span > src/index.js< / span >
< / a >
< / div >
< p > Disconnects from the given peer< / p >
< div class = 'pre p1 fill-light mt0' > hangUp(peer: (PeerInfo | PeerId | Multiaddr | < a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String" > string< / a > ), callback: function (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error" > Error< / a > )): void< / div >
< div class = 'py1 quiet mt1 prose-big' > Parameters< / div >
< div class = 'prose' >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > peer< / span > < code class = 'quiet' > ((PeerInfo | PeerId | Multiaddr | < a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String" > string< / a > ))< / code >
The peer to ping
< / div >
< / div >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > callback< / span > < code class = 'quiet' > (function (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error" > Error< / a > ))< / code >
< / div >
< / div >
< / div >
< div class = 'py1 quiet mt1 prose-big' > Returns< / div >
< code > void< / code > :
< / section >
< / div >
< / div >
< div class = 'border-bottom' id = 'libp2pping' >
< div class = "clearfix small pointer toggle-sibling" >
< div class = "py1 contain" >
< a class = 'icon pin-right py1 dark-link caret-right' > ▸< / a >
< span class = 'code strong strong truncate' > ping(peer, callback)< / span >
< / div >
< / div >
< div class = "clearfix display-none toggle-target" >
< section class = 'p2 mb2 clearfix bg-white minishadow' >
< div class = 'clearfix' >
< a class = 'fr fill-darken0 round round pad1x quiet h5' href = 'https://github.com/libp2p/js-libp2p/blob/0489972b4b0fba30c2348ff1a6035151f48a0748/src/index.js#L325-L335' >
< span > src/index.js< / span >
< / a >
< / div >
< p > Pings the provided peer< / p >
< div class = 'pre p1 fill-light mt0' > ping(peer: (PeerInfo | PeerId | Multiaddr | < a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String" > string< / a > ), callback: function (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error" > Error< / a > , Ping)): void< / div >
< div class = 'py1 quiet mt1 prose-big' > Parameters< / div >
< div class = 'prose' >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > peer< / span > < code class = 'quiet' > ((PeerInfo | PeerId | Multiaddr | < a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String" > string< / a > ))< / code >
The peer to ping
< / div >
< / div >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > callback< / span > < code class = 'quiet' > (function (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error" > Error< / a > , Ping))< / code >
< / div >
< / div >
< / div >
< div class = 'py1 quiet mt1 prose-big' > Returns< / div >
< code > void< / code > :
2019-07-31 09:47:22 +02:00
< / section >
< / div >
< / div >
< / div >
< / section >
< section class = 'p2 mb2 clearfix bg-white minishadow' >
< div class = 'clearfix' >
< h3 class = 'fl m0' id = 'createlibp2p' >
createLibp2p
< / h3 >
2019-08-06 12:27:39 +02:00
< a class = 'fr fill-darken0 round round pad1x quiet h5' href = 'https://github.com/libp2p/js-libp2p/blob/0489972b4b0fba30c2348ff1a6035151f48a0748/src/index.js#L580-L589' >
2019-07-31 09:47:22 +02:00
< span > src/index.js< / span >
< / a >
< / div >
< p > Like < code > new Libp2p(options)< / code > except it will create a < code > PeerInfo< / code >
2019-06-07 17:10:19 +02:00
instance if one is not provided in options.< / p >
2019-07-31 09:47:22 +02:00
< div class = 'pre p1 fill-light mt0' > createLibp2p< / div >
< div class = 'py1 quiet mt1 prose-big' > Parameters< / div >
< div class = 'prose' >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > options< / span > < code class = 'quiet' > (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object" > object< / a > )< / code >
Libp2p configuration options
< / div >
< / div >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > callback< / span > < code class = 'quiet' > (function (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error" > Error< / a > , < a href = "#libp2p" > Libp2p< / a > ))< / code >
< / div >
< / div >
< / div >
< div class = 'py1 quiet mt1 prose-big' > Returns< / div >
< code > void< / code > :
< / section >
< section class = 'p2 mb2 clearfix bg-white minishadow' >
< div class = 'clearfix' >
< h3 class = 'fl m0' id = 'findpeer' >
findPeer
< / h3 >
2019-08-06 12:27:39 +02:00
< a class = 'fr fill-darken0 round round pad1x quiet h5' href = 'https://github.com/libp2p/js-libp2p/blob/0489972b4b0fba30c2348ff1a6035151f48a0748/src/peer-routing.js#L25-L57' >
2019-07-31 09:47:22 +02:00
< span > src/peer-routing.js< / span >
< / a >
< / div >
< p > Iterates over all peer routers in series to find the given peer.< / p >
< div class = 'pre p1 fill-light mt0' > findPeer< / div >
< div class = 'py1 quiet mt1 prose-big' > Parameters< / div >
< div class = 'prose' >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > id< / span > < code class = 'quiet' > (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String" > String< / a > )< / code >
The id of the peer to find
< / div >
< / div >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > options< / span > < code class = 'quiet' > (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object" > object< / a > )< / code >
< / div >
< table class = 'mt1 mb2 fixed-table h5 col-12' >
< colgroup >
< col width = '30%' / >
< col width = '70%' / >
< / colgroup >
< thead >
< tr class = 'bold fill-light' >
< th > Name< / th >
< th > Description< / th >
< / tr >
< / thead >
< tbody class = 'mt1' >
< tr >
< td class = 'break-word' > < span class = 'code bold' > options.maxTimeout< / span > < code class = 'quiet' > < a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number" > number< / a > < / code >
< / td >
< td class = 'break-word' > < span > How long the query should run
< / span > < / td >
< / tr >
< / tbody >
< / table >
< / div >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > callback< / span > < code class = 'quiet' > (function (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error" > Error< / a > , Result< < a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array" > Array< / a > >))< / code >
< / div >
< / div >
< / div >
< div class = 'py1 quiet mt1 prose-big' > Returns< / div >
< code > void< / code > :
< / section >
< section class = 'p2 mb2 clearfix bg-white minishadow' >
< div class = 'clearfix' >
< h3 class = 'fl m0' id = 'findproviders' >
findProviders
< / h3 >
2019-08-06 12:27:39 +02:00
< a class = 'fr fill-darken0 round round pad1x quiet h5' href = 'https://github.com/libp2p/js-libp2p/blob/0489972b4b0fba30c2348ff1a6035151f48a0748/src/content-routing.js#L28-L64' >
2019-07-31 09:47:22 +02:00
< span > src/content-routing.js< / span >
< / a >
< / div >
< p > Iterates over all content routers in series to find providers of the given key.
2018-11-16 14:12:15 +01:00
Once a content router succeeds, iteration will stop.< / p >
2019-07-31 09:47:22 +02:00
< div class = 'pre p1 fill-light mt0' > findProviders< / div >
< div class = 'py1 quiet mt1 prose-big' > Parameters< / div >
< div class = 'prose' >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > key< / span > < code class = 'quiet' > (CID)< / code >
The CID key of the content to find
< / div >
< / div >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > options< / span > < code class = 'quiet' > (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object" > object< / a > )< / code >
< / div >
< table class = 'mt1 mb2 fixed-table h5 col-12' >
< colgroup >
< col width = '30%' / >
< col width = '70%' / >
< / colgroup >
< thead >
< tr class = 'bold fill-light' >
< th > Name< / th >
< th > Description< / th >
< / tr >
< / thead >
< tbody class = 'mt1' >
< tr >
< td class = 'break-word' > < span class = 'code bold' > options.maxTimeout< / span > < code class = 'quiet' > < a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number" > number< / a > < / code >
< / td >
< td class = 'break-word' > < span > How long the query should run
< / span > < / td >
< / tr >
< tr >
< td class = 'break-word' > < span class = 'code bold' > options.maxNumProviders< / span > < code class = 'quiet' > < a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number" > number< / a > < / code >
< / td >
< td class = 'break-word' > < span > maximum number of providers to find
< / span > < / td >
< / tr >
< / tbody >
< / table >
< / div >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > callback< / span > < code class = 'quiet' > (function (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error" > Error< / a > , Result< < a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array" > Array< / a > >))< / code >
< / div >
< / div >
< / div >
< div class = 'py1 quiet mt1 prose-big' > Returns< / div >
< code > void< / code > :
< / section >
< section class = 'p2 mb2 clearfix bg-white minishadow' >
< div class = 'clearfix' >
< h3 class = 'fl m0' id = 'provide' >
provide
< / h3 >
2019-08-06 12:27:39 +02:00
< a class = 'fr fill-darken0 round round pad1x quiet h5' href = 'https://github.com/libp2p/js-libp2p/blob/0489972b4b0fba30c2348ff1a6035151f48a0748/src/content-routing.js#L74-L82' >
2019-07-31 09:47:22 +02:00
< span > src/content-routing.js< / span >
< / a >
< / div >
< p > Iterates over all content routers in parallel to notify it is
2018-11-16 14:12:15 +01:00
a provider of the given key.< / p >
2019-07-31 09:47:22 +02:00
< div class = 'pre p1 fill-light mt0' > provide< / div >
< div class = 'py1 quiet mt1 prose-big' > Parameters< / div >
< div class = 'prose' >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > key< / span > < code class = 'quiet' > (CID)< / code >
The CID key of the content to find
< / div >
< / div >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > callback< / span > < code class = 'quiet' > (function (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error" > Error< / a > ))< / code >
< / div >
< / div >
< / div >
< div class = 'py1 quiet mt1 prose-big' > Returns< / div >
< code > void< / code > :
< / section >
< section class = 'p2 mb2 clearfix bg-white minishadow' >
< div class = 'clearfix' >
< h3 class = 'fl m0' id = 'subscribe' >
subscribe
< / h3 >
2019-08-06 12:27:39 +02:00
< a class = 'fr fill-darken0 round round pad1x quiet h5' href = 'https://github.com/libp2p/js-libp2p/blob/0489972b4b0fba30c2348ff1a6035151f48a0748/src/pubsub.js#L35-L55' >
2019-07-31 09:47:22 +02:00
< span > src/pubsub.js< / span >
< / a >
< / div >
< p > Subscribe the given handler to a pubsub topic< / p >
< div class = 'pre p1 fill-light mt0' > subscribe< / div >
< div class = 'py1 quiet mt1 prose-big' > Parameters< / div >
< div class = 'prose' >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > topic< / span > < code class = 'quiet' > (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String" > string< / a > )< / code >
< / div >
< / div >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > handler< / span > < code class = 'quiet' > (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function" > function< / a > )< / code >
The handler to subscribe
< / div >
< / div >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > options< / span > < code class = 'quiet' > ((< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object" > object< / a > | null)?)< / code >
< / div >
< / div >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > callback< / span > < code class = 'quiet' > (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function" > function< / a > ?)< / code >
An optional callback
< / div >
< / div >
< / div >
< div class = 'py1 quiet mt1 prose-big' > Returns< / div >
< code > (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise" > Promise< / a > | void)< / code > :
A promise is returned if no callback is provided
< div class = 'py1 quiet mt1 prose-big' > Example< / div >
< p > < p > Subscribe a handler to a topic< / p >
< / p >
< pre class = 'p1 overflow-auto round fill-light' > < span class = "hljs-comment" > // `null` must be passed for options until subscribe is no longer using promisify< / span >
< span class = "hljs-keyword" > const< / span > handler = < span class = "hljs-function" > (< span class = "hljs-params" > message< / span > ) => < / span > { }
< span class = "hljs-keyword" > await< / span > libp2p.subscribe(topic, handler, < span class = "hljs-literal" > null< / span > )< / pre >
< p > < p > Use a callback instead of the Promise api< / p >
< / p >
< pre class = 'p1 overflow-auto round fill-light' > < span class = "hljs-comment" > // `options` may be passed or omitted when supplying a callback< / span >
< span class = "hljs-keyword" > const< / span > handler = < span class = "hljs-function" > (< span class = "hljs-params" > message< / span > ) => < / span > { }
libp2p.subscribe(topic, handler, callback)< / pre >
< / section >
< section class = 'p2 mb2 clearfix bg-white minishadow' >
< div class = 'clearfix' >
< h3 class = 'fl m0' id = 'unsubscribe' >
unsubscribe
< / h3 >
2019-08-06 12:27:39 +02:00
< a class = 'fr fill-darken0 round round pad1x quiet h5' href = 'https://github.com/libp2p/js-libp2p/blob/0489972b4b0fba30c2348ff1a6035151f48a0748/src/pubsub.js#L79-L99' >
2019-07-31 09:47:22 +02:00
< span > src/pubsub.js< / span >
< / a >
< / div >
< p > Unsubscribes from a pubsub topic< / p >
< div class = 'pre p1 fill-light mt0' > unsubscribe< / div >
< div class = 'py1 quiet mt1 prose-big' > Parameters< / div >
< div class = 'prose' >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > topic< / span > < code class = 'quiet' > (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String" > string< / a > )< / code >
< / div >
< / div >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > handler< / span > < code class = 'quiet' > ((< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function" > function< / a > | null))< / code >
The handler to unsubscribe from
< / div >
< / div >
< div class = 'space-bottom0' >
< div >
< span class = 'code bold' > callback< / span > < code class = 'quiet' > (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function" > function< / a > ?)< / code >
An optional callback
< / div >
< / div >
< / div >
< div class = 'py1 quiet mt1 prose-big' > Returns< / div >
< code > (< a href = "https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise" > Promise< / a > | void)< / code > :
A promise is returned if no callback is provided
< div class = 'py1 quiet mt1 prose-big' > Example< / div >
< p > < p > Unsubscribe a topic for all handlers< / p >
< / p >
< pre class = 'p1 overflow-auto round fill-light' > < span class = "hljs-comment" > // `null` must be passed until unsubscribe is no longer using promisify< / span >
< span class = "hljs-keyword" > await< / span > libp2p.unsubscribe(topic, < span class = "hljs-literal" > null< / span > )< / pre >
< p > < p > Unsubscribe a topic for 1 handler< / p >
< / p >
< pre class = 'p1 overflow-auto round fill-light' > < span class = "hljs-keyword" > await< / span > libp2p.unsubscribe(topic, handler)< / pre >
< p > < p > Use a callback instead of the Promise api< / p >
< / p >
< pre class = 'p1 overflow-auto round fill-light' > libp2p.unsubscribe(topic, handler, callback)< / pre >
< / section >
< / div >
< / div >
< script src = 'assets/anchor.js' > < / script >
< script src = 'assets/split.js' > < / script >
< script src = 'assets/site.js' > < / script >
< / body >
< / html >