How to downcast connection_limits::Exceeded
?
#4018
-
I am trying to upgrade to libp2p 0.51.0, specifically to use the new
Here is my code snippet // Inside impl NetworkBehaviour ...
fn on_swarm_event(&mut self, event: libp2p::swarm::FromSwarm<Self::ConnectionHandler>) {
match event {
// ...
libp2p::swarm::FromSwarm::DialFailure(event) => {
if let DialError::Denied { cause } = event.error {
if let Ok(connection_limits::Exceeded { .. }) = cause.downcast() {
// Do something about the connection limit error
}
}
}
// ...
}
} I am unable to downcast as I only have a reference to the Happy to contribute a fix if one is needed. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 2 replies
-
Ah yes, the downcast was intended to be used when you receive the event via polling the We can't give ownership of the error to all behaviours because errors are seldomly clonable. |
Beta Was this translation helpful? Give feedback.
-
@nathanielc can you post your |
Beta Was this translation helpful? Give feedback.
-
Yeah makes sense why Clone isn't available. Here is the WIP branch I have for more context https://github.com/nathanielc/beetle/blob/custom-behaviour/iroh-bitswap/src/lib.rs#L426 This is in a stripped down fork of beetle specifically in the bitswap implementation. Here is the behaviour itself https://github.com/nathanielc/beetle/blob/custom-behaviour/iroh-p2p/src/behaviour.rs#L37-L52 Its mostly flat with exception of the |
Beta Was this translation helpful? Give feedback.
That was simple, let me know if you'd like a different/better test #4020