Skip to content
10 changes: 9 additions & 1 deletion pingora-core/src/listeners/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub mod tls;
#[cfg(not(feature = "any_tls"))]
pub use crate::tls::listeners as tls;

use crate::protocols::{tls::TlsRef, Stream};
use crate::protocols::{l4::socket::SocketAddr, tls::TlsRef, Stream};

#[cfg(unix)]
use crate::server::ListenFds;
Expand All @@ -35,6 +35,7 @@ use l4::{ListenerEndpoint, Stream as L4Stream};
use tls::{Acceptor, TlsSettings};

pub use crate::protocols::tls::ALPN;
use crate::protocols::GetSocketDigest;
pub use l4::{ServerAddress, TcpSocketOptions};

/// The APIs to customize things like certificate during TLS server side handshake
Expand Down Expand Up @@ -118,6 +119,13 @@ impl UninitializedStream {
Ok(Box::new(self.l4))
}
}

/// Get the peer address of the connection if available
pub fn peer_addr(&self) -> Option<SocketAddr> {
self.l4
.get_socket_digest()
.and_then(|d| d.peer_addr().cloned())
}
}

/// The struct to hold one more multiple listening endpoints
Expand Down
9 changes: 7 additions & 2 deletions pingora-core/src/services/listening.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,16 @@ impl<A: ServerApp + Send + Sync + 'static> Service<A> {
let app = app_logic.clone();
let shutdown = shutdown.clone();
current_handle().spawn(async move {
let peer_addr = io.peer_addr();
match io.handshake().await {
Ok(io) => Self::handle_event(io, app, shutdown).await,
Err(e) => {
// TODO: Maybe IOApp trait needs a fn to handle/filter our this error
error!("Downstream handshake error {e}");
// TODO: Maybe IOApp trait needs a fn to handle/filter out this error
if let Some(addr) = peer_addr {
error!("Downstream handshake error from {}: {e}", addr);
Comment thread
jsulmont marked this conversation as resolved.
} else {
error!("Downstream handshake error: {e}");
}
}
}
});
Expand Down
Loading