-
Notifications
You must be signed in to change notification settings - Fork 23
improve efficiency of propagating address failures #443
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
Open
dharjeezy
wants to merge
4
commits into
paritytech:master
Choose a base branch
from
dharjeezy:dami/dial-up-addresses
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 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
Some comments aren't visible on the classic Files Changed page.
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 |
|---|---|---|
|
|
@@ -73,6 +73,19 @@ pub(crate) mod handle; | |
| /// Logging target for the file. | ||
| const LOG_TARGET: &str = "litep2p::transport-manager"; | ||
|
|
||
| /// Determines if a protocol requires the list of failed addresses upon a dial failure. | ||
| /// | ||
| /// This is used during protocol registration with the `TransportManager` to specify | ||
| /// whether `InnerTransportEvent::DialFailure` events sent to this protocol should | ||
| /// include the specific multiaddresses that failed. | ||
| #[derive(Debug, Clone, Copy, Eq, PartialEq)] | ||
| pub enum DialFailureAddresses { | ||
| /// The protocol needs the list of failed addresses. | ||
| Required, | ||
| /// The protocol does not need the list of failed addresses. | ||
| NotRequired, | ||
| } | ||
|
|
||
| /// The connection established result. | ||
| #[derive(Debug, Clone, Copy, Eq, PartialEq)] | ||
| enum ConnectionEstablishedResult { | ||
|
|
@@ -106,6 +119,9 @@ pub struct ProtocolContext { | |
|
|
||
| /// Fallback names for the protocol. | ||
| pub fallback_names: Vec<ProtocolName>, | ||
|
|
||
| /// Specifies if the protocol requires dial failure addresses. | ||
| pub dial_failure_mode: DialFailureAddresses, | ||
lexnv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| impl ProtocolContext { | ||
|
|
@@ -114,11 +130,20 @@ impl ProtocolContext { | |
| codec: ProtocolCodec, | ||
| tx: Sender<InnerTransportEvent>, | ||
| fallback_names: Vec<ProtocolName>, | ||
| dial_failure_mode: DialFailureAddresses, | ||
| ) -> Self { | ||
| Self { | ||
| tx, | ||
| codec, | ||
| fallback_names, | ||
| dial_failure_mode, | ||
| } | ||
| } | ||
|
|
||
| fn dial_failure_addresses(&self, addresses: &[Multiaddr]) -> Vec<Multiaddr> { | ||
| match self.dial_failure_mode { | ||
| DialFailureAddresses::Required => addresses.to_vec(), | ||
| DialFailureAddresses::NotRequired => Vec::new(), | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -332,6 +357,7 @@ impl TransportManager { | |
| fallback_names: Vec<ProtocolName>, | ||
| codec: ProtocolCodec, | ||
| keep_alive_timeout: Duration, | ||
| dial_failure_mode: DialFailureAddresses, | ||
| ) -> TransportService { | ||
| assert!(!self.protocol_names.contains(&protocol)); | ||
|
|
||
|
|
@@ -352,7 +378,7 @@ impl TransportManager { | |
|
|
||
| self.protocols.insert( | ||
| protocol.clone(), | ||
| ProtocolContext::new(codec, sender, fallback_names.clone()), | ||
| ProtocolContext::new(codec, sender, fallback_names.clone(), dial_failure_mode), | ||
| ); | ||
| self.protocol_names.insert(protocol); | ||
| self.protocol_names.extend(fallback_names); | ||
|
|
@@ -1116,10 +1142,10 @@ impl TransportManager { | |
| ?protocol, | ||
| "dial failure, notify protocol", | ||
| ); | ||
| match context.tx.try_send(InnerTransportEvent::DialFailure { | ||
| peer, | ||
| addresses: vec![address.clone()], | ||
| }) { | ||
|
|
||
| let addresses = context.dial_failure_addresses(&[address.clone()]); | ||
|
|
||
| match context.tx.try_send(InnerTransportEvent::DialFailure { peer, addresses: addresses.clone() }) { | ||
| Ok(()) => {} | ||
| Err(_) => { | ||
| tracing::trace!( | ||
|
|
@@ -1132,10 +1158,7 @@ impl TransportManager { | |
| ); | ||
| let _ = context | ||
| .tx | ||
| .send(InnerTransportEvent::DialFailure { | ||
| peer, | ||
| addresses: vec![address.clone()], | ||
| }) | ||
| .send(InnerTransportEvent::DialFailure { peer, addresses }) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dharjeezy Can you also add to the doc of |
||
| .await; | ||
| } | ||
| } | ||
|
|
@@ -1266,12 +1289,10 @@ impl TransportManager { | |
| .collect::<Vec<_>>(); | ||
|
|
||
| for (protocol, context) in &self.protocols { | ||
| let addresses = context.dial_failure_addresses(&addresses); | ||
| let _ = match context | ||
| .tx | ||
| .try_send(InnerTransportEvent::DialFailure { | ||
| peer, | ||
| addresses: addresses.clone(), | ||
| }) { | ||
| .try_send(InnerTransportEvent::DialFailure { peer, addresses: addresses.clone() }) { | ||
| Ok(_) => Ok(()), | ||
| Err(_) => { | ||
| tracing::trace!( | ||
|
|
@@ -1284,10 +1305,7 @@ impl TransportManager { | |
|
|
||
| context | ||
| .tx | ||
| .send(InnerTransportEvent::DialFailure { | ||
| peer, | ||
| addresses: addresses.clone(), | ||
| }) | ||
| .send(InnerTransportEvent::DialFailure { peer, addresses }) | ||
| .await | ||
| } | ||
| }; | ||
|
|
||
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.