|
@@ -392,19 +392,32 @@ impl Channel {
|
|
|
/// Ban a malicious peer and stop the channel.
|
|
/// Ban a malicious peer and stop the channel.
|
|
|
pub async fn ban(&self, peer: &Url) {
|
|
pub async fn ban(&self, peer: &Url) {
|
|
|
debug!(target: "net::channel::ban()", "START {:?}", self);
|
|
debug!(target: "net::channel::ban()", "START {:?}", self);
|
|
|
|
|
+ debug!(target: "net::channel::ban()", "Peer: {:?}", peer);
|
|
|
|
|
|
|
|
// Just store the hostname if this is an inbound session.
|
|
// Just store the hostname if this is an inbound session.
|
|
|
// This will block all ports from this peer by setting
|
|
// This will block all ports from this peer by setting
|
|
|
// `hosts.block_all_ports()` to true.
|
|
// `hosts.block_all_ports()` to true.
|
|
|
let peer = {
|
|
let peer = {
|
|
|
if self.session_type_id() & SESSION_INBOUND != 0 {
|
|
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 {
|
|
} else {
|
|
|
- peer
|
|
|
|
|
|
|
+ peer.clone()
|
|
|
}
|
|
}
|
|
|
};
|
|
};
|
|
|
|
|
+
|
|
|
let last_seen = UNIX_EPOCH.elapsed().unwrap().as_secs();
|
|
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;
|
|
self.stop().await;
|
|
|
debug!(target: "net::channel::ban()", "STOP {:?}", self);
|
|
debug!(target: "net::channel::ban()", "STOP {:?}", self);
|
|
|
}
|
|
}
|