Skip to content

Conversation

dharjeezy
Copy link
Contributor

closes #409

Comment on lines 336 to 340
fallback_names: Vec<ProtocolName>,
codec: ProtocolCodec,
keep_alive_timeout: Duration,
needs_dial_failure_addresses: bool,
) -> TransportService {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add an explicit enum for this option:

pub enum DialFailureAddresses {
    Required,
    NotRequired,
}

Such that we can easily follow during the protocol registration the purpose of this flag

peer,
addresses: addresses.clone(),
}) {
.try_send(make_dial_failure_event(&self.address_reporting_protocols, protocol, peer, addresses.clone())) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could introduce a tiny helper over the protocol context:

impl ProtocolContext {
    fn dial_failure(&self, addresses: &[Multiaddr]) -> Vec<Multiaddr> {
        match self.dial_failure_mode {
            DialFailureMode::Required => addresses.to_vec(),
            DialFailureMode::NotRequired => Vec::new(),
        }
    }
}

 let _ = match context.tx.try_send(
    InnerTransportEvent::DialFailure {
        peer,
        addresses: context.dial_failure(addresses)
    }
 )

This way we avoid cloning the addresses until we need them, while keeping the InnerTransportEvent::DialFailure event explicit. This will also provide a bit better isolation to avoid free floating functions

@dharjeezy dharjeezy requested a review from lexnv October 14, 2025 09:40
const LOG_TARGET: &str = "litep2p::transport-manager";

#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub enum DialFailureAddresses {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: We could add some documentation explaining the purpose of this enum

/// Fallback names for the protocol.
pub fallback_names: Vec<ProtocolName>,

pub dial_failure_mode: DialFailureAddresses,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Missing docs

Comment on lines 1138 to 1140
let adresses = context.dial_failure_addresses(&[address.clone()]);

match context.tx.try_send(make_dial_failure_event(peer, adresses.clone())) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Is there a way to avoid the cloning here? Maybe changing the signature of the fn to take a & Multiaddr?

I would also inline the make_dial_failure_event:

match context.tx.try_send(InnerTransportEvent::DialFailure { peer, addresses })

Instead of cloning the addreses here (addresses.clone()), we could recreate the addresses on error

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have changed to this inline way, but can't still do without cloning

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TransportManager: Improve the efficiency of propagating dial failure messages

2 participants