aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrew Hauck <[email protected]>2024-10-22 08:45:24 -0700
committerAndrew Hauck <[email protected]>2024-10-28 15:30:43 +0000
commit8f257a6b692bb5d51a489ca4b672efe46905ed11 (patch)
tree26f25d8085b24780e2e02d9b062a8a2f26fb0ecd
parentab6f84cf8bbc023dfca31b58256e4d506a67298c (diff)
downloadpingora-8f257a6b692bb5d51a489ca4b672efe46905ed11.tar.gz
pingora-8f257a6b692bb5d51a489ca4b672efe46905ed11.zip
Use OkOrErr on connect() + accept() when stream doesn't exist
-rw-r--r--.bleep2
-rw-r--r--pingora-core/src/protocols/tls/rustls/stream.rs46
2 files changed, 20 insertions, 28 deletions
diff --git a/.bleep b/.bleep
index 6be531e..bd43cdc 100644
--- a/.bleep
+++ b/.bleep
@@ -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>> {