diff options
author | Andrew Hauck <[email protected]> | 2024-10-22 08:45:24 -0700 |
---|---|---|
committer | Yuchen Wu <[email protected]> | 2024-11-01 10:32:08 -0700 |
commit | 9a159869f2ec281d11c0a131d47a37a5bd0eba51 (patch) | |
tree | 26f25d8085b24780e2e02d9b062a8a2f26fb0ecd | |
parent | ab6f84cf8bbc023dfca31b58256e4d506a67298c (diff) | |
download | pingora-9a159869f2ec281d11c0a131d47a37a5bd0eba51.tar.gz pingora-9a159869f2ec281d11c0a131d47a37a5bd0eba51.zip |
Use OkOrErr on connect() + accept() when stream doesn't exist
-rw-r--r-- | .bleep | 2 | ||||
-rw-r--r-- | pingora-core/src/protocols/tls/rustls/stream.rs | 46 |
2 files changed, 20 insertions, 28 deletions
@@ -1 +1 @@ -93a8806fd5a1e6df065f20bc40e9594fde0a21db
\ No newline at end of file +d715e2d7a34ba00f8872339d4596b2e1e68de304
\ No newline at end of file diff --git a/pingora-core/src/protocols/tls/rustls/stream.rs b/pingora-core/src/protocols/tls/rustls/stream.rs index 9cdd2a7..a2c6811 100644 --- a/pingora-core/src/protocols/tls/rustls/stream.rs +++ b/pingora-core/src/protocols/tls/rustls/stream.rs @@ -27,7 +27,7 @@ use crate::protocols::{ }; use crate::utils::tls::get_organization_serial_bytes; use pingora_error::ErrorType::{AcceptError, ConnectError, InternalError, TLSHandshakeFailure}; -use pingora_error::{Error, ImmutStr, OrErr, Result}; +use pingora_error::{OkOrErr, OrErr, Result}; use pingora_rustls::TlsStream as RusTlsStream; use pingora_rustls::{hash_certificate, NoDebug}; use pingora_rustls::{Accept, Connect, ServerName, TlsConnector}; @@ -273,40 +273,32 @@ impl<T: AsyncRead + AsyncWrite + Unpin + Send> InnerStream<T> { /// Connect to the remote TLS server as a client pub(crate) async fn connect(&mut self) -> Result<()> { let connect = &mut (*self.connect); + let connect = connect.take().or_err( + ConnectError, + "TLS connect not available to perform handshake.", + )?; - if let Some(connect) = connect.take() { - let stream = connect - .await - .or_err(TLSHandshakeFailure, "tls connect error")?; - self.stream = Some(RusTlsStream::Client(stream)); - - Ok(()) - } else { - Error::e_explain( - ConnectError, - ImmutStr::from("TLS connect not available to perform handshake."), - ) - } + let stream = connect + .await + .or_err(TLSHandshakeFailure, "tls connect error")?; + self.stream = Some(RusTlsStream::Client(stream)); + Ok(()) } /// Finish the TLS handshake from client as a server /// no-op implementation within Rustls, handshake is performed during creation of stream. pub(crate) async fn accept(&mut self) -> Result<()> { let accept = &mut (*self.accept); + let accept = accept.take().or_err( + AcceptError, + "TLS accept not available to perform handshake.", + )?; - if let Some(ref mut accept) = accept.take() { - let stream = accept - .await - .explain_err(TLSHandshakeFailure, |e| format!("tls connect error: {e}"))?; - self.stream = Some(RusTlsStream::Server(stream)); - - Ok(()) - } else { - Err(Error::explain( - AcceptError, - ImmutStr::from("TLS accept not available to perform handshake."), - )) - } + let stream = accept + .await + .explain_err(TLSHandshakeFailure, |e| format!("tls connect error: {e}"))?; + self.stream = Some(RusTlsStream::Server(stream)); + Ok(()) } pub(crate) fn digest(&mut self) -> Option<Arc<SslDigest>> { |