Skip to content

Commit 37e1b77

Browse files
committed
fixups
1 parent 2091aba commit 37e1b77

File tree

7 files changed

+32
-73
lines changed

7 files changed

+32
-73
lines changed

portmapper/src/lib.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ use std::{
99
use current_mapping::CurrentMapping;
1010
use futures_lite::StreamExt;
1111
use iroh_metrics::inc;
12-
use nested_enum_utils::common_fields;
1312
use netwatch::interfaces::HomeRouter;
14-
use snafu::{Backtrace, Snafu};
13+
use snafu::Snafu;
1514
use tokio::sync::{mpsc, oneshot, watch};
1615
use tokio_util::task::AbortOnDropHandle;
1716
use tracing::{debug, info_span, trace, Instrument};
@@ -68,24 +67,22 @@ impl ProbeOutput {
6867
}
6968
}
7069

71-
#[common_fields({
72-
backtrace: Option<Backtrace>,
73-
#[snafu(implicit)]
74-
span_trace: n0_snafu::SpanTrace,
75-
})]
70+
// Cannot have backtrace due to Clone bound
71+
// #[nested_enum_utils::common_fields({
72+
// backtrace: Option<snafu::Backtrace>,
73+
// })]
7674
#[allow(missing_docs)]
7775
#[derive(Debug, Clone, Snafu)]
7876
#[non_exhaustive]
79-
#[snafu(visibility(pub(crate)))]
8077
pub enum ProbeError {
8178
#[snafu(display("Mapping channel is full"))]
82-
ChannelFull {},
79+
ChannelFull,
8380
#[snafu(display("Mapping channel is closed"))]
84-
ChannelClosed {},
81+
ChannelClosed,
8582
#[snafu(display("No gateway found for probe"))]
86-
NoGateway {},
83+
NoGateway,
8784
#[snafu(display("gateway found is ipv6, ignoring"))]
88-
Ipv6Gateway {},
85+
Ipv6Gateway,
8986
#[snafu(display("Probe task stopped. is_panic: {is_panic}, is_cancelled: {is_cancelled}"))]
9087
Join { is_panic: bool, is_cancelled: bool },
9188
}

portmapper/src/mapping.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,10 @@ pub enum Mapping {
2727
/// Mapping error.
2828
#[common_fields({
2929
backtrace: Option<Backtrace>,
30-
#[snafu(implicit)]
31-
span_trace: n0_snafu::SpanTrace,
3230
})]
3331
#[allow(missing_docs)]
3432
#[derive(Debug, Snafu)]
3533
#[non_exhaustive]
36-
#[snafu(visibility(pub(crate)))]
3734
pub enum Error {
3835
#[snafu(display("PCP mapping failed"))]
3936
Pcp { source: pcp::Error },

portmapper/src/nat_pmp.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
33
use std::{net::Ipv4Addr, num::NonZeroU16, time::Duration};
44

5+
use nested_enum_utils::common_fields;
56
use netwatch::UdpSocket;
67
use snafu::{Backtrace, Snafu};
78
use tracing::{debug, trace};
@@ -32,23 +33,17 @@ pub struct Mapping {
3233
lifetime_seconds: u32,
3334
}
3435

36+
#[common_fields({
37+
backtrace: Option<Backtrace>
38+
})]
3539
#[allow(missing_docs)]
3640
#[derive(Debug, Snafu)]
3741
#[non_exhaustive]
38-
#[snafu(visibility(pub(crate)))]
3942
pub enum Error {
4043
#[snafu(display("server returned unexpected response for mapping request"))]
41-
UnexpectedServerResponse {
42-
backtrace: Option<Backtrace>,
43-
#[snafu(implicit)]
44-
span_trace: n0_snafu::SpanTrace,
45-
},
44+
UnexpectedServerResponse {},
4645
#[snafu(display("received 0 port from server as external port"))]
47-
ZeroExternalPort {
48-
backtrace: Option<Backtrace>,
49-
#[snafu(implicit)]
50-
span_trace: n0_snafu::SpanTrace,
51-
},
46+
ZeroExternalPort {},
5247
#[snafu(transparent)]
5348
Io { source: std::io::Error },
5449
#[snafu(transparent)]

portmapper/src/nat_pmp/protocol/response.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::net::Ipv4Addr;
44

55
use nested_enum_utils::common_fields;
66
use num_enum::{IntoPrimitive, TryFromPrimitive};
7-
use snafu::Snafu;
7+
use snafu::{Backtrace, Snafu};
88

99
use super::{MapProtocol, Opcode, Version};
1010

@@ -55,44 +55,41 @@ pub enum ResultCode {
5555
/// Errors that can occur when decoding a [`Response`] from a server.
5656
#[common_fields({
5757
backtrace: Option<Backtrace>,
58-
#[snafu(implicit)]
59-
span_trace: n0_snafu::SpanTrace,
6058
})]
6159
#[allow(missing_docs)]
62-
#[derive(Debug, Snafu, PartialEq, Eq)]
60+
#[derive(Debug, Snafu)]
6361
#[non_exhaustive]
64-
#[snafu(visibility(pub(crate)))]
6562
pub enum Error {
6663
/// Request is too short or is otherwise malformed.
6764
#[snafu(display("Response is malformed"))]
68-
Malformed,
65+
Malformed {},
6966
/// The [`Response::RESPONSE_INDICATOR`] is not present.
7067
#[snafu(display("Packet does not appear to be a response"))]
71-
NotAResponse,
68+
NotAResponse {},
7269
/// The received opcode is not recognized.
7370
#[snafu(display("Invalid Opcode received"))]
74-
InvalidOpcode,
71+
InvalidOpcode {},
7572
/// The received version is not recognized.
7673
#[snafu(display("Invalid version received"))]
77-
InvalidVersion,
74+
InvalidVersion {},
7875
/// The received result code is not recognized.
7976
#[snafu(display("Invalid result code received"))]
80-
InvalidResultCode,
77+
InvalidResultCode {},
8178
/// Received an error code indicating the server does not support the sent version.
8279
#[snafu(display("Server does not support the version"))]
83-
UnsupportedVersion,
80+
UnsupportedVersion {},
8481
/// Received an error code indicating the operation is supported but not authorized.
8582
#[snafu(display("Operation is supported but not authorized"))]
86-
NotAuthorizedOrRefused,
83+
NotAuthorizedOrRefused {},
8784
/// Received an error code indicating the server experienced a network failure
8885
#[snafu(display("Server experienced a network failure"))]
89-
NetworkFailure,
86+
NetworkFailure {},
9087
/// Received an error code indicating the server cannot create more mappings at this time.
9188
#[snafu(display("Server is out of resources"))]
92-
OutOfResources,
89+
OutOfResources {},
9390
/// Received an error code indicating the Opcode is not supported by the server.
9491
#[snafu(display("Server does not support this opcode"))]
95-
UnsupportedOpcode,
92+
UnsupportedOpcode {},
9693
}
9794

9895
impl Response {
@@ -283,7 +280,7 @@ mod tests {
283280

284281
let response = Response::random(Opcode::DetermineExternalAddress, &mut gen);
285282
let encoded = response.encode();
286-
assert_eq!(Ok(response), Response::decode(&encoded));
283+
assert_eq!(response, Response::decode(&encoded).unwrap());
287284
}
288285

289286
#[test]
@@ -292,6 +289,6 @@ mod tests {
292289

293290
let response = Response::random(Opcode::MapUdp, &mut rng);
294291
let encoded = response.encode();
295-
assert_eq!(Ok(response), Response::decode(&encoded));
292+
assert_eq!(response, Response::decode(&encoded).unwrap());
296293
}
297294
}

portmapper/src/pcp.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,10 @@ pub struct Mapping {
3838

3939
#[common_fields({
4040
backtrace: Option<Backtrace>,
41-
#[snafu(implicit)]
42-
span_trace: n0_snafu::SpanTrace,
4341
})]
4442
#[allow(missing_docs)]
4543
#[derive(Debug, Snafu)]
4644
#[non_exhaustive]
47-
#[snafu(visibility(pub(crate)))]
4845
pub enum Error {
4946
#[snafu(display("received nonce does not match sent request"))]
5047
NonceMissmatch {},

portmapper/src/pcp/protocol/response.rs

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,8 @@ pub struct Response {
126126
#[non_exhaustive]
127127
#[common_fields({
128128
backtrace: Option<Backtrace>,
129-
#[snafu(implicit)]
130-
span_trace: n0_snafu::SpanTrace,
131129
})]
132130
#[derive(Debug, Snafu)]
133-
#[snafu(visibility(pub(crate)))]
134131
pub enum DecodeError {
135132
/// Request is too short or is otherwise malformed.
136133
#[snafu(display("Response is malformed"))]
@@ -152,25 +149,7 @@ pub enum DecodeError {
152149
InvalidOpcodeData {},
153150
}
154151

155-
impl PartialEq for DecodeError {
156-
#[allow(clippy::match_like_matches_macro)]
157-
fn eq(&self, other: &Self) -> bool {
158-
match (self, other) {
159-
(DecodeError::Malformed { .. }, DecodeError::Malformed { .. }) => true,
160-
(DecodeError::NotAResponse { .. }, DecodeError::NotAResponse { .. }) => true,
161-
(DecodeError::InvalidOpcode { .. }, DecodeError::InvalidOpcode { .. }) => true,
162-
(DecodeError::InvalidVersion { .. }, DecodeError::InvalidVersion { .. }) => true,
163-
(DecodeError::InvalidResultCode { .. }, DecodeError::InvalidResultCode { .. }) => true,
164-
(DecodeError::InvalidOpcodeData { .. }, DecodeError::InvalidOpcodeData { .. }) => true,
165-
_ => false,
166-
}
167-
}
168-
}
169-
170-
impl Eq for DecodeError {}
171-
172-
#[derive(Debug, Snafu, PartialEq, Eq)]
173-
#[snafu(visibility(pub(crate)))]
152+
#[derive(Debug, Snafu)]
174153
pub enum Error {
175154
#[snafu(transparent)]
176155
DecodeError { source: DecodeError },
@@ -299,7 +278,7 @@ mod tests {
299278

300279
let response = Response::random(Opcode::Announce, &mut gen);
301280
let encoded = response.encode();
302-
assert_eq!(Ok(response), Response::decode(&encoded));
281+
assert_eq!(response, Response::decode(&encoded).unwrap());
303282
}
304283

305284
#[test]
@@ -320,6 +299,6 @@ mod tests {
320299

321300
let response = Response::random(Opcode::Map, &mut rng);
322301
let encoded = response.encode();
323-
assert_eq!(Ok(response), Response::decode(&encoded));
302+
assert_eq!(response, Response::decode(&encoded).unwrap());
324303
}
325304
}

portmapper/src/upnp.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,10 @@ pub struct Mapping {
3939

4040
#[common_fields({
4141
backtrace: Option<Backtrace>,
42-
#[snafu(implicit)]
43-
span_trace: n0_snafu::SpanTrace,
4442
})]
4543
#[allow(missing_docs)]
4644
#[derive(Debug, Snafu)]
4745
#[non_exhaustive]
48-
#[snafu(visibility(pub(crate)))]
4946
pub enum Error {
5047
#[snafu(display("Zero external port"))]
5148
ZeroExternalPort {},

0 commit comments

Comments
 (0)