Skip to content

Commit

Permalink
feat: implement circuit v2 (#1533)
Browse files Browse the repository at this point in the history
Implements circuit relay v2

See the [relay section of the configuration](https://github.com/libp2p/js-libp2p/blob/master/doc/CONFIGURATION.md#setup-with-relay) for how to configure it.

Fixes #1029

---------

Co-authored-by: achingbrain <alex@achingbrain.net>
  • Loading branch information
ckousik and achingbrain authored Mar 2, 2023
1 parent fc8831d commit d605cbe
Show file tree
Hide file tree
Showing 44 changed files with 3,002 additions and 1,490 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ dist
.coverage
package-lock.json
yarn.lock
.vscode
27 changes: 18 additions & 9 deletions doc/CONFIGURATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
- [Customizing DHT](#customizing-dht)
- [Setup with Content and Peer Routing](#setup-with-content-and-peer-routing)
- [Setup with Relay](#setup-with-relay)
- [Setup with Auto Relay](#setup-with-auto-relay)
- [Setup with Automatic Reservations](#setup-with-automatic-reservations)
- [Setup with Keychain](#setup-with-keychain)
- [Configuring Dialing](#configuring-dialing)
- [Configuring Connection Manager](#configuring-connection-manager)
Expand Down Expand Up @@ -433,22 +433,31 @@ const node = await createLibp2p({
transports: [tcp()],
streamMuxers: [mplex()],
connectionEncryption: [noise()],
relay: { // Circuit Relay options (this config is part of libp2p core configurations)
relay: { // Circuit Relay options
enabled: true, // Allows you to dial and accept relayed connections. Does not make you a relay.
hop: {
enabled: true, // Allows you to be a relay for other peers
active: true // You will attempt to dial destination peers if you are not connected to them
enabled: true, // Allows you to be a relay for other peers.
timeout: 30 * 1000, // Incoming hop requests must complete within this timeout
applyConnectionLimits: true // Apply data/duration limits to relayed connections (default: true)
limit: {
duration: 120 * 1000 // the maximum amount of ms a relayed connection can be open for
data: BigInt(1 << 17) // the maximum amount of data that can be transferred over a relayed connection
}
},
advertise: {
enabled: true, // Allows you to disable advertising the Hop service
bootDelay: 15 * 60 * 1000, // Delay before HOP relay service is advertised on the network
enabled: true, // Allows you to disable the advertise of the Hop service
ttl: 30 * 60 * 1000 // Delay Between HOP relay service advertisements on the network
ttl: 30 * 60 * 1000 // Delay Between HOP relay service advertisements on the network
},
reservationManager: { // the reservation manager creates reservations on discovered relays
enabled: true, // enable the reservation manager, default: false
maxReservations: 1 // the maximum number of relays to create reservations on
}
}
})
```

#### Setup with Auto Relay
#### Setup with Automatic Reservations

```js
import { createLibp2p } from 'libp2p'
Expand All @@ -462,9 +471,9 @@ const node = await createLibp2p({
connectionEncryption: [noise()]
relay: { // Circuit Relay options (this config is part of libp2p core configurations)
enabled: true, // Allows you to dial and accept relayed connections. Does not make you a relay.
autoRelay: {
reservationManager: {
enabled: true, // Allows you to bind to relays with HOP enabled for improving node dialability
maxListeners: 2 // Configure maximum number of HOP relays to use
maxListeners: 2 // Configure maximum number of HOP relays to use
}
}
})
Expand Down
16 changes: 9 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
"@libp2p/interface-libp2p": "^1.0.0",
"@libp2p/interface-metrics": "^4.0.0",
"@libp2p/interface-peer-discovery": "^1.0.1",
"@libp2p/interface-peer-id": "^2.0.0",
"@libp2p/interface-peer-id": "^2.0.1",
"@libp2p/interface-peer-info": "^1.0.3",
"@libp2p/interface-peer-routing": "^1.0.1",
"@libp2p/interface-peer-store": "^1.2.2",
Expand All @@ -122,7 +122,7 @@
"@libp2p/peer-id": "^2.0.0",
"@libp2p/peer-id-factory": "^2.0.0",
"@libp2p/peer-record": "^5.0.0",
"@libp2p/peer-store": "^6.0.0",
"@libp2p/peer-store": "^6.0.4",
"@libp2p/tracked-map": "^3.0.0",
"@libp2p/utils": "^3.0.2",
"@multiformats/mafmt": "^11.0.2",
Expand All @@ -143,11 +143,13 @@
"it-map": "^2.0.0",
"it-merge": "^2.0.0",
"it-pair": "^2.0.2",
"it-pb-stream": "^3.0.0",
"it-pipe": "^2.0.3",
"it-sort": "^2.0.0",
"it-stream-types": "^1.0.4",
"merge-options": "^3.0.4",
"multiformats": "^11.0.0",
"p-defer": "^4.0.0",
"p-fifo": "^1.0.0",
"p-retry": "^5.0.0",
"private-ip": "^3.0.0",
Expand All @@ -162,17 +164,18 @@
"xsalsa20": "^1.1.0"
},
"devDependencies": {
"@chainsafe/libp2p-gossipsub": "^6.2.0",
"@chainsafe/libp2p-noise": "^11.0.0",
"@chainsafe/libp2p-yamux": "^3.0.3",
"@libp2p/bootstrap": "^6.0.0",
"@libp2p/daemon-client": "^4.0.1",
"@libp2p/daemon-server": "^4.0.1",
"@libp2p/daemon-client": "^5.0.0",
"@libp2p/daemon-server": "^4.1.0",
"@libp2p/floodsub": "^6.0.0",
"@libp2p/interface-compliance-tests": "^3.0.2",
"@libp2p/interface-connection-compliance-tests": "^2.0.3",
"@libp2p/interface-connection-encrypter-compliance-tests": "^4.0.0",
"@libp2p/interface-mocks": "^9.0.0",
"@libp2p/interop": "^4.0.0",
"@libp2p/interop": "^7.0.0",
"@libp2p/kad-dht": "^7.0.0",
"@libp2p/mdns": "^6.0.0",
"@libp2p/mplex": "^7.0.0",
Expand All @@ -188,11 +191,10 @@
"cborg": "^1.8.1",
"delay": "^5.0.0",
"execa": "^7.0.0",
"go-libp2p": "^0.0.6",
"go-libp2p": "^1.0.1",
"it-pushable": "^3.0.0",
"it-to-buffer": "^3.0.0",
"npm-run-all": "^4.1.5",
"p-defer": "^4.0.0",
"p-event": "^5.0.1",
"p-times": "^4.0.0",
"p-wait-for": "^5.0.0",
Expand Down
128 changes: 0 additions & 128 deletions src/circuit/IMPLEMENTATION_NOTES.md

This file was deleted.

Loading

0 comments on commit d605cbe

Please sign in to comment.