Bladeren bron

[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 jaren geleden
bovenliggende
commit
e4eb6754dd
1 gewijzigde bestanden met toevoegingen van 4 en 4 verwijderingen
  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