-
Notifications
You must be signed in to change notification settings - Fork 995
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
Conversation
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.
There was a problem hiding this 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
?
🤦♂️ Thanks! Mind taking another look @elenaf9? |
There was a problem hiding this 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
.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 | ||
} | ||
}) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 🙂.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
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. |
Probably not :) |
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