Skip to content

Commit

Permalink
protocols/dcutr: Use extend instead of double push_back
Browse files Browse the repository at this point in the history
  • Loading branch information
mxinden committed Feb 2, 2022
1 parent 354900f commit b50708b
Showing 1 changed file with 22 additions and 28 deletions.
50 changes: 22 additions & 28 deletions protocols/dcutr/src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,24 +112,23 @@ impl NetworkBehaviour for Behaviour {
// connection upgrade by initiating a direct connection to A.
//
// https://github.com/libp2p/specs/blob/master/relay/DCUtR.md#the-protocol
self.queued_actions.push_back(Action::Connect {
peer_id: *peer_id,
attempt: 1,
handler: NotifyHandler::One(*connection_id),
});
let local_addr = match connected_point {
ConnectedPoint::Listener { local_addr, .. } => local_addr,
ConnectedPoint::Dialer { .. } => unreachable!("Due to outer if."),
};
self.queued_actions.push_back(
self.queued_actions.extend([
Action::Connect {
peer_id: *peer_id,
attempt: 1,
handler: NotifyHandler::One(*connection_id),
},
NetworkBehaviourAction::GenerateEvent(
Event::InitiatedDirectConnectionUpgrade {
remote_peer_id: *peer_id,
local_relayed_addr: local_addr.clone(),
local_relayed_addr: match connected_point {
ConnectedPoint::Listener { local_addr, .. } => local_addr.clone(),
ConnectedPoint::Dialer { .. } => unreachable!("Due to outer if."),
},
},
)
.into(),
);
]);
}
} else {
self.direct_connections
Expand Down Expand Up @@ -159,7 +158,7 @@ impl NetworkBehaviour for Behaviour {
attempt: attempt + 1,
});
} else {
self.queued_actions.push_back(
self.queued_actions.extend([
NetworkBehaviourAction::NotifyHandler {
peer_id,
handler: NotifyHandler::One(relayed_connection_id),
Expand All @@ -168,16 +167,14 @@ impl NetworkBehaviour for Behaviour {
),
}
.into(),
);
self.queued_actions.push_back(
NetworkBehaviourAction::GenerateEvent(
Event::DirectConnectionUpgradeFailed {
remote_peer_id: peer_id,
error: UpgradeError::Dial,
},
)
.into(),
);
]);
}
}
_ => {}
Expand Down Expand Up @@ -221,20 +218,20 @@ impl NetworkBehaviour for Behaviour {
inbound_connect,
remote_addr,
}) => {
self.queued_actions.push_back(Action::AcceptInboundConnect {
peer_id: event_source,
handler: NotifyHandler::One(connection),
inbound_connect,
});
self.queued_actions.push_back(
self.queued_actions.extend([
Action::AcceptInboundConnect {
peer_id: event_source,
handler: NotifyHandler::One(connection),
inbound_connect,
},
NetworkBehaviourAction::GenerateEvent(
Event::RemoteInitiatedDirectConnectionUpgrade {
remote_peer_id: event_source,
remote_relayed_addr: remote_addr,
},
)
.into(),
);
]);
}
Either::Left(handler::relayed::Event::InboundNegotiationFailed { error }) => {
self.queued_actions.push_back(
Expand Down Expand Up @@ -293,7 +290,7 @@ impl NetworkBehaviour for Behaviour {
relayed_connection_id,
},
)) => {
self.queued_actions.push_back(
self.queued_actions.extend([
NetworkBehaviourAction::NotifyHandler {
peer_id: event_source,
handler: NotifyHandler::One(relayed_connection_id),
Expand All @@ -302,16 +299,13 @@ impl NetworkBehaviour for Behaviour {
),
}
.into(),
);
self.queued_actions.push_back(
NetworkBehaviourAction::GenerateEvent(
Event::DirectConnectionUpgradeSucceeded {
remote_peer_id: event_source,
},
)
.into(),
);
return;
]);
}
Either::Right(Either::Right(event)) => void::unreachable(event),
};
Expand Down

0 comments on commit b50708b

Please sign in to comment.