From 4c6768fd2b74918b8cd18cecced885ada1b238e1 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sat, 22 Jun 2019 13:40:41 -0700 Subject: [PATCH] fixup windows build --- src/config.rs | 3 ++ src/server/client.rs | 4 +-- src/server/listener.rs | 62 ++++++++++++++++++++++++------------------ 3 files changed, 41 insertions(+), 28 deletions(-) diff --git a/src/config.rs b/src/config.rs index 48407ed4f..cd158eea2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -373,6 +373,7 @@ pub struct DaemonOptions { } impl DaemonOptions { + #[cfg_attr(windows, allow(dead_code))] pub fn pid_file(&self) -> PathBuf { self.pid_file .as_ref() @@ -380,6 +381,7 @@ impl DaemonOptions { .unwrap_or_else(|| RUNTIME_DIR.join("pid")) } + #[cfg_attr(windows, allow(dead_code))] pub fn stdout(&self) -> PathBuf { self.stdout .as_ref() @@ -387,6 +389,7 @@ impl DaemonOptions { .unwrap_or_else(|| RUNTIME_DIR.join("log")) } + #[cfg_attr(windows, allow(dead_code))] pub fn stderr(&self) -> PathBuf { self.stderr .as_ref() diff --git a/src/server/client.rs b/src/server/client.rs index 2e16deb7c..c68c088cf 100644 --- a/src/server/client.rs +++ b/src/server/client.rs @@ -342,7 +342,7 @@ impl Client { key: tls_client .pem_private_key .as_ref() - .ok_or_else(|| failure::err_msg("missing mux_client_pem_private_key config value"))? + .ok_or_else(|| failure::err_msg("missing pem_private_key config value"))? .into(), cert: tls_client.pem_cert.clone(), chain: tls_client.pem_ca.clone(), @@ -350,7 +350,7 @@ impl Client { let connector = TlsConnector::builder() .identity(identity.try_into()?) - .danger_accept_invalid_hostnames(tls_client.accept_invalid_hostnames.unwrap_or(false)) + .danger_accept_invalid_hostnames(tls_client.accept_invalid_hostnames) .build()?; let stream = TcpStream::connect(remote_address) diff --git a/src/server/listener.rs b/src/server/listener.rs index 72a11b810..c85b6860f 100644 --- a/src/server/listener.rs +++ b/src/server/listener.rs @@ -158,6 +158,8 @@ impl TryFrom for Identity { mod not_ossl { use super::*; use native_tls::TlsAcceptor; + use std::convert::TryInto; + struct NetListener { acceptor: Arc, listener: TcpListener, @@ -206,6 +208,39 @@ mod not_ossl { } } } + + pub fn spawn_tls_listener( + _config: &Arc, + executor: Box, + tls_server: &TlsDomainServer, + ) -> Fallible<()> { + let identity = IdentitySource::PemFiles { + key: tls_server + .pem_private_key + .as_ref() + .ok_or_else(|| err_msg("missing pem_private_key config value"))? + .into(), + cert: tls_server.pem_cert.clone(), + chain: tls_server.pem_ca.clone(), + }; + + let mut net_listener = NetListener::new( + TcpListener::bind(&tls_server.bind_address).map_err(|e| { + format_err!( + "error binding to bind_address {}: {}", + tls_server.bind_address, + e + ) + })?, + TlsAcceptor::new(identity.try_into()?)?, + executor, + ); + thread::spawn(move || { + net_listener.run(); + }); + Ok(()) + } + } #[cfg(any(feature = "openssl", unix))] @@ -912,32 +947,7 @@ fn spawn_tls_listener( executor: Box, tls_server: &TlsDomainServer, ) -> Fallible<()> { - use std::convert::TryInto; - let identity = IdentitySource::PemFiles { - key: tls_server - .pem_private_key - .as_ref() - .ok_or_else(|| err_msg("missing mux_server_pem_private_key config value"))? - .into(), - cert: tls_server.pem_cert.clone(), - chain: tls_server.pem_ca.clone(), - }; - - let mut net_listener = NetListener::new( - TcpListener::bind(&tls_server.bind_address).map_err(|e| { - format_err!( - "error binding to mux_server_bind_address {}: {}", - tls_server.bind_address, - e - ) - })?, - TlsAcceptor::new(identity.try_into()?)?, - executor, - ); - thread::spawn(move || { - net_listener.run(); - }); - Ok(()) + not_ossl::spawn_tls_listener(config, executor, tls_server) } pub fn spawn_listener(config: &Arc, executor: Box) -> Fallible<()> {