Skip to content

Commit

Permalink
Merge branch 'issue-1510' of https://github.com/acul71/js-libp2p-fork
Browse files Browse the repository at this point in the history
…into issue-1510
  • Loading branch information
acul71 committed Nov 7, 2024
2 parents 76cf02b + 3a8ab4f commit d268455
Show file tree
Hide file tree
Showing 160 changed files with 3,480 additions and 1,445 deletions.
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"packages/connection-encrypter-plaintext":"2.0.8","packages/connection-encrypter-tls":"2.0.8","packages/crypto":"5.0.5","packages/interface":"2.1.3","packages/interface-compliance-tests":"6.1.6","packages/interface-internal":"2.0.8","packages/kad-dht":"14.0.1","packages/keychain":"5.0.7","packages/libp2p":"2.1.9","packages/logger":"5.1.1","packages/metrics-devtools":"1.1.6","packages/metrics-prometheus":"4.2.2","packages/metrics-simple":"1.2.4","packages/multistream-select":"6.0.6","packages/peer-collections":"6.0.8","packages/peer-discovery-bootstrap":"11.0.8","packages/peer-discovery-mdns":"11.0.8","packages/peer-id":"5.0.5","packages/peer-record":"8.0.8","packages/peer-store":"11.0.8","packages/pnet":"2.0.8","packages/protocol-autonat":"2.0.8","packages/protocol-dcutr":"2.0.8","packages/protocol-echo":"2.0.8","packages/protocol-fetch":"2.0.8","packages/protocol-identify":"3.0.8","packages/protocol-perf":"4.0.8","packages/protocol-ping":"2.0.8","packages/pubsub":"10.0.8","packages/pubsub-floodsub":"10.1.6","packages/record":"4.0.4","packages/stream-multiplexer-mplex":"11.0.8","packages/transport-circuit-relay-v2":"2.1.5","packages/transport-tcp":"10.0.9","packages/transport-webrtc":"5.0.13","packages/transport-websockets":"9.0.8","packages/transport-webtransport":"5.0.13","packages/upnp-nat":"2.0.8","packages/utils":"6.1.1"}
{"packages/connection-encrypter-plaintext":"2.0.10","packages/connection-encrypter-tls":"2.0.10","packages/crypto":"5.0.6","packages/interface":"2.2.0","packages/interface-compliance-tests":"6.1.8","packages/interface-internal":"2.0.10","packages/kad-dht":"14.1.0","packages/keychain":"5.0.9","packages/libp2p":"2.2.1","packages/logger":"5.1.3","packages/metrics-devtools":"1.1.8","packages/metrics-prometheus":"4.2.4","packages/metrics-simple":"1.2.6","packages/multistream-select":"6.0.8","packages/peer-collections":"6.0.10","packages/peer-discovery-bootstrap":"11.0.10","packages/peer-discovery-mdns":"11.0.10","packages/peer-id":"5.0.7","packages/peer-record":"8.0.10","packages/peer-store":"11.0.10","packages/pnet":"2.0.10","packages/protocol-autonat":"2.0.10","packages/protocol-dcutr":"2.0.10","packages/protocol-echo":"2.1.1","packages/protocol-fetch":"2.0.10","packages/protocol-identify":"3.0.10","packages/protocol-perf":"4.0.10","packages/protocol-ping":"2.0.10","packages/pubsub":"10.0.10","packages/pubsub-floodsub":"10.1.8","packages/record":"4.0.4","packages/stream-multiplexer-mplex":"11.0.10","packages/transport-circuit-relay-v2":"3.1.0","packages/transport-tcp":"10.0.11","packages/transport-webrtc":"5.0.16","packages/transport-websockets":"9.0.11","packages/transport-webtransport":"5.0.16","packages/upnp-nat":"2.0.10","packages/utils":"6.1.3"}
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ If you are looking for the documentation of the latest release, you can view the
## Table of contents <!-- omit in toc -->

- [Background](#background)
- [Roadmap](#roadmap)
- [Install](#install)
- [Usage](#usage)
- [Configuration](#configuration)
Expand Down Expand Up @@ -83,6 +84,12 @@ We are in the process of writing better documentation, blog posts, tutorials and

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.

## 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.

## Install

```sh
Expand Down
91 changes: 91 additions & 0 deletions ROADMAP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# 🛣️ Roadmap 2024-H2/2025-H1

This roadmap document contains the themes upon which maintainer effort will be concentrated on in 2024/25.

## 👔 Productionization

js-libp2p is deployed in many production environments so to take adoption to the next level we want to really double down on helping these users get the best out of their deployments.

### js-libp2p amino DHT bootstrapper

Deploying a public bootstrapper is a great test of the capacity of js-libp2p since it will need to maintain several thousand simultaneous connections and service many DHT RPC requests. Comprehensive metrics and logging will also give us insight into real world usage patterns that can further direct performance optimisations.

- Deploy a bootstrap server that acts as an entry point to the network for DHT clients
- Ship it in the default config of majority libp2p/IPFS implementations
- Publish a dashboard showing usage statistics

### Metrics

Having a view on the internal workings of a js-libp2p node is essential to debugging implementation problems as well as user misconfigurations.

- Add the missing metrics types, e.g. Histograms, Summaries, etc
- Implement metrics consistently across transports

### DevTools

The [js-libp2p-devtools](https://github.com/libp2p/js-libp2p-devtools) plugin is an invaluable resource for debugging a running libp2p node running [@libp2p/devtools-metrics](https://npmjs.com/package/@libp2p/devtools-metrics).

- Finish UX improvements
- Publish to browser extension stores
- Add DHT capability detection
- Publish as standalone electron app to connect to Node.js/electron/react-native processes using `@libp2p/devtools-metrics`

### Tuning and reduction of resource usage

JavaScript is a poor choice of language in which to perform computationally expensive operations. Conveniently the ones we need to do (hashing, signing, verification) are largely implemented in native modules or as part of web browser APIs.

- Profile and benchmark CPU usage
- Use this to drive further optimizations in resource usage

## 📚 Documentation & developer onboarding

- Documentation refresh - ensure all guides are up to date and follow current best practices
- Revamp getting started guides
- Focus on use cases
- Browser vs Node.js
- Public server vs behind NAT
- Create additional self-directed learning in the style of [@libp2p/protocol-adventure](https://www.npmjs.com/package/@libp2p/protocol-adventure)
- @libp2p/services-adventure
- @libp2p/dht-adventure
- @libp2p/pubsub-adventure
- @libp2p/peer-discovery-adventure
- Link the adventure modules into a syllabus
- Publish browser based versions using protoschool or https://tutorialkit.dev/

## 🌐 Browser connectivity

Browsers remain the single most challenging environment in which to deploy truly decentralized applications and most of the issues are related to the poor connectivity options presented to browsers by the rest of the network.

### Listen on Secure WebSockets with libp2p.direct

IP Shipyard have recently acquired the ability to create wildcard ACME certificates under the `libp2p.direct` domain. This feature is being enabled in https://github.com/ipfs/kubo/pull/10521

JS should implement a similar extension to the `@libp2p/websocket` transport to allow config-free SSL encryption.

### WebSocket single encryption

When a browser connects to a WebSocket listener they can only connect over TLS. We then apply noise encryption as well which means everything is encrypted twice which is inefficient.

We should be able to use the noise handshake mechanism to ensure the remote has the private key corresponding to it's public key, then use the browser's TLS implementation to prevent eavesdropping.

The specification is [in progress](https://github.com/libp2p/specs/pull/625) the milestone is to ship a POC.

## Node.js connectivity

### QUIC in Node.js

There's a decent chance the Node.js QUIC implementation is [not going to be exposed to userland](https://github.com/nodejs/node/pull/52628#issuecomment-2143475066), but we need this to have compatibility with other libp2p implementations.

https://github.com/ChainSafe/js-libp2p-quic is in-progress to add QUIC support via a native module that uses the Rust implementation.

### WebTransport in Node.js

A [long-lived PR](https://github.com/libp2p/js-libp2p/pull/2422) is open that adds WebTransport support via the [@fails-components/webtransport](https://www.npmjs.com/package/@fails-components/webtransport) module, however it's blocked on [spec incompatibilities](https://github.com/fails-components/webtransport/issues/213).

We can either resolve these incompatibilities, implement WebTransport on top of https://github.com/ChainSafe/js-libp2p-quic, or perhaps Node.js will finally ship [HTTP3 support](https://github.com/nodejs/node/issues/38478) and WebTransport, whichever is most expedient.

### WebRTC Direct in Node.js

Another [long-lived PR](https://github.com/libp2p/js-libp2p/pull/2583) adds support for a [WebRTC Direct](https://github.com/libp2p/specs/blob/master/webrtc/webrtc-direct.md) listener to Node.js.

It's currently blocked on a number of PRs that require the input of upstream maintainers (see linked issues in [#2583](https://github.com/libp2p/js-libp2p/pull/2583)). We will continue to encourage the maintainers of these libraries to give feedback and ultimately merge those PRs but we may need to publish forks in the interim.
81 changes: 34 additions & 47 deletions doc/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
- [Customizing Peer Discovery](#customizing-peer-discovery)
- [Customizing Pubsub](#customizing-pubsub)
- [Customizing DHT](#customizing-dht)
- [Setup with Content and Peer Routing](#setup-with-content-and-peer-routing)
- [Setup with Delegated Content and Peer Routing](#setup-with-delegated-content-and-peer-routing)
- [Setup with Relay](#setup-with-relay)
- [Setup with Automatic Reservations](#setup-with-automatic-reservations)
- [Setup with Preconfigured Reservations](#setup-with-preconfigured-reservations)
Expand Down Expand Up @@ -145,14 +145,15 @@ If you want to know more about libp2p peer discovery, you should read the follow
Some available content routing modules are:

- [@libp2p/kad-dht](https://github.com/libp2p/js-libp2p/tree/main/packages/kad-dht)
- [@helia/delegated-routing-v1-http-api-client](https://github.com/ipfs/helia-delegated-routing-v1-http-api)
- [@libp2p/delegated-content-routing](https://github.com/libp2p/js-libp2p-delegated-content-routing)
- [@libp2p/ipni-content-routing](https://github.com/libp2p/js-ipni-content-routing)

If none of the available content routing protocols fulfil your needs, you can create a libp2p compatible one. A libp2p content routing protocol just needs to be compliant with the [Content Routing Interface](https://github.com/libp2p/js-libp2p/tree/main/packages/interface/content-routing).
> [!NOTE]
> The `@helia/delegated-routing-v1-http-api-client` module is a client for the [IPFS Delegated Routing V1 HTTP API](https://specs.ipfs.tech/routing/http-routing-v1/). It is not a libp2p module, but it can be used in conjunction with libp2p to provide content and peer routing functionality.
> For most purposes, `@helia/delegated-routing-v1-http-api-client` should be favoured over `@libp2p/delegated-content-routing` for delegated routing, as it is more broadly adopted by the ecosystem and doesn't rely on Kubo specific APIs.
If you want to know more about libp2p content routing, you should read the following content:
If none of the available content routing protocols fulfil your needs, you can create a libp2p compatible one. A libp2p content routing protocol just needs to be compliant with the [Content Routing Interface](https://github.com/libp2p/js-libp2p/blob/main/packages/interface/src/content-routing/index.ts).

- https://docs.libp2p.io/concepts/content-routing

### Peer Routing

Expand All @@ -161,13 +162,14 @@ If you want to know more about libp2p content routing, you should read the follo
Some available peer routing modules are:

- [@libp2p/kad-dht](https://github.com/libp2p/js-libp2p/tree/main/packages/kad-dht)
- [@helia/delegated-routing-v1-http-api-client](https://github.com/ipfs/helia-delegated-routing-v1-http-api)
- [@libp2p/delegated-peer-routing](https://github.com/libp2p/js-libp2p-delegated-peer-routing)
If none of the available peer routing protocols fulfills your needs, you can create a libp2p compatible one. A libp2p peer routing protocol just needs to be compliant with the [Peer Routing Interface](https://github.com/libp2p/js-libp2p/blob/main/packages/interface/src/peer-routing/index.ts).

If none of the available peer routing protocols fulfills your needs, you can create a libp2p compatible one. A libp2p peer routing protocol just needs to be compliant with the [Peer Routing Interface](https://github.com/libp2p/js-libp2p/tree/main/packages/interface/peer-routing). **(WIP: This module is not yet implemented)**
> [!NOTE]
> The `@helia/delegated-routing-v1-http-api-client` module is a client for the [IPFS Delegated Routing V1 HTTP API](https://specs.ipfs.tech/routing/http-routing-v1/). It is not a libp2p module, but it can be used in conjunction with libp2p to provide content and peer routing functionality.
> For most purposes, `@helia/delegated-routing-v1-http-api-client` should be favoured over `@libp2p/delegated-content-routing` for delegated routing, as it is more broadly adopted by the ecosystem and doesn't rely on Kubo specific APIs.
If you want to know more about libp2p peer routing, you should read the following content:

- https://docs.libp2p.io/concepts/peer-routing

### DHT

Expand Down Expand Up @@ -219,7 +221,7 @@ const modules = {
Moreover, the majority of the modules can be customized via option parameters. This way, it is also possible to provide this options through a `config` object. This config object should have the property name of each building block to configure, the same way as the modules specification.

Besides the `modules` and `config`, libp2p allows other internal options and configurations:
- `datastore`: an instance of [ipfs/interface-datastore](https://github.com/ipfs/js-ipfs-interfaces/tree/master/packages/interface-datastore) modules.
- `datastore`: an instance of [ipfs/interface-datastore](https://github.com/ipfs/js-stores/tree/main/packages/interface-datastore) modules.
- This is used in modules such as the DHT. If it is not provided, `js-libp2p` will use an in memory datastore.
- `peerId`: the identity of the node, an instance of [libp2p/js-peer-id](https://github.com/libp2p/js-peer-id).
- This is particularly useful if you want to reuse the same `peer-id`, as well as for modules like `libp2p-delegated-content-routing`, which need a `peer-id` in their instantiation.
Expand Down Expand Up @@ -314,7 +316,8 @@ Potential methods for discovering peers include:
- [Distributed hash tables](#dht)
- [Local network broadcasts](https://docs.libp2p.io/concepts/discovery-routing/mdns/)
- [Centralized trackers or rendezvous points](https://docs.libp2p.io/concepts/discovery-routing/rendezvous/)
- [Lists of bootstrap peers](https://github.com/libp2p/js-libp2p-bootstrap)
- [Lists of bootstrap peers](https://github.com/ipfs/helia/blob/main/packages/helia/src/utils/bootstrappers.ts)

```js
import { createLibp2p } from 'libp2p'
import { tcp } from '@libp2p/tcp'
Expand Down Expand Up @@ -379,32 +382,14 @@ const node = await createLibp2p({
})
```

#### Setup with Content and Peer Routing
#### Setup with Delegated Content and Peer Routing

```js
import { createLibp2p } from 'libp2p'
import { tcp } from '@libp2p/tcp'
import { yamux } from '@chainsafe/libp2p-yamux'
import { noise } from '@chainsafe/libp2p-noise'
import { create as ipfsHttpClient } from 'ipfs-http-client'
import { DelegatedPeerRouting } from '@libp2p/delegated-peer-routing'
import { DelegatedContentRouting} from '@libp2p/delegated-content-routing'

// create a peerId
const peerId = await PeerId.create()

const delegatedPeerRouting = new DelegatedPeerRouting(ipfsHttpClient.create({
host: 'node0.delegate.ipfs.io', // In production you should setup your own delegates
protocol: 'https',
port: 443
}))

const delegatedContentRouting = new DelegatedContentRouting(peerId, ipfsHttpClient.create({
host: 'node0.delegate.ipfs.io', // In production you should setup your own delegates
protocol: 'https',
port: 443
}))

import { createDelegatedRoutingV1HttpApiClient } from '@helia/delegated-routing-v1-http-api-client'
const node = await createLibp2p({
transports: [
tcp()
Expand All @@ -415,13 +400,9 @@ const node = await createLibp2p({
connectionEncrypters: [
noise()
],
contentRouting: [
delegatedContentRouting
],
peerRouting: [
delegatedPeerRouting
],
peerId
services: {
delegatedRouting: () => createDelegatedRoutingV1HttpApiClient('https://delegated-ipfs.dev'),
}
})
```

Expand All @@ -445,12 +426,15 @@ import { identify } from '@libp2p/identify'


const node = await createLibp2p({
addresses: {
listen: {
// discover a relay using the routing
'/p2p-circuit'
}
},
transports: [
tcp(),
circuitRelayTransport({ // allows the current node to make and accept relayed connections
discoverRelays: 0, // how many network relays to find
reservationConcurrency: 1 // how many relays to attempt to reserve slots on at once
})
circuitRelayTransport()
],
streamMuxers: [
yamux()
Expand Down Expand Up @@ -499,11 +483,14 @@ import { noise } from '@chainsafe/libp2p-noise'
import { circuitRelayTransport } from '@libp2p/circuit-relay-v2'

const node = await createLibp2p({
addresses: {
listen: [
'/p2p-circuit'
]
},
transports: [
tcp(),
circuitRelayTransport({
discoverRelays: 1
})
circuitRelayTransport()
],
streamMuxers: [
yamux()
Expand Down Expand Up @@ -993,8 +980,8 @@ protocols: [

As libp2p is designed to be a modular networking library, its usage will vary based on individual project needs. We've included links to some existing project configurations for your reference, in case you wish to replicate their configuration:

- [libp2p-ipfs-nodejs](https://github.com/ipfs/js-ipfs/blob/master/packages/ipfs-core-config/src/libp2p.js) - libp2p configuration used by js-ipfs when running in Node.js
- [libp2p-ipfs-browser](https://github.com/ipfs/js-ipfs/blob/master/packages/ipfs-core-config/src/libp2p.browser.js) - libp2p configuration used by js-ipfs when running in a Browser (that supports WebRTC)
- [libp2p-Helia-nodejs](https://github.com/ipfs/helia/blob/main/packages/helia/src/utils/libp2p-defaults.ts) - libp2p configuration used by Helia when running in Node.js
- [libp2p-Helia-browser](https://github.com/ipfs/helia/blob/main/packages/helia/src/utils/libp2p-defaults.browser.ts) - libp2p configuration used by Helia when running in a Browser

If you have developed a project using `js-libp2p`, please consider submitting your configuration to this list so that it can be found easily by other users.

Expand Down
5 changes: 2 additions & 3 deletions doc/migrations/v0.42-v0.43.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,12 @@ const node = await createLibp2p({
// ... other options
addresses: {
listen: {
'/p2p-circuit', // discover a public relay
'/ip4/123.123.123.123/p2p/QmRelay/p2p-circuit' // optionally configure a static relay
}
},
transports: [
circuitRelayClient({ // enable client portion of relay
discoverRelays: 1 // find this number of network relays (default: 0)
})
circuitRelayClient()
],
relay: circuitRelayServer({ // enable server portion of relay
advertise: {
Expand Down
Loading

0 comments on commit d268455

Please sign in to comment.