瀏覽代碼

[net] Tor dialers: return error instead of panic

Refactor the Tor Dialers to return an error instead of panicking via
unwrap(). In any case, we don't expect this to happen because new
dialers are instantiated using a macro that ensures that endpoints have
valid hosts and ports.
y 2 年之前
父節點
當前提交
e4eb6754dd
共有 1 個文件被更改,包括 4 次插入4 次删除
  1. 4 4
      src/net/transport/mod.rs

+ 4 - 4
src/net/transport/mod.rs

@@ -214,8 +214,8 @@ impl Dialer {
 
             #[cfg(feature = "p2p-tor")]
             DialerVariant::Tor(dialer) => {
-                let host = self.endpoint.host_str().unwrap();
-                let port = self.endpoint.port().unwrap();
+                let host = self.endpoint.host_str().ok_or(Error::InvalidDialerScheme)?;
+                let port = self.endpoint.port().ok_or(Error::InvalidDialerScheme)?;
                 // Extract error reports (i.e. very detailed debugging)
                 // from arti-client in order to help debug Tor connections.
                 // https://docs.rs/arti-client/latest/arti_client/#reporting-arti-errors
@@ -233,8 +233,8 @@ impl Dialer {
 
             #[cfg(feature = "p2p-tor")]
             DialerVariant::TorTls(dialer) => {
-                let host = self.endpoint.host_str().unwrap();
-                let port = self.endpoint.port().unwrap();
+                let host = self.endpoint.host_str().ok_or(Error::InvalidDialerScheme)?;
+                let port = self.endpoint.port().ok_or(Error::InvalidDialerScheme)?;
                 // Extract error reports (i.e. very detailed debugging)
                 // from arti-client in order to help debug Tor connections.
                 // https://docs.rs/arti-client/latest/arti_client/#reporting-arti-errors