font-weight: bold;}.hljs-deletion{background: #fdd;}.hljs-addition{background: #dfd;}.hljs-emphasis{font-style: italic;}.hljs-strong{font-weight: bold;}</style><divstyle="margin-bottom:104px;"data-radium="true"><h1data-radium="true"><aclass="anchor"name="intro"></a>Intro</h1><div><p>Installable via <code>npm install --save libp2p</code>, it can also be used directly in the browser.</p>
<h2>Download</h2>
<p>The source is available for download from <ahref="https://github.com/libp2p/js-libp2p.git">GitHub</a>. Alternatively, you can install using npm:</p>
<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 <ahref="https://unpkg.com">unpkg.com</a> under</p>
</div><divdata-radium="true"><h4>Parameters</h4><olstyle="list-style:none;margin-left:0;padding-left:0;"data-radium="true"><divdata-radium="true"><listyle="padding-bottom:13px;"data-radium="true"><code>callback: function (<ahref="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error">Error</a>) (=()=>{})</code>: <divstyle="display:inline-block;"data-radium="true"></div></li></div></ol></div><divdata-radium="true"><h4>Returns</h4><divdata-radium="true"><code>void</code><span>
</div><divdata-radium="true"><h4>Parameters</h4><olstyle="list-style:none;margin-left:0;padding-left:0;"data-radium="true"><divdata-radium="true"><listyle="padding-bottom:13px;"data-radium="true"><code>callback: function (<ahref="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error">Error</a>) (=()=>{})</code>: <divstyle="display:inline-block;"data-radium="true"></div></li></div></ol></div><divdata-radium="true"><h4>Returns</h4><divdata-radium="true"><code>void</code><span>
</div></li></div><divdata-radium="true"><listyle="padding-bottom:13px;"data-radium="true"><code>callback: function (<ahref="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error">Error</a>)</code>: <divstyle="display:inline-block;"data-radium="true"></div></li></div></ol></div><divdata-radium="true"><h4>Returns</h4><divdata-radium="true"><code>void</code><span>
</span></div></div></div></div></div><divstyle="margin-bottom:104px;"data-radium="true"><h1data-radium="true"><aclass="anchor"name="findpeer"></a>findPeer<ahref="https://github.com/libp2p/js-libp2p/blob/71dcaafcac426a5ece9b5def616e256654669b64/src/peer-routing.js#L24-L56"title="src/peer-routing.js"style="float:right;"data-radium="true"><svgfill="currentColor"preserveAspectRatio="xMidYMid meet"height="1em"width="1em"viewBox="0 0 40 40"style="vertical-align:middle;"><g><pathd="m26.3 7.5l-3.8 3.8 8.8 8.7-8.8 8.8 3.8 3.7 11.2-12.5-11.2-12.5z m-12.5 0l-11.3 12.5 11.3 12.5 3.7-3.7-8.7-8.8 8.7-8.7-3.7-3.8z"></path></g></svg></a></h1><div><p>Iterates over all peer routers in series to find the given peer.</p>
</div><divdata-radium="true"><h4>Parameters</h4><olstyle="list-style:none;margin-left:0;padding-left:0;"data-radium="true"><divdata-radium="true"><listyle="padding-bottom:13px;"data-radium="true"><code>id: <ahref="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">String</a></code>: <divstyle="display:inline-block;"data-radium="true">The id of the peer to find
</div></li></div><divdata-radium="true"><listyle="padding-bottom:13px;"data-radium="true"><code>options: <ahref="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object">object</a></code>: <divstyle="display:inline-block;"data-radium="true"></div></li><listyle="padding-bottom:13px;"data-radium="true"><code>options.maxTimeout: <ahref="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code>: <divstyle="display:inline-block;"data-radium="true">How long the query should run
</div></li></div><divdata-radium="true"><listyle="padding-bottom:13px;"data-radium="true"><code>callback: function (<ahref="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error">Error</a>, Result<<ahref="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>>)</code>: <divstyle="display:inline-block;"data-radium="true"></div></li></div></ol></div><divdata-radium="true"><h4>Returns</h4><divdata-radium="true"><code>void</code><span>
</span></div></div></div><divstyle="margin-bottom:104px;"data-radium="true"><h1data-radium="true"><aclass="anchor"name="findproviders"></a>findProviders<ahref="https://github.com/libp2p/js-libp2p/blob/71dcaafcac426a5ece9b5def616e256654669b64/src/content-routing.js#L27-L63"title="src/content-routing.js"style="float:right;"data-radium="true"><svgfill="currentColor"preserveAspectRatio="xMidYMid meet"height="1em"width="1em"viewBox="0 0 40 40"style="vertical-align:middle;"><g><pathd="m26.3 7.5l-3.8 3.8 8.8 8.7-8.8 8.8 3.8 3.7 11.2-12.5-11.2-12.5z m-12.5 0l-11.3 12.5 11.3 12.5 3.7-3.7-8.7-8.8 8.7-8.7-3.7-3.8z"></path></g></svg></a></h1><div><p>Iterates over all content routers in series to find providers of the given key.
Once a content router succeeds, iteration will stop.</p>
</div><divdata-radium="true"><h4>Parameters</h4><olstyle="list-style:none;margin-left:0;padding-left:0;"data-radium="true"><divdata-radium="true"><listyle="padding-bottom:13px;"data-radium="true"><code>key: CID</code>: <divstyle="display:inline-block;"data-radium="true">The CID key of the content to find
</div></li></div><divdata-radium="true"><listyle="padding-bottom:13px;"data-radium="true"><code>options: <ahref="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object">object</a></code>: <divstyle="display:inline-block;"data-radium="true"></div></li><listyle="padding-bottom:13px;"data-radium="true"><code>options.maxTimeout: <ahref="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code>: <divstyle="display:inline-block;"data-radium="true">How long the query should run
</div></li><listyle="padding-bottom:13px;"data-radium="true"><code>options.maxNumProviders: <ahref="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a></code>: <divstyle="display:inline-block;"data-radium="true">maximum number of providers to find
</div></li></div><divdata-radium="true"><listyle="padding-bottom:13px;"data-radium="true"><code>callback: function (<ahref="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error">Error</a>, Result<<ahref="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array">Array</a>>)</code>: <divstyle="display:inline-block;"data-radium="true"></div></li></div></ol></div><divdata-radium="true"><h4>Returns</h4><divdata-radium="true"><code>void</code><span>
</span></div></div></div><divstyle="margin-bottom:104px;"data-radium="true"><h1data-radium="true"><aclass="anchor"name="provide"></a>provide<ahref="https://github.com/libp2p/js-libp2p/blob/71dcaafcac426a5ece9b5def616e256654669b64/src/content-routing.js#L73-L81"title="src/content-routing.js"style="float:right;"data-radium="true"><svgfill="currentColor"preserveAspectRatio="xMidYMid meet"height="1em"width="1em"viewBox="0 0 40 40"style="vertical-align:middle;"><g><pathd="m26.3 7.5l-3.8 3.8 8.8 8.7-8.8 8.8 3.8 3.7 11.2-12.5-11.2-12.5z m-12.5 0l-11.3 12.5 11.3 12.5 3.7-3.7-8.7-8.8 8.7-8.7-3.7-3.8z"></path></g></svg></a></h1><div><p>Iterates over all content routers in parallel to notify it is
</div><divdata-radium="true"><h4>Parameters</h4><olstyle="list-style:none;margin-left:0;padding-left:0;"data-radium="true"><divdata-radium="true"><listyle="padding-bottom:13px;"data-radium="true"><code>key: CID</code>: <divstyle="display:inline-block;"data-radium="true">The CID key of the content to find
</div></li></div><divdata-radium="true"><listyle="padding-bottom:13px;"data-radium="true"><code>callback: function (<ahref="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error">Error</a>)</code>: <divstyle="display:inline-block;"data-radium="true"></div></li></div></ol></div><divdata-radium="true"><h4>Returns</h4><divdata-radium="true"><code>void</code><span>