mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
net/channel: Add helpful debugging error calls
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user