408: Improve error reporting of failed protocols r=thomaseizinger a=thomaseizinger Instead of forwarding every error, we deliberately ignore certain variants that are not worth being printed to the log. In particular, this concerns "UnsupportedProtocols" and "ResponseOmission". To make this less verbose we introduce a macro for mapping a `RequestResponseEvent` to `{alice,bob}::OutEvent`. We use a macro because those `OutEvent`s are different types and the only other way of abstracting over them would be to introduce traits that we implement on both of them. To make the macro easier to use, we move all the `From` implementations that convert between the protocol and the more high-level behaviour into the actual protocol module. 417: Bump curve25519-dalek from 3.0.2 to 3.1.0 r=thomaseizinger a=dependabot[bot] Bumps [curve25519-dalek](https://github.com/dalek-cryptography/curve25519-dalek) from 3.0.2 to 3.1.0. <details> <summary>Changelog</summary> <p><em>Sourced from <a href="https://github.com/dalek-cryptography/curve25519-dalek/blob/main/CHANGELOG.md">curve25519-dalek's changelog</a>.</em></p> <blockquote> <h3>3.1.0</h3> <ul> <li>Add support for the Elligator2 encoding for Edwards points.</li> <li>Add two optional formally-verified field arithmetic backends which use the Fiat Crypto project's Rust code, which is generated from proofs of functional correctness checked by the Coq theorem proving system.</li> <li>Add support for additional sizes of precomputed tables for basepoint scalar multiplication.</li> <li>Fix an unused import.</li> <li>Add support for using the <code>zeroize</code> traits with all point types. Note that points are not automatically zeroized on Drop, but that consumers of <code>curve25519-dalek</code> should call these methods manually when needed.</li> </ul> </blockquote> </details> <details> <summary>Commits</summary> <ul> <li><a href="pull/422/head2ea17d554a
"><code>2ea17d5</code></a> Update CHANGELOG and README; bump to 3.1.0.</li> <li><a href="5eca140010
"><code>5eca140</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/dalek-cryptography/curve25519-dalek/issues/351">#351</a> from isislovecruft/fix/cleanup-elligator</li> <li><a href="cecc821f40
"><code>cecc821</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/dalek-cryptography/curve25519-dalek/issues/342">#342</a> from huitseeker/fiat4_with_u32</li> <li><a href="35d4eab431
"><code>35d4eab</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/dalek-cryptography/curve25519-dalek/issues/349">#349</a> from huitseeker/modernize_benchmarks</li> <li><a href="b05feec7aa
"><code>b05feec</code></a> Merge pull request <a href="https://github-redirect.dependabot.com/dalek-cryptography/curve25519-dalek/issues/350">#350</a> from isislovecruft/develop</li> <li><a href="0da8f08d65
"><code>0da8f08</code></a> Maintain legacy 3.x support for lookup tables.</li> <li><a href="ee90202a58
"><code>ee90202</code></a> Trivial cleanups to Elligator2 encoding.</li> <li><a href="d130b5f17e
"><code>d130b5f</code></a> [benchmarks-only] Updates the benchmarks</li> <li><a href="cc0c444fae
"><code>cc0c444</code></a> Merge branch 'feature/dynamic-table-sizes' into develop</li> <li><a href="1491f0db36
"><code>1491f0d</code></a> Update copyright years.</li> <li>Additional commits viewable in <a href="https://github.com/dalek-cryptography/curve25519-dalek/compare/3.0.2...3.1.0">compare view</a></li> </ul> </details> <br /> [![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=curve25519-dalek&package-manager=cargo&previous-version=3.0.2&new-version=3.1.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot merge` will merge this PR after your CI passes on it - `@dependabot squash and merge` will squash and merge this PR after your CI passes on it - `@dependabot cancel merge` will cancel a previously requested merge and block automerging - `@dependabot reopen` will reopen this PR if it is closed - `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Co-authored-by: Thomas Eizinger <thomas@eizinger.io> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
commit
2e3f052417
@ -0,0 +1,66 @@
|
||||
/// Helper macro to map a [`RequestResponseEvent`] to our [`OutEvent`].
|
||||
///
|
||||
/// This is primarily a macro and not a regular function because we use it for
|
||||
/// Alice and Bob and they have different [`OutEvent`]s that just happen to
|
||||
/// share a couple of variants, like `OutEvent::Failure` and `OutEvent::Other`.
|
||||
#[macro_export]
|
||||
macro_rules! impl_from_rr_event {
|
||||
($protocol_event:ty, $behaviour_out_event:ty, $protocol:ident) => {
|
||||
impl From<$protocol_event> for $behaviour_out_event {
|
||||
fn from(event: $protocol_event) -> Self {
|
||||
use ::libp2p::request_response::RequestResponseEvent::*;
|
||||
use anyhow::anyhow;
|
||||
|
||||
match event {
|
||||
Message { message, peer, .. } => Self::from((peer, message)),
|
||||
ResponseSent { .. } => Self::Other,
|
||||
InboundFailure { peer, error, .. } => {
|
||||
use libp2p::request_response::InboundFailure::*;
|
||||
|
||||
match error {
|
||||
Timeout => {
|
||||
Self::Failure {
|
||||
error: anyhow!("{} failed because of an inbound timeout", $protocol),
|
||||
peer,
|
||||
}
|
||||
}
|
||||
ConnectionClosed => {
|
||||
Self::Failure {
|
||||
error: anyhow!("{} failed because the connection was closed before a response could be sent", $protocol),
|
||||
peer,
|
||||
}
|
||||
}
|
||||
UnsupportedProtocols => Self::Other, // TODO: Report this and disconnected / ban the peer?
|
||||
ResponseOmission => Self::Other
|
||||
}
|
||||
}
|
||||
OutboundFailure { peer, error, .. } => {
|
||||
use libp2p::request_response::OutboundFailure::*;
|
||||
|
||||
match error {
|
||||
Timeout => {
|
||||
Self::Failure {
|
||||
error: anyhow!("{} failed because we did not receive a response within the configured timeout", $protocol),
|
||||
peer,
|
||||
}
|
||||
}
|
||||
ConnectionClosed => {
|
||||
Self::Failure {
|
||||
error: anyhow!("{} failed because the connection was closed we received a response", $protocol),
|
||||
peer,
|
||||
}
|
||||
}
|
||||
UnsupportedProtocols => Self::Other, // TODO: Report this and disconnected / ban the peer?
|
||||
DialFailure => {
|
||||
Self::Failure {
|
||||
error: anyhow!("{} failed because we failed to dial", $protocol),
|
||||
peer,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in new issue