-
Notifications
You must be signed in to change notification settings - Fork 26
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
base: master
Are you sure you want to change the base?
Changes from all commits
4199102
a7eaf78
3d19a9c
d8711b3
6777dca
da770a5
b4816ce
7dc2be5
48d971c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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(), | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -402,6 +427,7 @@ impl TransportManager { | |
| fallback_names: Vec<ProtocolName>, | ||
| codec: ProtocolCodec, | ||
| keep_alive_timeout: Duration, | ||
| dial_failure_mode: DialFailureAddresses, | ||
| ) -> TransportService { | ||
| assert!(!self.protocol_names.contains(&protocol)); | ||
|
|
||
|
|
@@ -422,7 +448,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); | ||
|
|
@@ -1186,10 +1212,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(std::slice::from_ref(&address)); | ||
|
|
||
| match context.tx.try_send(InnerTransportEvent::DialFailure { peer, addresses: addresses.clone() }) { | ||
| Ok(()) => {} | ||
| Err(_) => { | ||
| tracing::trace!( | ||
|
|
@@ -1202,10 +1228,7 @@ impl TransportManager { | |
| ); | ||
| let _ = context | ||
| .tx | ||
| .send(InnerTransportEvent::DialFailure { | ||
| peer, | ||
| addresses: vec![address.clone()], | ||
| }) | ||
| .send(InnerTransportEvent::DialFailure { peer, addresses }) | ||
|
Collaborator
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
Contributor
Author
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. this is done now @dmitry-markin. can we merge it in now? |
||
| .await; | ||
| } | ||
| } | ||
|
|
@@ -1336,12 +1359,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!( | ||
|
|
@@ -1354,10 +1375,7 @@ impl TransportManager { | |
|
|
||
| context | ||
| .tx | ||
| .send(InnerTransportEvent::DialFailure { | ||
| peer, | ||
| addresses: addresses.clone(), | ||
| }) | ||
| .send(InnerTransportEvent::DialFailure { peer, addresses }) | ||
| .await | ||
| } | ||
| }; | ||
|
|
@@ -1648,12 +1666,14 @@ mod tests { | |
| Vec::new(), | ||
| ProtocolCodec::UnsignedVarint(None), | ||
| KEEP_ALIVE_TIMEOUT, | ||
| DialFailureAddresses::NotRequired | ||
| ); | ||
| manager.register_protocol( | ||
| ProtocolName::from("/notif/1"), | ||
| Vec::new(), | ||
| ProtocolCodec::UnsignedVarint(None), | ||
| KEEP_ALIVE_TIMEOUT, | ||
| DialFailureAddresses::NotRequired | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -1668,6 +1688,7 @@ mod tests { | |
| Vec::new(), | ||
| ProtocolCodec::UnsignedVarint(None), | ||
| KEEP_ALIVE_TIMEOUT, | ||
| DialFailureAddresses::NotRequired, | ||
| ); | ||
| manager.register_protocol( | ||
| ProtocolName::from("/notif/2"), | ||
|
|
@@ -1677,6 +1698,7 @@ mod tests { | |
| ], | ||
| ProtocolCodec::UnsignedVarint(None), | ||
| KEEP_ALIVE_TIMEOUT, | ||
| DialFailureAddresses::NotRequired, | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -1694,6 +1716,7 @@ mod tests { | |
| ], | ||
| ProtocolCodec::UnsignedVarint(None), | ||
| KEEP_ALIVE_TIMEOUT, | ||
| DialFailureAddresses::NotRequired, | ||
| ); | ||
| manager.register_protocol( | ||
| ProtocolName::from("/notif/2"), | ||
|
|
@@ -1703,6 +1726,7 @@ mod tests { | |
| ], | ||
| ProtocolCodec::UnsignedVarint(None), | ||
| KEEP_ALIVE_TIMEOUT, | ||
| DialFailureAddresses::NotRequired, | ||
| ); | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.