libp2p / js-libp2p

The JavaScript Implementation of libp2p networking stack.
https://libp2p.github.io/js-libp2p/
Other
2.33k stars 445 forks source link

Clarify readme "bundles" section #231

Closed ghost closed 4 years ago

ghost commented 6 years ago

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

Isan-Rivkin commented 6 years ago

It's me on the IRC and agreed :D

Mr0grog commented 6 years ago

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 working libp2p 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. The libp2p project contains packages that implement all of these, but it’s up to you to import those packages and send them to the js-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:

^ 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:

  1. Directly create a libp2p instance (instead of a constructor that creates instances with default options).
  2. Starts the instance.
  3. Does something simple, like pinging or dialing a peer.
  4. Stops the instance. (Side note: does that gracefully hang up on connected peers, or would a good example do that before stopping?)
Mr0grog commented 6 years ago

Or maybe “Composable Functionality” as a title instead?

vasco-santos commented 4 years ago

We don't use the bundles name anymore, so I am going to close this