Skip to content

Commit 09c6908

Browse files
authored
protocols/dcutr: Fix clippy lints (#2772)
1 parent 56c492c commit 09c6908

File tree

2 files changed

+34
-39
lines changed

2 files changed

+34
-39
lines changed

protocols/dcutr/src/behaviour.rs

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ pub enum UpgradeError {
6565
Handler(ConnectionHandlerUpgrErr<void::Void>),
6666
}
6767

68+
#[derive(Default)]
6869
pub struct Behaviour {
6970
/// Queue of actions to return when polled.
7071
queued_actions: VecDeque<ActionBuilder>,
@@ -145,40 +146,35 @@ impl NetworkBehaviour for Behaviour {
145146
handler: Self::ConnectionHandler,
146147
_error: &DialError,
147148
) {
148-
match handler {
149-
handler::Prototype::DirectConnection {
150-
relayed_connection_id,
151-
role: handler::Role::Initiator { attempt },
152-
} => {
153-
let peer_id =
154-
peer_id.expect("Peer of `Prototype::DirectConnection` is always known.");
155-
if attempt < MAX_NUMBER_OF_UPGRADE_ATTEMPTS {
156-
self.queued_actions.push_back(ActionBuilder::Connect {
149+
if let handler::Prototype::DirectConnection {
150+
relayed_connection_id,
151+
role: handler::Role::Initiator { attempt },
152+
} = handler
153+
{
154+
let peer_id = peer_id.expect("Peer of `Prototype::DirectConnection` is always known.");
155+
if attempt < MAX_NUMBER_OF_UPGRADE_ATTEMPTS {
156+
self.queued_actions.push_back(ActionBuilder::Connect {
157+
peer_id,
158+
handler: NotifyHandler::One(relayed_connection_id),
159+
attempt: attempt + 1,
160+
});
161+
} else {
162+
self.queued_actions.extend([
163+
NetworkBehaviourAction::NotifyHandler {
157164
peer_id,
158165
handler: NotifyHandler::One(relayed_connection_id),
159-
attempt: attempt + 1,
160-
});
161-
} else {
162-
self.queued_actions.extend([
163-
NetworkBehaviourAction::NotifyHandler {
164-
peer_id,
165-
handler: NotifyHandler::One(relayed_connection_id),
166-
event: Either::Left(
167-
handler::relayed::Command::UpgradeFinishedDontKeepAlive,
168-
),
169-
}
170-
.into(),
171-
NetworkBehaviourAction::GenerateEvent(
172-
Event::DirectConnectionUpgradeFailed {
173-
remote_peer_id: peer_id,
174-
error: UpgradeError::Dial,
175-
},
176-
)
177-
.into(),
178-
]);
179-
}
166+
event: Either::Left(
167+
handler::relayed::Command::UpgradeFinishedDontKeepAlive,
168+
),
169+
}
170+
.into(),
171+
NetworkBehaviourAction::GenerateEvent(Event::DirectConnectionUpgradeFailed {
172+
remote_peer_id: peer_id,
173+
error: UpgradeError::Dial,
174+
})
175+
.into(),
176+
]);
180177
}
181-
_ => {}
182178
}
183179
}
184180

@@ -324,7 +320,6 @@ impl NetworkBehaviour for Behaviour {
324320

325321
/// A [`NetworkBehaviourAction`], either complete, or still requiring data from [`PollParameters`]
326322
/// before being returned in [`Behaviour::poll`].
327-
#[allow(clippy::large_enum_variant)]
328323
enum ActionBuilder {
329324
Done(NetworkBehaviourAction<Event, handler::Prototype>),
330325
Connect {
@@ -333,7 +328,7 @@ enum ActionBuilder {
333328
peer_id: PeerId,
334329
},
335330
AcceptInboundConnect {
336-
inbound_connect: protocol::inbound::PendingConnect,
331+
inbound_connect: Box<protocol::inbound::PendingConnect>,
337332
handler: NotifyHandler,
338333
peer_id: PeerId,
339334
},

protocols/dcutr/src/handler/relayed.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub enum Command {
4444
},
4545
AcceptInboundConnect {
4646
obs_addrs: Vec<Multiaddr>,
47-
inbound_connect: protocol::inbound::PendingConnect,
47+
inbound_connect: Box<protocol::inbound::PendingConnect>,
4848
},
4949
/// Upgrading the relayed connection to a direct connection either failed for good or succeeded.
5050
/// There is no need to keep the relayed connection alive for the sake of upgrading to a direct
@@ -76,7 +76,7 @@ impl fmt::Debug for Command {
7676

7777
pub enum Event {
7878
InboundConnectRequest {
79-
inbound_connect: protocol::inbound::PendingConnect,
79+
inbound_connect: Box<protocol::inbound::PendingConnect>,
8080
remote_addr: Multiaddr,
8181
},
8282
InboundNegotiationFailed {
@@ -201,7 +201,7 @@ impl ConnectionHandler for Handler {
201201
};
202202
self.queued_events.push_back(ConnectionHandlerEvent::Custom(
203203
Event::InboundConnectRequest {
204-
inbound_connect,
204+
inbound_connect: Box::new(inbound_connect),
205205
remote_addr,
206206
},
207207
));
@@ -245,9 +245,10 @@ impl ConnectionHandler for Handler {
245245
inbound_connect,
246246
obs_addrs,
247247
} => {
248-
if let Some(_) = self
248+
if self
249249
.inbound_connect
250250
.replace(inbound_connect.accept(obs_addrs).boxed())
251+
.is_some()
251252
{
252253
log::warn!(
253254
"New inbound connect stream while still upgrading previous one. \
@@ -337,8 +338,7 @@ impl ConnectionHandler for Handler {
337338
_ => {
338339
// Anything else is considered a fatal error or misbehaviour of
339340
// the remote peer and results in closing the connection.
340-
self.pending_error =
341-
Some(error.map_upgrade_err(|e| e.map_err(|e| EitherError::B(e))));
341+
self.pending_error = Some(error.map_upgrade_err(|e| e.map_err(EitherError::B)));
342342
}
343343
}
344344
}

0 commit comments

Comments
 (0)