Skip to content
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

fix(dcutr): Skip unparsable multiaddr (#3280) #3300

Merged
merged 4 commits into from Jan 11, 2023

Conversation

mxinden
Copy link
Member

@mxinden mxinden commented Jan 2, 2023

Description

With this commit libp2p-dcutr no longer discards the whole remote payload in case an addr is unparsable, but instead logs the failure and skips the unparsable multiaddr.

Notes

Links to any relevant issues

See #3244 for details.

Open Questions

Change checklist

  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • A changelog entry has been made in the appropriate crates

With this commit `libp2p-dcutr` no longer discards the whole remote payload in case an addr is
unparsable, but instead logs the failure and skips the unparsable multiaddr.

See libp2p#3244 for details.
Copy link
Contributor

@elenaf9 elenaf9 left a comment

Choose a reason for hiding this comment

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

Good catch 👍
Unless I am missing something, the same also needs to be fixed in dcutr/protocol/outbound.rs?

@mxinden
Copy link
Member Author

mxinden commented Jan 4, 2023

Unless I am missing something, the same also needs to be fixed in dcutr/protocol/outbound.rs?

🤦‍♂️ Thanks! Mind taking another look @elenaf9?

Copy link
Contributor

@elenaf9 elenaf9 left a comment

Choose a reason for hiding this comment

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

Looks good to me

Comment on lines +61 to 76
.filter_map(|a| match Multiaddr::try_from(a) {
Ok(a) => Some(a),
Err(e) => {
log::debug!("Unable to parse multiaddr: {e}");
None
}
})
// Filter out relayed addresses.
.filter(|a| match a {
Ok(a) => !a.iter().any(|p| p == Protocol::P2pCircuit),
Err(_) => true,
.filter(|a| {
if a.iter().any(|p| p == Protocol::P2pCircuit) {
log::debug!("Dropping relayed address {a}");
false
} else {
true
}
})
Copy link
Contributor

Choose a reason for hiding this comment

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

We could merged these two filter blocks:

                    .filter_map(|a| match Multiaddr::try_from(a) {
                        Ok(a) if !a.iter().any(|p| p == Protocol::P2pCircuit) => Some(a),
                        Ok(a) => {
                            log::debug!("Dropping relayed address {a}");
                            None
                        }
                        Err(e) => {
                            log::debug!("Unable to parse multiaddr: {e}");
                            None
                        }
                    })

(here and below)
No strong opinion.

Copy link
Member Author

Choose a reason for hiding this comment

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

What would be the benefit of merging the two?

Structure wise, I find the separation to ease understanding.

Copy link
Contributor

Choose a reason for hiding this comment

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

The benefit would be to have a single place where addresses are filtered out. I actually first oversaw that there was a second filter call.
But that's subjective and nit-picky; feel free to ignore 🙂.

Copy link
Contributor

Choose a reason for hiding this comment

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

Alternative idea: Keep using .map(Multiaddr::try_from) and use .filter twice for consistency.

Copy link
Contributor

Choose a reason for hiding this comment

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

Alternative idea: Keep using .map(Multiaddr::try_from) and use .filter twice for consistency.

Don't mind me, that doesn't work because we need to unpack the result somewhere.

Copy link
Contributor

@thomaseizinger thomaseizinger left a comment

Choose a reason for hiding this comment

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

One way to reduce the code duplication here would be to create our own type that implements FromIterator and filters unparseable and relayed addresses.

@mxinden
Copy link
Member Author

mxinden commented Jan 10, 2023

One way to reduce the code duplication here would be to create our own type that implements FromIterator and filters unparseable and relayed addresses.

Neat trick. That said, is it worth the abstraction given that it is only used twice?


I will move forward here, releasing this patch right away.

@mxinden mxinden merged commit 92a1b95 into libp2p:v0.50 Jan 11, 2023
@mxinden
Copy link
Member Author

mxinden commented Jan 11, 2023

Tagged and published.

@thomaseizinger
Copy link
Contributor

One way to reduce the code duplication here would be to create our own type that implements FromIterator and filters unparseable and relayed addresses.

Neat trick. That said, is it worth the abstraction given that it is only used twice?

Probably not :)

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.

None yet

3 participants