Просмотр исходного кода

[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 лет назад
Родитель
Сommit
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")]
             #[cfg(feature = "p2p-tor")]
             DialerVariant::Tor(dialer) => {
             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)
                 // Extract error reports (i.e. very detailed debugging)
                 // from arti-client in order to help debug Tor connections.
                 // from arti-client in order to help debug Tor connections.
                 // https://docs.rs/arti-client/latest/arti_client/#reporting-arti-errors
                 // https://docs.rs/arti-client/latest/arti_client/#reporting-arti-errors
@@ -233,8 +233,8 @@ impl Dialer {
 
 
             #[cfg(feature = "p2p-tor")]
             #[cfg(feature = "p2p-tor")]
             DialerVariant::TorTls(dialer) => {
             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)
                 // Extract error reports (i.e. very detailed debugging)
                 // from arti-client in order to help debug Tor connections.
                 // from arti-client in order to help debug Tor connections.
                 // https://docs.rs/arti-client/latest/arti_client/#reporting-arti-errors
                 // https://docs.rs/arti-client/latest/arti_client/#reporting-arti-errors