-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Full support for multiple connections per peer in libp2p-swarm. #1519
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
Conversation
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 commit makes the notion of multiple connections per peer first-class in the API of libp2p-swarm, introducing the new callbacks `inject_connection_established` and `inject_connection_closed`. The `endpoint` parameter from `inject_connected` and `inject_disconnected` is removed, since the first connection to open may not be the last connection to close, i.e. it cannot be guaranteed, as was previously the case, that the endpoints passed to these callbacks match up.
So that identify requests can be answered with the correct observed address of the connection on which the request arrives.
twittner
approved these changes
Mar 26, 2020
tomaka
suggested changes
Mar 26, 2020
The only thing that I think should be resolved before merging is the |
To retain the possibility of not re-exposing all network configuration choices, thereby providing a more convenient API on the \`SwarmBuilder\`.
tomaka
approved these changes
Mar 30, 2020
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.
👍
This was referenced Mar 31, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This is a follow-up to #1440 that introduces "first class" support for multiple connections per peer to
libp2p-swarm
. Concretely:inject_connection_established
andinject_connection_closed
are added to theNetworkBehaviour
with empty default impls.inject_connected
andinject_disconnected
no longer get theendpoint
as an argument. This is primarily because these callbacks are invoked for the first established connection, respectively last closed connection, whose endpoints may now differ, as opposed to the previous behaviour. Network behaviours that made use of the endpoint will naturally have to implement the new callbacks and split the code previously ininject_connected
/inject_disconnected
, as is demonstrated in some of the behaviours updated in this PR.NetworkBehaviourAction::DialPeer
as well esExpandedSwarm::dial
now take another parameter, aDialPeerCondition
, which specifies the conditions under which a new dialing attempt should be initiated. The default (and what most behaviours migrating old code will want to use) isDialPeerCondition::Disconnected
.NetworkConfig
of a swarm (which includes connection limits) can now be fully customised viaSwarmBuilder::network_config
, in order to avoid code duplication. For example, substrate will probably want to configure the maximum connections per peer to2
(just to permit concurrent dialing attempts) and possibly also configure limits for concurrent inbound and outbound connections.It is worth mentioning that I took the opportunity to change
inject_connected
to take the peer ID by reference, rather than by value, just likeinject_disconnected
and most other methods. This simplifies things a bit in the derive-macro code and can avoid a bit of unnecessary cloning. I further did this because the signature ofinject_connected
changed anyway in this PR.This PR is expected to be rebased over #1515 eventually.