Closed ghost closed 4 years ago
It's me on the IRC and agreed :D
Hmmm, what’s the story with the libp2p-ipfs-nodejs
and libp2p-ipfs-browser
links? They read like they should link to actual packages (which seemed surprising, since I know how js-ipfs uses libp2p), but then I clicked them and realized they just linked to js-ipfs’s internal configuration. Were these once intended to become wrapper packages of some sort? I definitely agree it’s confusing.
Are there any published “bundles” that wrap up groups of libp2p modules so you can just create an instance [of the bundle] instead of manually composing a bunch of libp2p parts? If not, I don’t think we should even call this section “bundles.” Maybe it could be “composing functionality” or something similar.
My take:
Composing Functionality
js-libp2p
itself is just a tool for plugging together different pieces of a peer-to-peer networking stack. To create a workinglibp2p
instance, you’ll need to select a set of transports (like TCP, WebSockets, etc.), multiplexers, encryption mechanisms, peer discovery mechanisms, and DHT implementations to use. Thelibp2p
project contains packages that implement all of these, but it’s up to you to import those packages and send them to thejs-libp2p
constructor.For example, you might use the TCP and WebSocket transports, MPLEX multiplexing, SecIO encryption, Multicast discovery, and Kademlia DHT:
const libp2p = require('libp2p') const TCP = require('libp2p-tcp') const WS = require('libp2p-websockets') const MPLEX = require('libp2p-mplex') const SECIO = require('libp2p-secio') const MulticastDNS = require('libp2p-mdns') const KademliaDHT = require('libp2p-kad-dht') const p2pInstance = new libp2p({ modules: { transport: [ TCP, new WS() ], streamMuxer: [ MPLEX ], connEncryption: [ SECIO ], peerDiscovery: [ MulticastDNS ], dht: KademliaDHT } })
See the packages section below for a list of officially maintained packages you can use to configure an instance.
You can also check out how
js-ipfs
creates a Libp2p constructor with different standard defaults for different environments here:
- Node.js version
- Browser version, which doesn’t use TCP or Multicast, but does use WebRTC, a browser-specific technology.
^ Not sure if this is a great set of choices for an example. I am 100% sure other people have more expert opinions here. That code is also untested, so I’m not even sure if works :P
I also think the usage example could use a lot of work here — it only demonstrates how to construct a libp2p
instance and doesn’t show how to use it. The constructor is also unnecessarily elaborate (looks like it’s just a copy of the one from js-ipfs) and doesn’t make it especially clear what’s happening. In fact, it’s not even quite complete because it requires a PeerInfo
and PeerBook
instance without showing what they are or how to create them :\
A better example might:
libp2p
instance (instead of a constructor that creates instances with default options).Or maybe “Composable Functionality” as a title instead?
We don't use the bundles name anymore, so I am going to close this
We just had someone in IRC confused about the relationship between the bundles and js-libp2p. I feel like the section should avoid the word skeleton, which sounds like death and lack of substance, and feels more like a quantification of project status vs. a qualification of the js-libp2p repo's function within the js-libp2p project.
Instead it should probably say something like:
(I think the concept of bundles generally needs clarification and rethinking. Maybe "snippets" get closer to what we're trying to achieve there.)
cc @Mr0grog