From 09328c79d556c22f9b36cef8f7010bfff3f093a8 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sat, 7 Oct 2023 13:33:44 +0200 Subject: feat(tvix/store/listener): implement connect_info() For Unix and TCP streams, we can actually give more info than just (). Change-Id: I80ca261b9e7a880389ec2029ea5893180314f0b2 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9561 Autosubmit: flokli Tested-by: BuildkiteCI Reviewed-by: Connor Brewster --- tvix/store/src/listener/mod.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'tvix') diff --git a/tvix/store/src/listener/mod.rs b/tvix/store/src/listener/mod.rs index 3a44a0511cb8..ed1220803562 100644 --- a/tvix/store/src/listener/mod.rs +++ b/tvix/store/src/listener/mod.rs @@ -9,7 +9,7 @@ use futures::Stream; use pin_project_lite::pin_project; use tokio::io::{AsyncRead, AsyncWrite}; use tokio_listener::{Listener, ListenerAddress}; -use tonic::transport::server::Connected; +use tonic::transport::server::{Connected, TcpConnectInfo, UdsConnectInfo}; /// A wrapper around a [Listener] which implements the [Stream] trait. /// Mainly used to bridge [tokio_listener] with [tonic]. @@ -72,11 +72,27 @@ impl DerefMut for Connection { } } +#[derive(Clone)] +pub enum ListenerConnectInfo { + TCP(TcpConnectInfo), + Unix(UdsConnectInfo), + Stdio, + Other, +} + impl Connected for Connection { - type ConnectInfo = (); + type ConnectInfo = ListenerConnectInfo; fn connect_info(&self) -> Self::ConnectInfo { - () + if let Some(tcp_stream) = self.try_borrow_tcp() { + ListenerConnectInfo::TCP(tcp_stream.connect_info()) + } else if let Some(unix_stream) = self.try_borrow_unix() { + ListenerConnectInfo::Unix(unix_stream.connect_info()) + } else if let Some(_) = self.try_borrow_stdio() { + ListenerConnectInfo::Stdio + } else { + ListenerConnectInfo::Other + } } } -- cgit 1.4.1