mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-03-30 22:31:03 +00:00
* refactor: add js-libp2p-connection-manager to repo Co-authored-by: David Dias <daviddias.p@gmail.com> Co-authored-by: Jacob Heun <jacobheun@gmail.com> Co-authored-by: Pedro Teixeira <i@pgte.me> Co-authored-by: Vasco Santos <vasco.santos@ua.pt> * test(conn-mgr): only run in node * refactor: add js-libp2p-identify to repo Co-authored-by: David Dias <daviddias.p@gmail.com> Co-authored-by: Friedel Ziegelmayer <dignifiedquire@gmail.com> Co-authored-by: Hugo Dias <hugomrdias@gmail.com> Co-authored-by: Jacob Heun <jacobheun@gmail.com> Co-authored-by: Maciej Krüger <mkg20001@gmail.com> Co-authored-by: Richard Littauer <richard.littauer@gmail.com> Co-authored-by: Vasco Santos <vasco.santos@moxy.studio> Co-authored-by: Yusef Napora <yusef@protocol.ai> Co-authored-by: ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com> * refactor: add libp2p-pnet to repo Co-authored-by: Jacob Heun <jacobheun@gmail.com> Co-authored-by: Vasco Santos <vasco.santos@moxy.studio> * refactor: add libp2p-ping to repo Co-authored-by: David Dias <daviddias.p@gmail.com> Co-authored-by: Francisco Baio Dias <xicombd@gmail.com> Co-authored-by: Friedel Ziegelmayer <dignifiedquire@gmail.com> Co-authored-by: Hugo Dias <mail@hugodias.me> Co-authored-by: Jacob Heun <jacobheun@gmail.com> Co-authored-by: João Antunes <j.goncalo.antunes@gmail.com> Co-authored-by: Richard Littauer <richard.littauer@gmail.com> Co-authored-by: Vasco Santos <vasco.santos@moxy.studio> Co-authored-by: Vasco Santos <vasco.santos@ua.pt> Co-authored-by: ᴠɪᴄᴛᴏʀ ʙᴊᴇʟᴋʜᴏʟᴍ <victorbjelkholm@gmail.com> * refactor: add libp2p-circuit to repo Co-authored-by: David Dias <daviddias.p@gmail.com> Co-authored-by: Dmitriy Ryajov <dryajov@gmail.com> Co-authored-by: Friedel Ziegelmayer <dignifiedquire@gmail.com> Co-authored-by: Hugo Dias <mail@hugodias.me> Co-authored-by: Jacob Heun <jacobheun@gmail.com> Co-authored-by: Maciej Krüger <mkg20001@gmail.com> Co-authored-by: Oli Evans <oli@tableflip.io> Co-authored-by: Pedro Teixeira <i@pgte.me> Co-authored-by: Vasco Santos <vasco.santos@ua.pt> Co-authored-by: Victor Bjelkholm <victorbjelkholm@gmail.com> Co-authored-by: Yusef Napora <yusef@napora.org> Co-authored-by: dirkmc <dirk@mccormick.cx> * test(switch): avoid using instanceof * chore(switch): update bignumber dep * refactor(circuit): clean up tests * refactor(switch): consolidate get peer utils * test(identify): do deep checks of addresses * test(identify): bump timeout for identify test * test(switch): tidy up limit dialer test * refactor(switch): remove redundant circuit tests * chore: add coverage script * refactor(circuit): consolidate get peer info * docs: reference original repositories in each sub readme * docs: fix comment * refactor: clean up sub package.json files and readmes
61 lines
2.2 KiB
JavaScript
61 lines
2.2 KiB
JavaScript
'use strict'
|
|
|
|
const Libp2p = require('libp2p')
|
|
const TCP = require('libp2p-tcp')
|
|
const MPLEX = require('libp2p-mplex')
|
|
const SECIO = require('libp2p-secio')
|
|
const fs = require('fs')
|
|
const Protector = require('libp2p-pnet')
|
|
|
|
/**
|
|
* Options for the libp2p bundle
|
|
* @typedef {Object} libp2pBundle~options
|
|
* @property {PeerInfo} peerInfo - The PeerInfo of the IPFS node
|
|
* @property {PeerBook} peerBook - The PeerBook of the IPFS node
|
|
* @property {Object} config - The config of the IPFS node
|
|
* @property {Object} options - The options given to the IPFS node
|
|
*/
|
|
|
|
/**
|
|
* privateLibp2pBundle returns a libp2p bundle function that will use the swarm
|
|
* key at the given `swarmKeyPath` to create the Protector
|
|
*
|
|
* @param {string} swarmKeyPath The path to our swarm key
|
|
* @returns {libp2pBundle} Returns a libp2pBundle function for use in IPFS creation
|
|
*/
|
|
const privateLibp2pBundle = (swarmKeyPath) => {
|
|
/**
|
|
* This is the bundle we will use to create our fully customized libp2p bundle.
|
|
*
|
|
* @param {libp2pBundle~options} opts The options to use when generating the libp2p node
|
|
* @returns {Libp2p} Our new libp2p node
|
|
*/
|
|
const libp2pBundle = (opts) => {
|
|
// Set convenience variables to clearly showcase some of the useful things that are available
|
|
const peerInfo = opts.peerInfo
|
|
const peerBook = opts.peerBook
|
|
|
|
// Build and return our libp2p node
|
|
return new Libp2p({
|
|
peerInfo,
|
|
peerBook,
|
|
modules: {
|
|
transport: [TCP], // We're only using the TCP transport for this example
|
|
streamMuxer: [MPLEX], // We're only using mplex muxing
|
|
// Let's make sure to use identifying crypto in our pnet since the protector doesn't
|
|
// care about node identity, and only the presence of private keys
|
|
connEncryption: [SECIO],
|
|
// Leave peer discovery empty, we don't want to find peers. We could omit the property, but it's
|
|
// being left in for explicit readability.
|
|
// We should explicitly dial pnet peers, or use a custom discovery service for finding nodes in our pnet
|
|
peerDiscovery: [],
|
|
connProtector: new Protector(fs.readFileSync(swarmKeyPath))
|
|
}
|
|
})
|
|
}
|
|
|
|
return libp2pBundle
|
|
}
|
|
|
|
module.exports = privateLibp2pBundle
|