mirror of
https://github.com/fluencelabs/rust-libp2p
synced 2025-05-03 14:42:16 +00:00
protocols/dcutr: Fix clippy lints (#2772)
This commit is contained in:
parent
56c492cf41
commit
09c690862e
@ -65,6 +65,7 @@ pub enum UpgradeError {
|
|||||||
Handler(ConnectionHandlerUpgrErr<void::Void>),
|
Handler(ConnectionHandlerUpgrErr<void::Void>),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Default)]
|
||||||
pub struct Behaviour {
|
pub struct Behaviour {
|
||||||
/// Queue of actions to return when polled.
|
/// Queue of actions to return when polled.
|
||||||
queued_actions: VecDeque<ActionBuilder>,
|
queued_actions: VecDeque<ActionBuilder>,
|
||||||
@ -145,40 +146,35 @@ impl NetworkBehaviour for Behaviour {
|
|||||||
handler: Self::ConnectionHandler,
|
handler: Self::ConnectionHandler,
|
||||||
_error: &DialError,
|
_error: &DialError,
|
||||||
) {
|
) {
|
||||||
match handler {
|
if let handler::Prototype::DirectConnection {
|
||||||
handler::Prototype::DirectConnection {
|
relayed_connection_id,
|
||||||
relayed_connection_id,
|
role: handler::Role::Initiator { attempt },
|
||||||
role: handler::Role::Initiator { attempt },
|
} = handler
|
||||||
} => {
|
{
|
||||||
let peer_id =
|
let peer_id = peer_id.expect("Peer of `Prototype::DirectConnection` is always known.");
|
||||||
peer_id.expect("Peer of `Prototype::DirectConnection` is always known.");
|
if attempt < MAX_NUMBER_OF_UPGRADE_ATTEMPTS {
|
||||||
if attempt < MAX_NUMBER_OF_UPGRADE_ATTEMPTS {
|
self.queued_actions.push_back(ActionBuilder::Connect {
|
||||||
self.queued_actions.push_back(ActionBuilder::Connect {
|
peer_id,
|
||||||
|
handler: NotifyHandler::One(relayed_connection_id),
|
||||||
|
attempt: attempt + 1,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
self.queued_actions.extend([
|
||||||
|
NetworkBehaviourAction::NotifyHandler {
|
||||||
peer_id,
|
peer_id,
|
||||||
handler: NotifyHandler::One(relayed_connection_id),
|
handler: NotifyHandler::One(relayed_connection_id),
|
||||||
attempt: attempt + 1,
|
event: Either::Left(
|
||||||
});
|
handler::relayed::Command::UpgradeFinishedDontKeepAlive,
|
||||||
} else {
|
),
|
||||||
self.queued_actions.extend([
|
}
|
||||||
NetworkBehaviourAction::NotifyHandler {
|
.into(),
|
||||||
peer_id,
|
NetworkBehaviourAction::GenerateEvent(Event::DirectConnectionUpgradeFailed {
|
||||||
handler: NotifyHandler::One(relayed_connection_id),
|
remote_peer_id: peer_id,
|
||||||
event: Either::Left(
|
error: UpgradeError::Dial,
|
||||||
handler::relayed::Command::UpgradeFinishedDontKeepAlive,
|
})
|
||||||
),
|
.into(),
|
||||||
}
|
]);
|
||||||
.into(),
|
|
||||||
NetworkBehaviourAction::GenerateEvent(
|
|
||||||
Event::DirectConnectionUpgradeFailed {
|
|
||||||
remote_peer_id: peer_id,
|
|
||||||
error: UpgradeError::Dial,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
.into(),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -324,7 +320,6 @@ impl NetworkBehaviour for Behaviour {
|
|||||||
|
|
||||||
/// A [`NetworkBehaviourAction`], either complete, or still requiring data from [`PollParameters`]
|
/// A [`NetworkBehaviourAction`], either complete, or still requiring data from [`PollParameters`]
|
||||||
/// before being returned in [`Behaviour::poll`].
|
/// before being returned in [`Behaviour::poll`].
|
||||||
#[allow(clippy::large_enum_variant)]
|
|
||||||
enum ActionBuilder {
|
enum ActionBuilder {
|
||||||
Done(NetworkBehaviourAction<Event, handler::Prototype>),
|
Done(NetworkBehaviourAction<Event, handler::Prototype>),
|
||||||
Connect {
|
Connect {
|
||||||
@ -333,7 +328,7 @@ enum ActionBuilder {
|
|||||||
peer_id: PeerId,
|
peer_id: PeerId,
|
||||||
},
|
},
|
||||||
AcceptInboundConnect {
|
AcceptInboundConnect {
|
||||||
inbound_connect: protocol::inbound::PendingConnect,
|
inbound_connect: Box<protocol::inbound::PendingConnect>,
|
||||||
handler: NotifyHandler,
|
handler: NotifyHandler,
|
||||||
peer_id: PeerId,
|
peer_id: PeerId,
|
||||||
},
|
},
|
||||||
|
@ -44,7 +44,7 @@ pub enum Command {
|
|||||||
},
|
},
|
||||||
AcceptInboundConnect {
|
AcceptInboundConnect {
|
||||||
obs_addrs: Vec<Multiaddr>,
|
obs_addrs: Vec<Multiaddr>,
|
||||||
inbound_connect: protocol::inbound::PendingConnect,
|
inbound_connect: Box<protocol::inbound::PendingConnect>,
|
||||||
},
|
},
|
||||||
/// Upgrading the relayed connection to a direct connection either failed for good or succeeded.
|
/// Upgrading the relayed connection to a direct connection either failed for good or succeeded.
|
||||||
/// There is no need to keep the relayed connection alive for the sake of upgrading to a direct
|
/// 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 {
|
|||||||
|
|
||||||
pub enum Event {
|
pub enum Event {
|
||||||
InboundConnectRequest {
|
InboundConnectRequest {
|
||||||
inbound_connect: protocol::inbound::PendingConnect,
|
inbound_connect: Box<protocol::inbound::PendingConnect>,
|
||||||
remote_addr: Multiaddr,
|
remote_addr: Multiaddr,
|
||||||
},
|
},
|
||||||
InboundNegotiationFailed {
|
InboundNegotiationFailed {
|
||||||
@ -201,7 +201,7 @@ impl ConnectionHandler for Handler {
|
|||||||
};
|
};
|
||||||
self.queued_events.push_back(ConnectionHandlerEvent::Custom(
|
self.queued_events.push_back(ConnectionHandlerEvent::Custom(
|
||||||
Event::InboundConnectRequest {
|
Event::InboundConnectRequest {
|
||||||
inbound_connect,
|
inbound_connect: Box::new(inbound_connect),
|
||||||
remote_addr,
|
remote_addr,
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
@ -245,9 +245,10 @@ impl ConnectionHandler for Handler {
|
|||||||
inbound_connect,
|
inbound_connect,
|
||||||
obs_addrs,
|
obs_addrs,
|
||||||
} => {
|
} => {
|
||||||
if let Some(_) = self
|
if self
|
||||||
.inbound_connect
|
.inbound_connect
|
||||||
.replace(inbound_connect.accept(obs_addrs).boxed())
|
.replace(inbound_connect.accept(obs_addrs).boxed())
|
||||||
|
.is_some()
|
||||||
{
|
{
|
||||||
log::warn!(
|
log::warn!(
|
||||||
"New inbound connect stream while still upgrading previous one. \
|
"New inbound connect stream while still upgrading previous one. \
|
||||||
@ -337,8 +338,7 @@ impl ConnectionHandler for Handler {
|
|||||||
_ => {
|
_ => {
|
||||||
// Anything else is considered a fatal error or misbehaviour of
|
// Anything else is considered a fatal error or misbehaviour of
|
||||||
// the remote peer and results in closing the connection.
|
// the remote peer and results in closing the connection.
|
||||||
self.pending_error =
|
self.pending_error = Some(error.map_upgrade_err(|e| e.map_err(EitherError::B)));
|
||||||
Some(error.map_upgrade_err(|e| e.map_err(|e| EitherError::B(e))));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user