net/channel: Add helpful debugging error calls

This commit is contained in:
parazyd
2024-07-09 12:28:36 +02:00
parent 27fd3785f8
commit 3bdae810b3

View File

@@ -392,19 +392,32 @@ impl Channel {
/// Ban a malicious peer and stop the channel.
pub async fn ban(&self, peer: &Url) {
debug!(target: "net::channel::ban()", "START {:?}", self);
debug!(target: "net::channel::ban()", "Peer: {:?}", peer);
// Just store the hostname if this is an inbound session.
// This will block all ports from this peer by setting
// `hosts.block_all_ports()` to true.
let peer = {
if self.session_type_id() & SESSION_INBOUND != 0 {
&Url::parse(peer.host_str().unwrap()).unwrap()
if peer.host_str().is_none() {
error!("[P2P] ban() caught Url without host: {:?}", peer);
return
}
match Url::parse(peer.host_str().unwrap()) {
Ok(v) => v,
Err(e) => {
error!("[P2P] ban() failed to parse {:?}: {}", peer, e);
return
}
}
} else {
peer
peer.clone()
}
};
let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
self.p2p().hosts().move_host(peer, last_seen, HostColor::Black).unwrap();
self.p2p().hosts().move_host(&peer, last_seen, HostColor::Black).unwrap();
self.stop().await;
debug!(target: "net::channel::ban()", "STOP {:?}", self);
}