-
Notifications
You must be signed in to change notification settings - Fork 446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: circuit relay v2 follow up items #1619
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
# Migrating to libp2p@43 <!-- omit in toc --> | ||
|
||
A migration guide for refactoring your application code from libp2p v0.42.x to v0.43.0. | ||
|
||
## Table of Contents <!-- omit in toc --> | ||
|
||
- [Circuit Relay v2](#circuit-relay-v2) | ||
|
||
## Circuit Relay v2 | ||
|
||
[email protected] ships with support for [Circuit Relay v2](https://github.com/libp2p/specs/blob/master/relay/circuit-v2.md). This update to the spec changes the relay from being an open relay by default, and as such quite dangerous to enable, to being a limited relay with a slot reservation mechanism that is much safer. | ||
|
||
With version 2, each relay has a limited number of slots available (default: 15) which network peers can reserve use of to transfer small amounts of data to and from other peers (default 128k) for short amounts of time (default: 2 minutes). | ||
|
||
This allows network nodes to act as intermediaries between nodes that may otherwise not be able to communicate due to a lack of compatible transports. | ||
|
||
To simplify configuration, the client and server parts of the relay have been split apart to make it easier to configure your node as a client and/or a server. | ||
|
||
**Before** | ||
|
||
```js | ||
import { createLibp2p } from 'libp2p' | ||
|
||
const node = await createLibp2p({ | ||
// ... other options | ||
addresses: { | ||
listen: { | ||
'/ip4/123.123.123.123/p2p/QmRelay/p2p-circuit' // optionally configure a static relay | ||
} | ||
}, | ||
relay: { | ||
enabled: true, // enable client portion of relay | ||
|
||
autoRelay: { | ||
enabled: true, // enable automatically finding network relays | ||
maxListeners: 2 // limit number of network relays to use | ||
} | ||
|
||
hop: { | ||
enabled: true, // enable server portion of relay | ||
active: true // dial other nodes on the incoming relay client's behalf | ||
}, | ||
|
||
advertise: { | ||
enabled: true, // advertise the relay server on this node | ||
bootDelay: 15 * 60 * 1000, // how long to wait after startup before advertising | ||
ttl: 30 * 60 * 1000 // how often to re-advertise | ||
} | ||
} | ||
}) | ||
``` | ||
|
||
**After** | ||
|
||
```js | ||
import { createLibp2p } from 'libp2p' | ||
import { circuitRelayClient, circuitRelayServer } from 'libp2p/circuit-relay' | ||
|
||
const node = await createLibp2p({ | ||
// ... other options | ||
addresses: { | ||
listen: { | ||
'/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) | ||
}) | ||
], | ||
relay: circuitRelayServer({ // enable server portion of relay | ||
advertise: { | ||
bootDelay: 15 * 60 * 1000 // how long to wait after startup before re-advertising | ||
} | ||
}) | ||
}) | ||
``` | ||
|
||
Please see the [Setup with Relay](https://github.com/libp2p/js-libp2p/blob/master/doc/CONFIGURATION.md#setup-with-relay) section of the configuration for a full breakdown of all the options. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the JS impl use ASNs to limit the peers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not out of the box, but the connection gater interface can be used to do this.