Преглед изворни кода

net/channel: Add helpful debugging error calls

parazyd пре 2 година
родитељ
комит
3bdae810b3
1 измењених фајлова са 16 додато и 3 уклоњено
  1. 16 3
      src/net/channel.rs

+ 16 - 3
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);
     }