Skip to content

Commit

Permalink
ban peer unexpected response
Browse files Browse the repository at this point in the history
  • Loading branch information
SWvheerden committed Aug 3, 2023
1 parent b1708fc commit a46df95
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions base_layer/core/src/base_node/comms_interface/inbound_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -618,10 +618,10 @@ where B: BlockchainBackend + 'static
match self
.outbound_nci
.request_blocks_by_hashes_from_peer(block_hash, Some(source_peer.clone()))
.await?
.await
{
Some(block) => Ok(block),
None => {
Ok(Some(block)) => Ok(block),
Ok(None) => {
if let Err(e) = self
.connectivity
.ban_peer_until(
Expand All @@ -643,6 +643,21 @@ where B: BlockchainBackend + 'static
source_peer
)))
},
Err(CommsInterfaceError::UnexpectedApiResponse) => {
debug!(
target: LOG_TARGET,
"Peer `{}` sent unexpected API response.", source_peer
);
if let Err(e) = self
.connectivity
.ban_peer(source_peer.clone(), format!("Peer sen invalid API response"))
.await
{
error!(target: LOG_TARGET, "Failed to ban peer: {}", e);
}
Err(CommsInterfaceError::UnexpectedApiResponse)
},
Err(e) => Err(e),
}
}

Expand Down

0 comments on commit a46df95

Please sign in to comment.