libp2p
Version:
JavaScript implementation of libp2p, a modular peer to peer network stack
162 lines (117 loc) • 44.9 kB
Markdown
<h1 align="center">
<a href="https://libp2p.io"><img width="250" src="https://github.com/libp2p/js-libp2p/blob/main/img/libp2p.png?raw=true" alt="libp2p hex logo" /></a>
</h1>
<h3 align="center">The JavaScript implementation of the libp2p Networking Stack</h3>
[](http://libp2p.io/)
[](https://www.npmjs.com/package/libp2p)
[](https://discuss.libp2p.io)
[](http://webchat.freenode.net/?channels=%23libp2p)
[](https://discord.com/invite/Ae4TbahHaT)
[](https://codecov.io/gh/libp2p/js-libp2p)
[](https://github.com/libp2p/js-libp2p/actions/workflows/main.yml?query=branch%3Amain)
# 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:
- [libp2p.io](https://libp2p.io)
- [docs.libp2p.io](https://docs.libp2p.io)
- [Specification (WIP)](https://github.com/libp2p/specs)
- [Discussion Forums](https://discuss.libp2p.io)
- Talks
- [`libp2p <3 ethereum` at DEVCON2](https://archive.devcon.org/archive/watch/2/libp2p-devp2p-ipfs-and-ethereum-networking/)
- Articles
- [The overview of libp2p](https://github.com/libp2p/libp2p#description)
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 upgradability. libp2p grew out of IPFS, but it is built so that lots of people can use it, for lots of different projects.
# Roadmap
The js-libp2p roadmap can be found here: <https://github.com/libp2p/js-libp2p/blob/main/ROADMAP.md>
It represents current projects the js-libp2p maintainers are focused on and provides an estimation of completion targets.
# Usage
### Configuration
For all the information on how you can configure libp2p see [CONFIGURATION.md](https://github.com/libp2p/js-libp2p/blob/main/doc/CONFIGURATION.md).
## Limits
For help configuring your node to resist malicious network peers, see [LIMITS.md](https://github.com/libp2p/js-libp2p/blob/main/doc/LIMITS.md)
## Getting started
If you are starting your journey with `js-libp2p`, read the [GETTING\_STARTED.md](https://github.com/libp2p/js-libp2p/blob/main/doc/GETTING_STARTED.md) guide.
## Tutorials and Examples
You can find multiple examples on the [examples repo](https://github.com/libp2p/js-libp2p-examples) that will guide you through using libp2p for several scenarios.
# Development
**Clone and install dependencies:**
```sh
> git clone https://github.com/libp2p/js-libp2p.git
> cd js-libp2p
> npm install
> npm run build
```
# Tests
## Run unit tests
```sh
# run all the unit tests
> npm test
# run just Node.js tests
> npm run test:node
# run just Browser tests (Chrome)
> npm run test:chrome
```
# 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`.
| Package | Version | Deps | CI | Coverage |
| ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **libp2p** | | | | |
| [`libp2p`](//github.com/libp2p/js-libp2p) | [](//github.com/libp2p/js-libp2p/releases) | [](//libraries.io/npm/libp2p) | [](//github.com/libp2p/js-libp2p/actions?query=branch%3Amain+workflow%3Aci+) | [](https://codecov.io/gh/libp2p/js-libp2p) |
| [`@libp2p/interface`](//github.com/libp2p/js-libp2p/tree/main/packages/interface) | [](//github.com/libp2p/js-libp2p/tree/main/packages/interface/releases) | [](//libraries.io/npm/%40libp2p%2Finterface) | [](//github.com/libp2p/js-libp2p/tree/main/packages/interface/actions?query=branch%3Amain+workflow%3Aci+) | [](https://codecov.io/gh/libp2p/js-libp2p/tree/main/packages/interface) |
| **transports** | | | | |
| [`@libp2p/tcp`](//github.com/libp2p/js-libp2p/tree/main/packages/transport-tcp) | [](//github.com/libp2p/js-libp2p/tree/main/packages/transport-tcp/releases) | [](//libraries.io/npm/%40libp2p%2Ftcp) | [](//github.com/libp2p/js-libp2p/tree/main/packages/transport-tcp/actions?query=branch%3Amain+workflow%3Aci+) | [](https://codecov.io/gh/libp2p/js-libp2p/tree/main/packages/transport-tcp) |
| [`@libp2p/webrtc`](//github.com/libp2p/js-libp2p/tree/main/packages/transport-webrtc) | [](//github.com/libp2p/js-libp2p/tree/main/packages/transport-webrtc/releases) | [](//libraries.io/npm/%40libp2p%2Fwebrtc) | [](//github.com/libp2p/js-libp2p/tree/main/packages/transport-webrtc/actions?query=branch%3Amain+workflow%3Aci+) | [](https://codecov.io/gh/libp2p/js-libp2p/tree/main/packages/transport-webrtc) |
| [`@libp2p/websockets`](//github.com/libp2p/js-libp2p/tree/main/packages/transport-websockets) | [](//github.com/libp2p/js-libp2p/tree/main/packages/transport-websockets/releases) | [](//libraries.io/npm/%40libp2p%2Fwebsockets) | [](//github.com/libp2p/js-libp2p/tree/main/packages/transport-websockets/actions?query=branch%3Amain+workflow%3Aci+) | [](https://codecov.io/gh/libp2p/js-libp2p/tree/main/packages/transport-websockets) |
| [`@libp2p/webtransport`](//github.com/libp2p/js-libp2p/tree/main/packages/transport-webtransport) | [](//github.com/libp2p/js-libp2p/tree/main/packages/transport-webtransport/releases) | [](//libraries.io/npm/%40libp2p%2Fwebtransport) | [](//github.com/libp2p/js-libp2p/tree/main/packages/transport-webtransport/actions?query=branch%3Amain+workflow%3Aci+) | [](https://codecov.io/gh/libp2p/js-libp2p/tree/main/packages/transport-webtransport) |
| **secure channels** | | | | |
| [`@chainsafe/libp2p-noise`](//github.com/ChainSafe/js-libp2p-noise) | [](//github.com/ChainSafe/js-libp2p-noise/releases) | [](//libraries.io/npm/%40chainsafe%2Flibp2p-noise) | [](//github.com/ChainSafe/js-libp2p-noise/actions?query=branch%3Amaster+workflow%3Aci+) | [](https://codecov.io/gh/ChainSafe/js-libp2p-noise) |
| [`@libp2p/plaintext`](//github.com/libp2p/js-libp2p/tree/main/packages/connection-encrypter-plaintext) | [](//github.com/libp2p/js-libp2p/tree/main/packages/connection-encrypter-plaintext/releases) | [](//libraries.io/npm/%40libp2p%2Fplaintext) | [](//github.com/libp2p/js-libp2p/tree/main/packages/connection-encrypter-plaintext/actions?query=branch%3Amain+workflow%3Aci+) | [](https://codecov.io/gh/libp2p/js-libp2p/tree/main/packages/connection-encrypter-plaintext) |
| **stream multiplexers** | | | | |
| [`@libp2p/mplex`](//github.com/libp2p/js-libp2p/tree/main/packages/stream-multiplexer-mplex) | [](//github.com/libp2p/js-libp2p/tree/main/packages/stream-multiplexer-mplex/releases) | [](//libraries.io/npm/%40libp2p%2Fmplex) | [](//github.com/libp2p/js-libp2p/tree/main/packages/stream-multiplexer-mplex/actions?query=branch%3Amain+workflow%3Aci+) | [](https://codecov.io/gh/libp2p/js-libp2p/tree/main/packages/stream-multiplexer-mplex) |
| [`@chainsafe/libp2p-yamux`](//github.com/ChainSafe/js-libp2p-yamux) | [](//github.com/ChainSafe/js-libp2p-yamux/releases) | [](//libraries.io/npm/%40chainsafe%2Flibp2p-yamux) | [](//github.com/ChainSafe/js-libp2p-yamux/actions?query=branch%3Amaster+workflow%3Aci+) | [](https://codecov.io/gh/ChainSafe/js-libp2p-yamux) |
| **peer discovery** | | | | |
| [`@libp2p/bootstrap`](//github.com/libp2p/js-libp2p/tree/main/packages/peer-discovery-bootstrap) | [](//github.com/libp2p/js-libp2p/tree/main/packages/peer-discovery-bootstrap/releases) | [](//libraries.io/npm/%40libp2p%2Fbootstrap) | [](//github.com/libp2p/js-libp2p/tree/main/packages/peer-discovery-bootstrap/actions?query=branch%3Amain+workflow%3Aci+) | [](https://codecov.io/gh/libp2p/js-libp2p/tree/main/packages/peer-discovery-bootstrap) |
| [`@libp2p/kad-dht`](//github.com/libp2p/js-libp2p/tree/main/packages/kad-dht) | [](//github.com/libp2p/js-libp2p/tree/main/packages/kad-dht/releases) | [](//libraries.io/npm/%40libp2p%2Fkad-dht) | [](//github.com/libp2p/js-libp2p/tree/main/packages/kad-dht/actions?query=branch%3Amain+workflow%3Aci+) | [](https://codecov.io/gh/libp2p/js-libp2p/tree/main/packages/kad-dht) |
| [`@libp2p/mdns`](//github.com/libp2p/js-libp2p/tree/main/packages/peer-discovery-mdns) | [](//github.com/libp2p/js-libp2p/tree/main/packages/peer-discovery-mdns/releases) | [](//libraries.io/npm/%40libp2p%2Fmdns) | [](//github.com/libp2p/js-libp2p/tree/main/packages/peer-discovery-mdns/actions?query=branch%3Amain+workflow%3Aci+) | [](https://codecov.io/gh/libp2p/js-libp2p/tree/main/packages/peer-discovery-mdns) |
| [`@chainsafe/discv5`](//github.com/ChainSafe/discv5) | [](//github.com/ChainSafe/discv5/releases) | [](//libraries.io/npm/%40chainsafe%2Fdiscv5) | [](//github.com/ChainSafe/discv5/actions?query=branch%3Amaster+workflow%3Aci+) | [](https://codecov.io/gh/ChainSafe/discv5) |
| **content routing** | | | | |
| [`@libp2p/http-v1-content-routing`](//github.com/libp2p/js-http-v1-content-routing) | [](//github.com/libp2p/js-http-v1-content-routing/releases) | [](//libraries.io/npm/%40libp2p%2Fhttp-v1-content-routing) | [](//github.com/libp2p/js-http-v1-content-routing/actions?query=branch%3Amain+workflow%3Aci+) | [](https://codecov.io/gh/libp2p/js-http-v1-content-routing) |
| [`@libp2p/delegated-content-routing`](//github.com/libp2p/js-libp2p-delegated-content-routing) | [](//github.com/libp2p/js-libp2p-delegated-content-routing/releases) | [](//libraries.io/npm/%40libp2p%2Fdelegated-content-routing) | [](//github.com/libp2p/js-libp2p-delegated-content-routing/actions?query=branch%3Amaster+workflow%3Aci+) | [](https://codecov.io/gh/libp2p/js-libp2p-delegated-content-routing) |
| [`@libp2p/kad-dht`](//github.com/libp2p/js-libp2p/tree/main/packages/kad-dht) | [](//github.com/libp2p/js-libp2p/tree/main/packages/kad-dht/releases) | [](//libraries.io/npm/%40libp2p%2Fkad-dht) | [](//github.com/libp2p/js-libp2p/tree/main/packages/kad-dht/actions?query=branch%3Amain+workflow%3Aci+) | [](https://codecov.io/gh/libp2p/js-libp2p/tree/main/packages/kad-dht) |
| **peer routing** | | | | |
| [`@libp2p/delegated-peer-routing`](//github.com/libp2p/js-libp2p-delegated-peer-routing) | [](//github.com/libp2p/js-libp2p-delegated-peer-routing/releases) | [](//libraries.io/npm/%40libp2p%2Fdelegated-peer-routing) | [](//github.com/libp2p/js-libp2p-delegated-peer-routing/actions?query=branch%3Amaster+workflow%3Aci+) | [](https://codecov.io/gh/libp2p/js-libp2p-delegated-peer-routing) |
| [`@libp2p/kad-dht`](//github.com/libp2p/js-libp2p/tree/main/packages/kad-dht) | [](//github.com/libp2p/js-libp2p/tree/main/packages/kad-dht/releases) | [](//libraries.io/npm/%40libp2p%2Fkad-dht) | [](//github.com/libp2p/js-libp2p/tree/main/packages/kad-dht/actions?query=branch%3Amain+workflow%3Aci+) | [](https://codecov.io/gh/libp2p/js-libp2p/tree/main/packages/kad-dht) |
| **utilities** | | | | |
| [`@libp2p/crypto`](//github.com/libp2p/js-libp2p/tree/main/packages/crypto) | [](//github.com/libp2p/js-libp2p/tree/main/packages/crypto/releases) | [](//libraries.io/npm/%40libp2p%2Fcrypto) | [](//github.com/libp2p/js-libp2p/tree/main/packages/crypto/actions?query=branch%3Amain+workflow%3Aci+) | [](https://codecov.io/gh/libp2p/js-libp2p/tree/main/packages/crypto) |
| **data types** | | | | |
| [`@libp2p/peer-id`](//github.com/libp2p/js-libp2p/tree/main/packages/peer-id) | [](//github.com/libp2p/js-libp2p/tree/main/packages/peer-id/releases) | [](//libraries.io/npm/%40libp2p%2Fpeer-id) | [](//github.com/libp2p/js-libp2p/tree/main/packages/peer-id/actions?query=branch%3Amain+workflow%3Aci+) | [](https://codecov.io/gh/libp2p/js-libp2p/tree/main/packages/peer-id) |
| [`@libp2p/peer-record`](//github.com/libp2p/js-libp2p/tree/main/packages/peer-record) | [](//github.com/libp2p/js-libp2p/tree/main/packages/peer-record/releases) | [](//libraries.io/npm/%40libp2p%2Fpeer-record) | [](//github.com/libp2p/js-libp2p/tree/main/packages/peer-record/actions?query=branch%3Amain+workflow%3Aci+) | [](https://codecov.io/gh/libp2p/js-libp2p/tree/main/packages/peer-record) |
| **pubsub** | | | | |
| [`@ChainSafe/libp2p-gossipsub`](//github.com/ChainSafe/js-libp2p-gossipsub) | [](//github.com/ChainSafe/js-libp2p-gossipsub/releases) | [](//libraries.io/npm/%40ChainSafe%2Flibp2p-gossipsub) | [](//github.com/ChainSafe/js-libp2p-gossipsub/actions?query=branch%3Amaster+workflow%3Aci+) | [](https://codecov.io/gh/ChainSafe/js-libp2p-gossipsub) |
| [`@libp2p/floodsub`](//github.com/libp2p/js-libp2p/tree/main/packages/pubsub-floodsub) | [](//github.com/libp2p/js-libp2p/tree/main/packages/pubsub-floodsub/releases) | [](//libraries.io/npm/%40libp2p%2Ffloodsub) | [](//github.com/libp2p/js-libp2p/tree/main/packages/pubsub-floodsub/actions?query=branch%3Amain+workflow%3Aci+) | [](https://codecov.io/gh/libp2p/js-libp2p/tree/main/packages/pubsub-floodsub) |
# Used by
<div style="padding: 20px">
<p align="middle">
<a href="https://lodestar.chainsafe.io/"><img width="300" src="https://github.com/ChainSafe/lodestar/blob/unstable/assets/lodestar_icon_text_black_stroke.png?raw=true"></a>
<a href="https://hoprnet.org/"><img width="150" src="https://github.com/hoprnet/hopr-assets/blob/master/v1/logo/hopr_logo_padded.png?raw=true" alt="HOPR Logo">
<a href="https://helia.io/"><img src="https://raw.githubusercontent.com/ipfs/helia/main/assets/helia.png" alt="Helia logo" width="150" /></a>
<a href="https://github.com/orbitdb/orbitdb"><img src="https://avatars.githubusercontent.com/u/25079463?s=200&v=4" alt="OrbitDB logo" width="150" /></a>
<a href="https://waku.org/"><img src="https://avatars.githubusercontent.com/u/107703624?s=200&v=4" alt="Waku" width="150" /></a>
<a href="https://peerbit.org/"><img src="https://github.com/dao-xyz/peerbit/blob/master/docs/peerbit-logo.png" alt="Peerbit logo" width="150" /></a>
</p>
</div>
And [many others...](https://github.com/libp2p/js-libp2p/network/dependents)
# 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**. 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.
# API Docs
- <https://libp2p.github.io/js-libp2p/modules/libp2p.html>
# License
Licensed under either of
- Apache 2.0, ([LICENSE-APACHE](https://github.com/libp2p/js-libp2p/blob/main/packages/libp2p/LICENSE-APACHE) / <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT ([LICENSE-MIT](https://github.com/libp2p/js-libp2p/blob/main/packages/libp2p/LICENSE-MIT) / <http://opensource.org/licenses/MIT>)
# Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.