diff --git a/src/net/channel.rs b/src/net/channel.rs index 95ec7d7a5..8a5a649aa 100644 --- a/src/net/channel.rs +++ b/src/net/channel.rs @@ -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); }