-
Notifications
You must be signed in to change notification settings - Fork 27
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 2 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,12 @@ pub(crate) mod handle; | |
| /// Logging target for the file. | ||
| const LOG_TARGET: &str = "litep2p::transport-manager"; | ||
|
|
||
| #[derive(Debug, Clone, Copy, Eq, PartialEq)] | ||
| pub enum DialFailureAddresses { | ||
| Required, | ||
| NotRequired, | ||
| } | ||
|
|
||
| /// The connection established result. | ||
| #[derive(Debug, Clone, Copy, Eq, PartialEq)] | ||
| enum ConnectionEstablishedResult { | ||
|
|
@@ -106,6 +112,8 @@ pub struct ProtocolContext { | |
|
|
||
| /// Fallback names for the protocol. | ||
| pub fallback_names: Vec<ProtocolName>, | ||
|
|
||
| pub dial_failure_mode: DialFailureAddresses, | ||
lexnv marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| impl ProtocolContext { | ||
|
|
@@ -114,11 +122,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 +349,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 +370,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 +1134,10 @@ impl TransportManager { | |
| ?protocol, | ||
| "dial failure, notify protocol", | ||
| ); | ||
| match context.tx.try_send(InnerTransportEvent::DialFailure { | ||
| peer, | ||
| addresses: vec![address.clone()], | ||
| }) { | ||
|
|
||
| let adresses = context.dial_failure_addresses(&[address.clone()]); | ||
|
|
||
| match context.tx.try_send(make_dial_failure_event(peer, adresses.clone())) { | ||
|
||
| Ok(()) => {} | ||
| Err(_) => { | ||
| tracing::trace!( | ||
|
|
@@ -1132,10 +1150,7 @@ impl TransportManager { | |
| ); | ||
| let _ = context | ||
| .tx | ||
| .send(InnerTransportEvent::DialFailure { | ||
| peer, | ||
| addresses: vec![address.clone()], | ||
| }) | ||
| .send(make_dial_failure_event(peer, adresses.clone())) | ||
| .await; | ||
| } | ||
| } | ||
|
|
@@ -1266,12 +1281,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(make_dial_failure_event(peer, addresses.clone())) { | ||
| Ok(_) => Ok(()), | ||
| Err(_) => { | ||
| tracing::trace!( | ||
|
|
@@ -1284,10 +1297,7 @@ impl TransportManager { | |
|
|
||
| context | ||
| .tx | ||
| .send(InnerTransportEvent::DialFailure { | ||
| peer, | ||
| addresses: addresses.clone(), | ||
| }) | ||
| .send(make_dial_failure_event(peer, addresses.clone())) | ||
| .await | ||
| } | ||
| }; | ||
|
|
@@ -1343,6 +1353,10 @@ impl TransportManager { | |
| } | ||
| } | ||
|
|
||
| fn make_dial_failure_event(peer: PeerId, addresses: Vec<Multiaddr>) -> InnerTransportEvent { | ||
| InnerTransportEvent::DialFailure { peer, addresses } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use crate::transport::manager::{address::AddressStore, peer_state::SecondaryOrDialing}; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.