New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

libp2p

Package Overview
Dependencies
Maintainers
1
Versions
1095
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

libp2p

JavaScript implementation of libp2p, a modular peer to peer network stack

0.27.0-pre.0
Source
npm
Version published
Weekly downloads
37K
29.15%
Maintainers
1
Weekly downloads
 
Created
Source

libp2p hex logo

The JavaScript implementation of the libp2p Networking Stack.



Project status

We've come a long way, but this project is still in Alpha, lots of development is happening, API might change, beware of the Dragons 🐉..

Want to get started? Check our examples folder.

Weekly Core Dev Calls

Tech Lead

David Dias

Lead Maintainer

Jacob Heun

Table of Contents

Background

libp2p is the product of a long and arduous quest to understand the evolution of the Internet networking stack. In order to build P2P applications, devs have long had to make custom ad-hoc solutions to fit their needs, sometimes making some hard assumptions about their runtimes and the state of the network at the time of their development. Today, looking back more than 20 years, we see a clear pattern in the types of mechanisms built around the Internet Protocol, IP, which can be found throughout many layers of the OSI layer system, libp2p distils these mechanisms into flat categories and defines clear interfaces that once exposed, enable other protocols and applications to use and swap them, enabling upgradability and adaptability for the runtime, without breaking the API.

We are in the process of writing better documentation, blog posts, tutorials and a formal specification. Today you can find:

To sum up, libp2p is a "network stack" -- a protocol suite -- that cleanly separates concerns, and enables sophisticated applications to only use the protocols they absolutely need, without giving up interoperability and upgradeability. libp2p grew out of IPFS, but it is built so that lots of people can use it, for lots of different projects.

Bundles

With its modular nature, libp2p can be found being used in different projects with different sets of features, while preserving the same top level API. js-libp2p is only a skeleton and should not be installed directly, if you are looking for a prebundled libp2p stack, please check:

If you have developed a libp2p bundle, please consider submitting it to this list so that it can be found easily by the users of libp2p.

Install

Again, as noted above, this module is only a skeleton and should not be used directly other than libp2p bundle implementors that want to extend its code.

npm install --save libp2p

Usage

IMPORTANT NOTE: We are currently on the way of migrating all our libp2p modules to use async await and async iterators, instead of callbacks and pull-streams. As a consequence, when you start a new libp2p project, we must check which versions of the modules you should use. For now, it is required to use the modules using callbacks with libp2p, while we are working on getting the remaining modules ready for a full migration. For more details, you can have a look at libp2p/js-libp2p#266.

Tutorials and Examples

You can find multiple examples on the examples folder that will guide you through using libp2p for several scenarios.

Creating your own libp2p bundle

The libp2p module acts as a glue for every libp2p module that you can use to create your own libp2p bundle. Creating your own libp2p bundle gives you a lot of freedom when it comes to customize it with features and default setup. We recommend creating your own libp2p bundle for the app you are developing that takes into account your needs (e.g. for a browser working version of libp2p that acts as the network layer of IPFS, we have built one that leverages the Browser transports).

Example:

// Creating a bundle that adds:
//   transport: websockets + tcp
//   stream-muxing: spdy & mplex
//   crypto-channel: secio
//   discovery: multicast-dns

const Libp2p = require('libp2p')
const TCP = require('libp2p-tcp')
const WS = require('libp2p-websockets')
const SPDY = require('libp2p-spdy')
const MPLEX = require('libp2p-mplex')
const SECIO = require('libp2p-secio')
const MulticastDNS = require('libp2p-mdns')
const DHT = require('libp2p-kad-dht')
const GossipSub = require('libp2p-gossipsub')
const defaultsDeep = require('@nodeutils/defaults-deep')
const Protector = require('libp2p/src/pnet')
const DelegatedPeerRouter = require('libp2p-delegated-peer-routing')
const DelegatedContentRouter = require('libp2p-delegated-content-routing')

class Node extends Libp2p {
  constructor (_options) {
    const peerInfo = _options.peerInfo
    const defaults = {
      // The libp2p modules for this libp2p bundle
      modules: {
        transport: [
          TCP,
          new WS()                    // It can take instances too!
        ],
        streamMuxer: [
          SPDY,
          MPLEX
        ],
        connEncryption: [
          SECIO
        ],
        /** Encryption for private networks. Needs additional private key to work **/
        // connProtector: new Protector(/*protector specific opts*/),
        /** Enable custom content routers, such as delegated routing **/
        // contentRouting: [
        //   new DelegatedContentRouter(peerInfo.id)
        // ],
        /** Enable custom peer routers, such as delegated routing **/
        // peerRouting: [
        //   new DelegatedPeerRouter()
        // ],
        peerDiscovery: [
          MulticastDNS
        ],
        dht: DHT,                      // DHT enables PeerRouting, ContentRouting and DHT itself components
        pubsub: GossipSub
      },

      // libp2p config options (typically found on a config.json)
      config: {                       // The config object is the part of the config that can go into a file, config.json.
        peerDiscovery: {
          autoDial: true,             // Auto connect to discovered peers (limited by ConnectionManager minPeers)
          mdns: {                     // mdns options
            interval: 1000,           // ms
            enabled: true
          },
          webrtcStar: {               // webrtc-star options
            interval: 1000,           // ms
            enabled: false
          }
          // .. other discovery module options.
        },
        relay: {                      // Circuit Relay options
          enabled: true,
          hop: {
            enabled: false,
            active: false
          }
        },
        dht: {
          kBucketSize: 20,
          enabled: true,
          randomWalk: {
            enabled: true,      // Allows to disable discovery (enabled by default)
            interval: 300e3,
            timeout: 10e3
          }
        },
        pubsub: {
          enabled: true,
          emitSelf: true,      // whether the node should emit to self on publish, in the event of the topic being subscribed
          signMessages: true,  // if messages should be signed
          strictSigning: true  // if message signing should be required
        }
      }
    }

    // overload any defaults of your bundle using https://github.com/nodeutils/defaults-deep
    super(defaultsDeep(_options, defaults))
  }
}

// Now all the nodes you create, will have TCP, WebSockets, SPDY, MPLEX, SECIO and MulticastDNS support.

API

See API.md.

Development

Clone and install dependencies:

> git clone https://github.com/libp2p/js-libp2p.git
> cd js-libp2p
> npm install

Tests

Run unit tests
# run all the unit tsts
> npm test

# run just Node.js tests
> npm run test:node

# run just Browser tests (Chrome)
> npm run test:browser

Packages

List of packages currently in existence for libp2p

This table is generated using the module package-table with package-table --data=package-list.json.

PackageVersionDepsCICoverageLead Maintainer
libp2p
libp2pnpmDepsTravis CIcodecovJacob Heun
libp2p-daemonnpmDepsTravis CIcodecovJacob Heun
libp2p-daemon-clientnpmDepsTravis CIcodecovN/A
libp2p-interfacesnpmDepsTravis CIcodecovN/A
interop-libp2pnpmDepsTravis CIcodecovN/A
transports
libp2p-tcpnpmDepsTravis CIcodecovN/A
libp2p-utpnpmDepsTravis CIcodecovN/A
libp2p-webrtc-directnpmDepsTravis CIcodecovN/A
libp2p-webrtc-starnpmDepsTravis CIcodecovVasco Santos
libp2p-websocketsnpmDepsTravis CIcodecovJacob Heun
libp2p-websocket-starnpmDepsTravis CIcodecovJacob Heun
secure channels
libp2p-secionpmDepsTravis CIcodecovFriedel Ziegelmayer
stream multiplexers
libp2p-mplexnpmDepsTravis CIcodecovVasco Santos
libp2p-spdynpmDepsTravis CIcodecovJacob Heun
peer discovery
libp2p-bootstrapnpmDepsTravis CIcodecovVasco Santos
libp2p-kad-dhtnpmDepsTravis CIcodecovVasco Santos
libp2p-mdnsnpmDepsTravis CIcodecovJacob Heun
libp2p-rendezvousnpmDepsTravis CIcodecovN/A
libp2p-webrtc-starnpmDepsTravis CIcodecovVasco Santos
libp2p-websocket-starnpmDepsTravis CIcodecovJacob Heun
content routing
libp2p-delegated-content-routingnpmDepsTravis CIcodecovN/A
libp2p-kad-dhtnpmDepsTravis CIcodecovVasco Santos
peer routing
libp2p-delegated-peer-routingnpmDepsTravis CIcodecovN/A
libp2p-kad-dhtnpmDepsTravis CIcodecovVasco Santos
utilities
libp2p-cryptonpmDepsTravis CIcodecovJacob Heun
libp2p-crypto-secp256k1npmDepsTravis CIcodecovFriedel Ziegelmayer
data types
peer-booknpmDepsTravis CIcodecovN/A
peer-idnpmDepsTravis CIcodecovN/A
peer-infonpmDepsTravis CIcodecovVasco Santos
pubsub
libp2p-pubsubnpmDepsTravis CIcodecovVasco Santos
libp2p-floodsubnpmDepsTravis CIcodecovN/A
libp2p-gossipsubnpmDepsTravis CIcodecovN/A
extensions
libp2p-nat-mgnrnpmDepsTravis CIcodecovN/A
libp2p-utilsnpmDepsTravis CIcodecovVasco Santos

Contribute

The libp2p implementation in JavaScript is a work in progress. As such, there are a few things you can do right now to help out:

  • Go through the modules and check out existing issues. This would be especially useful for modules in active development. Some knowledge of IPFS/libp2p may be required, as well as the infrastructure behind it - for instance, you may need to read up on p2p and more complex operations like muxing to be able to help technically.
  • Perform code reviews. Most of this has been developed by @diasdavid, which means that more eyes will help a) speed the project along b) ensure quality and c) reduce possible future bugs.
  • Add tests. There can never be enough tests.

License

MIT © Protocol Labs

Keywords

libp2p

FAQs

Package last updated on 12 Dec 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts