Skip to content

Commit

Permalink
Remove unwrap in NetworkController
Browse files Browse the repository at this point in the history
  • Loading branch information
kettlebell committed Nov 21, 2022
1 parent 081fd1c commit 30721df
Showing 1 changed file with 28 additions and 16 deletions.
44 changes: 28 additions & 16 deletions spectrum-network/src/network_controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,24 +281,36 @@ where
}) = self.enabled_peers.get_mut(&peer_id)
{
let protocol_id = protocol_tag.protocol_id();
let (_, prot_handler) = self.supported_protocols.get(&protocol_id).unwrap();
match enabled_protocols.entry(protocol_id) {
Entry::Vacant(entry) => {
entry.insert((EnabledProtocol::PendingApprove, prot_handler.clone()));
prot_handler.protocol_requested(peer_id, protocol_tag.protocol_ver(), handshake);
}
Entry::Occupied(_) => {
warn!(
"Peer {:?} opened already enabled protocol {:?}",
peer_id, protocol_id
);
self.pending_actions
.push_back(NetworkBehaviourAction::NotifyHandler {
if let Some((_, prot_handler)) = self.supported_protocols.get(&protocol_id) {
match enabled_protocols.entry(protocol_id) {
Entry::Vacant(entry) => {
entry.insert((EnabledProtocol::PendingApprove, prot_handler.clone()));
prot_handler.protocol_requested(
peer_id,
handler: NotifyHandler::One(connection),
event: ConnHandlerIn::Close(protocol_id),
})
protocol_tag.protocol_ver(),
handshake,
);
}
Entry::Occupied(_) => {
warn!(
"Peer {:?} opened already enabled protocol {:?}",
peer_id, protocol_id
);
self.pending_actions
.push_back(NetworkBehaviourAction::NotifyHandler {
peer_id,
handler: NotifyHandler::One(connection),
event: ConnHandlerIn::Close(protocol_id),
})
}
}
} else {
self.pending_actions
.push_back(NetworkBehaviourAction::NotifyHandler {
peer_id,
handler: NotifyHandler::One(connection),
event: ConnHandlerIn::Close(protocol_id),
})
}
}
}
Expand Down

0 comments on commit 30721df

Please sign in to comment.