Skip to content

Commit

Permalink
fix: attempt to add windows compatibility
Browse files Browse the repository at this point in the history
Windows will not be able to run tests
  • Loading branch information
mmtftr committed Feb 28, 2025
1 parent 90afc85 commit 46151df
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 18 deletions.
46 changes: 29 additions & 17 deletions core/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,23 +55,35 @@ where
.into_iter()
.map(|endpoint| async move {
let channel = if endpoint.starts_with("unix://") {
// Handle Unix socket
let path = endpoint.trim_start_matches("unix://").to_string();
Channel::from_static("lttp://[::]:50051")
.connect_with_connector(tower::service_fn(move |_| {
let path = PathBuf::from(path.clone());
async move {
let unix_stream = tokio::net::UnixStream::connect(path).await?;
Ok::<_, std::io::Error>(TokioIo::new(unix_stream))
}
}))
.await
.map_err(|e| {
BridgeError::ConfigError(format!(
"Failed to connect to Unix socket {}: {}",
endpoint, e
))
})?
#[cfg(unix)]
{
// Handle Unix socket (only available on Unix platforms)
let path = endpoint.trim_start_matches("unix://").to_string();
Channel::from_static("lttp://[::]:50051")
.connect_with_connector(tower::service_fn(move |_| {
let path = PathBuf::from(path.clone());
async move {
let unix_stream = tokio::net::UnixStream::connect(path).await?;
Ok::<_, std::io::Error>(TokioIo::new(unix_stream))
}
}))
.await
.map_err(|e| {
BridgeError::ConfigError(format!(
"Failed to connect to Unix socket {}: {}",
endpoint, e
))
})?
}

#[cfg(not(unix))]
{
// Windows doesn't support Unix sockets
return Err(BridgeError::ConfigError(format!(
"Unix sockets ({}), are not supported on this platform",
endpoint
)));
}
} else {
// Handle TCP/HTTP connection
let uri = Uri::try_from(endpoint.clone()).map_err(|e| {
Expand Down
47 changes: 46 additions & 1 deletion core/src/servers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ fn is_test_env() -> bool {
#[derive(Debug, Clone)]
pub enum ServerAddr {
Tcp(std::net::SocketAddr),
#[cfg(unix)]
Unix(std::path::PathBuf),
}

Expand All @@ -36,6 +37,7 @@ impl From<std::net::SocketAddr> for ServerAddr {
}
}

#[cfg(unix)]
impl From<std::path::PathBuf> for ServerAddr {
fn from(path: std::path::PathBuf) -> Self {
ServerAddr::Unix(path)
Expand Down Expand Up @@ -88,6 +90,7 @@ where
}
});
}
#[cfg(unix)]
ServerAddr::Unix(ref socket_path) => {
tracing::info!(
"Starting {} gRPC server with Unix socket: {:?}",
Expand Down Expand Up @@ -211,6 +214,7 @@ pub async fn create_watchtower_grpc_server(
}

// Functions for creating servers with Unix sockets (useful for tests)
#[cfg(unix)]
pub async fn create_verifier_unix_server(
config: BridgeConfig,
socket_path: std::path::PathBuf,
Expand All @@ -234,6 +238,17 @@ pub async fn create_verifier_unix_server(
}
}

#[cfg(not(unix))]
pub async fn create_verifier_unix_server(
_config: BridgeConfig,
_socket_path: std::path::PathBuf,
) -> Result<(std::path::PathBuf, oneshot::Sender<()>), BridgeError> {
Err(BridgeError::ConfigError(
"Unix sockets are not supported on this platform".into(),
))
}

#[cfg(unix)]
pub async fn create_operator_unix_server(
config: BridgeConfig,
socket_path: std::path::PathBuf,
Expand All @@ -257,6 +272,17 @@ pub async fn create_operator_unix_server(
}
}

#[cfg(not(unix))]
pub async fn create_operator_unix_server(
_config: BridgeConfig,
_socket_path: std::path::PathBuf,
) -> Result<(std::path::PathBuf, oneshot::Sender<()>), BridgeError> {
Err(BridgeError::ConfigError(
"Unix sockets are not supported on this platform".into(),
))
}

#[cfg(unix)]
pub async fn create_aggregator_unix_server(
config: BridgeConfig,
socket_path: std::path::PathBuf,
Expand All @@ -273,6 +299,17 @@ pub async fn create_aggregator_unix_server(
}
}

#[cfg(not(unix))]
pub async fn create_aggregator_unix_server(
_config: BridgeConfig,
_socket_path: std::path::PathBuf,
) -> Result<(std::path::PathBuf, oneshot::Sender<()>), BridgeError> {
Err(BridgeError::ConfigError(
"Unix sockets are not supported on this platform".into(),
))
}

#[cfg(unix)]
pub async fn create_watchtower_unix_server(
config: BridgeConfig,
socket_path: std::path::PathBuf,
Expand All @@ -289,4 +326,12 @@ pub async fn create_watchtower_unix_server(
}
}

// Similar Unix socket functions can be added for other server types as needed
#[cfg(not(unix))]
pub async fn create_watchtower_unix_server(
_config: BridgeConfig,
_socket_path: std::path::PathBuf,
) -> Result<(std::path::PathBuf, oneshot::Sender<()>), BridgeError> {
Err(BridgeError::ConfigError(
"Unix sockets are not supported on this platform".into(),
))
}

0 comments on commit 46151df

Please sign in to comment.