js-libp2p

repository·main·Indexed 25 days ago

https://github.com/libp2p/js-libp2p

A JavaScript implementation of libp2p, a modular peer-to-peer network stack. It provides Prometheus-compatible metrics for monitoring and supports various transports for browser nodes, including WebSockets, WebRTC, and WebTransport. The library includes a suite of packages such as @libp2p/crypto, @libp2p/tls, @libp2p/config, and @libp2p/floodsub, and utilizes Circuit Relays and Delegate Nodes to overcome connectivity limitations in constrained environments.

Tokens
112.6K
Snippets
331
Records
613
Agent score
81%

What's inside js-libp2p

  1. Overview of libp2p configuration

    main

    libp2p is a modular networking stack designed to be customized to specific project needs. Configuration allows you to include only the modules required for your application (e.g., specific transports, peer discovery mechanisms, or pubsub implementations).

    Important Note: While the top-level API remains consistent regardless of your configuration, attempting to call methods for modules that have not been configured (such as Content Routing) will result in errors.

  2. What is the DCUtR protocol?

    main
    Direct Connection Upgrade through Relay (DCUtR) is a protocol designed to allow two nodes to establish a direct connection even if they are behind NATed connections or firewalls. It works by establishing a relayed connection first and then using the relay to synchronize connection timings, allowing both peers to dial each other at the same moment to facilitate a direct upgrade.
  3. What is @libp2p/floodsub and when to use it

    main

    @libp2p/floodsub (also known as pubsub-flood or dumbsub) is a naive implementation of the Publish/Subscribe pattern. It works by broadcasting all messages to all network peers (flooding the network) without forming a CastTree.

    Warning: Do not use this in production.

    This module is intended for academic purposes only because:

    • It broadcasts all messages to all network peers.
    • It cannot provide older messages.
    • It has no protection against bad actors.

    For production use cases, use gossipsub instead, which is a more complete implementation and is compatible with floodsub.

  4. What is the Identify protocol?

    main

    The Identify protocol allows network peers to discover the multiaddrs the current node listens on and the protocols it supports.

    Additionally, the identify/push extension allows the node to proactively send updates to all connected peers when its multiaddrs or protocols change. For maximum network compatibility, you should configure both protocols.