-
Notifications
You must be signed in to change notification settings - Fork 496
feat: auto dial discovered peers #349
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
2f10234
feat: add strategies to discovery configs
jacobheun 4ec1701
feat: add auto dial support
jacobheun b1c9bb1
test: fix transport tests
jacobheun 568c423
refactor: do some cleanup and fix tests
jacobheun f52e7fd
fix: use switch priority queue via .connect
jacobheun 600bdd4
chore: fix lint
jacobheun ebb49e8
chore: fix README.md language
f9b9834
chore: fix feedback
jacobheun 2d4c675
test: disable autodial for browser tests
jacobheun 7c9d1b4
test: fix browser tests for auto dial
jacobheun 5aabb17
docs: update peer discovery readme language
jacobheun c3e2072
test: improve browser test determinism
jacobheun b26e0ba
fix: resolve feedback
jacobheun 3bb07b3
chore: update switch version
jacobheun 6a82f61
chore: bump bundle size for switch updates
jacobheun 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 hidden or 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 hidden or 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,60 @@ | ||
# Peer Discovery and Auto Dial | ||
|
||
**Synopsis**: | ||
* All peers discovered are emitted via `peer:discovery` so applications can take any desired action. | ||
* Libp2p defaults to automatically connecting to new peers, when under the [ConnectionManager](https://github.com/libp2p/js-libp2p-connection-manager) low watermark (minimum peers). | ||
* Applications can disable this via the `peerDiscovery.autoDial` config property, and handle connections themselves. | ||
* Applications who have not disabled this should **never** connect on peer discovery. Applications should use the `peer:connect` event if they wish to take a specific action on new peers. | ||
|
||
## Scenarios | ||
In any scenario, if a peer is discovered it should be added to the PeerBook. This ensures that even if we don't dial to a node when we discover it, we know about it in the event that it becomes known as a provider for something we need. The scenarios listed below detail what actions the auto dialer will take when peers are discovered. | ||
|
||
### 1. Joining the network | ||
The node is new and needs to join the network. It currently has 0 peers. | ||
**Discovery Mechanisms**: [Ambient Discovery](#ambient-discovery) | ||
|
||
### Action to take | ||
Connect to discovered peers. This should have some degree of concurrency limiting. While the case should be low, if we immediately discover more peers than our high watermark we should avoid dialing them all. | ||
|
||
### 2. Connected to some | ||
The node is connected to other nodes. The current number of connections is less than the desired low watermark. | ||
**Discovery Mechanisms**: [Ambient Discovery](#ambient-discovery) and [Active Discovery](#active-discovery) | ||
|
||
### Action to take | ||
Connect to discovered peers. This should have some degree of concurrency limiting. The concurrency may need to be modified to reflect the current number of peers connected. The more peers we have, the lower the concurrency may need to be. | ||
|
||
### 3. Connected to enough | ||
**Discovery Mechanisms**: [Ambient Discovery](#ambient-discovery) and [Active Discovery](#active-discovery) | ||
|
||
### Action to take | ||
None. If we are connected to enough peers, the low watermark, we should not connect to discovered peers. As other peers discover us, they may connect to us based on their current scenario. | ||
|
||
For example, a long running node with adequate peers is on an MDNS network. A new peer joins the network and both become aware of each other. The new peer should be the peer that dials, as it has too few peers. The existing node has no reason to dial the new peer, but should keep a record of it in case it later becomes an important node due to its contents/capabilities. | ||
|
||
Avoiding dials above the low watermark also allows for a pool of connections to be reserved for application specific actions, such as connecting to a specific content provider via a DHT query to find that content (ipfs-bitswap). | ||
|
||
### 4. Connected to too many | ||
The node has more connections than it wants. The current number of connections is greater than the high watermark. | ||
|
||
[WIP Connection Manager v2 spec](https://github.com/libp2p/specs/pull/161) | ||
**Discovery Mechanisms**: [Ambient Discovery](#ambient-discovery) and [Active Discovery](#active-discovery) | ||
|
||
### Action to take | ||
None, the `ConnectionManager` will automatically prune connections. | ||
|
||
## Discovery Mechanisms | ||
Means of which a libp2p node discovers other peers. | ||
|
||
### Active Discovery | ||
Through active use of the libp2p network, a node may discovery peers. | ||
|
||
* Content/Peer routing (DHT, delegated, etc) provider and peer queries | ||
* DHT random walk | ||
* Rendezvous servers | ||
|
||
### Ambient Discovery | ||
Leveraging known addresses, or network discovery mechanisms, a node may discover peers outside of the bounds of the libp2p network. | ||
|
||
* Bootstrap | ||
* MDNS | ||
* proximity based (bluetooth, sound, etc) |
This file contains hidden or 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 hidden or 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 hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.