소스 검색

[net] tor-dialer: revert to panic and document why

y 2 년 전
부모
커밋
521bc801fa
1개의 변경된 파일9개의 추가작업 그리고 4개의 파일을 삭제
  1. 9 4
      src/net/transport/mod.rs

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

@@ -193,6 +193,11 @@ impl Dialer {
     }
 
     /// Dial an instantiated [`Dialer`]. This creates a connection and returns a stream.
+
+    /// The Tor-based Dialer variants can panic: this is intended. There exists validation
+    /// for hosts and ports in other parts of the codebase. A panic occurring here
+    /// likely indicates a configuration issue on the part of the user. It is preferable
+    /// in this case that the user is alerted to this problem via a panic.
     pub async fn dial(&self, timeout: Option<Duration>) -> Result<Box<dyn PtStream>> {
         match &self.variant {
             #[cfg(feature = "p2p-tcp")]
@@ -214,8 +219,8 @@ impl Dialer {
 
             #[cfg(feature = "p2p-tor")]
             DialerVariant::Tor(dialer) => {
-                let host = self.endpoint.host_str().ok_or(Error::InvalidDialerScheme)?;
-                let port = self.endpoint.port().ok_or(Error::InvalidDialerScheme)?;
+                let host = self.endpoint.host_str().unwrap();
+                let port = self.endpoint.port().unwrap();
                 // 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 +238,8 @@ impl Dialer {
 
             #[cfg(feature = "p2p-tor")]
             DialerVariant::TorTls(dialer) => {
-                let host = self.endpoint.host_str().ok_or(Error::InvalidDialerScheme)?;
-                let port = self.endpoint.port().ok_or(Error::InvalidDialerScheme)?;
+                let host = self.endpoint.host_str().unwrap();
+                let port = self.endpoint.port().unwrap();
                 // 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