diff --git a/Cargo.lock b/Cargo.lock index ec62a37a..1e1511c6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,15 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "addr2line" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4fa78e18c64fce05e902adecd7a5eed15a5e0a3439f7b0e169f0252214865e3" +dependencies = [ + "gimli", +] + [[package]] name = "adler" version = "1.0.2" @@ -29,6 +38,21 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "backtrace" +version = "0.3.68" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4319208da049c43661739c5fade2ba182f09d1dc2299b32298d3a31692b17e12" +dependencies = [ + "addr2line", + "cc", + "cfg-if", + "libc", + "miniz_oxide 0.7.1", + "object", + "rustc-demangle", +] + [[package]] name = "base64" version = "0.13.1" @@ -166,7 +190,8 @@ version = "0.6.1" dependencies = [ "anyhow", "figment", - "futures", + "flexible-hyper-server-tls", + "futures-util", "getrandom", "hex", "hyper", @@ -177,11 +202,9 @@ dependencies = [ "psutil", "pty-process", "ring", - "rustls-pemfile", "serde", "serde_json", "tokio", - "tokio-rustls", "tokio-tungstenite", "tracing", "tracing-subscriber", @@ -221,7 +244,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841" dependencies = [ "crc32fast", - "miniz_oxide", + "miniz_oxide 0.6.2", +] + +[[package]] +name = "flexible-hyper-server-tls" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87651e5b8ed9cb4a20c04296bfae1a4d10cf2546f0e057328ccb742c55fbc91e" +dependencies = [ + "futures-util", + "hyper", + "rustls-pemfile", + "thiserror", + "tokio", + "tokio-rustls", ] [[package]] @@ -239,21 +276,6 @@ dependencies = [ "percent-encoding", ] -[[package]] -name = "futures" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" -dependencies = [ - "futures-channel", - "futures-core", - "futures-executor", - "futures-io", - "futures-sink", - "futures-task", - "futures-util", -] - [[package]] name = "futures-channel" version = "0.3.28" @@ -261,7 +283,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" dependencies = [ "futures-core", - "futures-sink", ] [[package]] @@ -270,34 +291,6 @@ version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" -[[package]] -name = "futures-executor" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" -dependencies = [ - "futures-core", - "futures-task", - "futures-util", -] - -[[package]] -name = "futures-io" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" - -[[package]] -name = "futures-macro" -version = "0.3.28" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.25", -] - [[package]] name = "futures-sink" version = "0.3.28" @@ -316,13 +309,9 @@ version = "0.3.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" dependencies = [ - "futures-channel", "futures-core", - "futures-io", - "futures-macro", "futures-sink", "futures-task", - "memchr", "pin-project-lite", "pin-utils", "slab", @@ -349,6 +338,12 @@ dependencies = [ "wasi", ] +[[package]] +name = "gimli" +version = "0.27.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c80984affa11d98d1b88b66ac8853f143217b399d3c74116778ff8fdb4ed2e" + [[package]] name = "glob" version = "0.3.1" @@ -444,7 +439,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2cfc4a06638d2fd0dda83b01126fefd38ef9f04f54d2fc717a938df68b83a68d" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -565,6 +560,15 @@ dependencies = [ "adler", ] +[[package]] +name = "miniz_oxide" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7" +dependencies = [ + "adler", +] + [[package]] name = "mio" version = "0.8.6" @@ -574,7 +578,7 @@ dependencies = [ "libc", "log", "wasi", - "windows-sys", + "windows-sys 0.45.0", ] [[package]] @@ -624,6 +628,15 @@ dependencies = [ "libc", ] +[[package]] +name = "object" +version = "0.31.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8bda667d9f2b5051b8833f59f3bf748b28ef54f850f4fcb389a252aa383866d1" +dependencies = [ + "memchr", +] + [[package]] name = "once_cell" version = "1.18.0" @@ -795,11 +808,17 @@ dependencies = [ "winapi", ] +[[package]] +name = "rustc-demangle" +version = "0.1.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" + [[package]] name = "rustls" -version = "0.21.0" +version = "0.21.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07180898a28ed6a7f7ba2311594308f595e3dd2e3c3812fa0a80a47b45f17e5d" +checksum = "79ea77c539259495ce8ca47f53e66ae0330a8819f67e23ac96ca02f50e7b7d36" dependencies = [ "log", "ring", @@ -818,9 +837,9 @@ dependencies = [ [[package]] name = "rustls-webpki" -version = "0.100.1" +version = "0.101.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6207cd5ed3d8dca7816f8f3725513a34609c0c765bf652b8c3cb4cfd87db46b" +checksum = "15f36a6828982f422756984e47912a7a51dcbc2a197aa791158f8ca61cd8204e" dependencies = [ "ring", "untrusted", @@ -972,22 +991,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.39" +version = "1.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a5ab016db510546d856297882807df8da66a16fb8c4101cb8b30054b0d5b2d9c" +checksum = "611040a08a0439f8248d1990b111c95baa9c704c805fa1f62104b39655fd7f90" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.39" +version = "1.0.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5420d42e90af0c38c3290abcca25b9b3bdf379fc9f55c528f53a269d9c9a267e" +checksum = "090198534930841fab3a5d1bb637cde49e339654e606195f8d9c76eeb081dc96" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.25", ] [[package]] @@ -1033,31 +1052,31 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.26.0" +version = "1.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03201d01c3c27a29c8a5cee5b55a93ddae1ccf6f08f65365c2c918f8c1b76f64" +checksum = "532826ff75199d5833b9d2c5fe410f29235e25704ee5f0ef599fb51c21f4a4da" dependencies = [ "autocfg", + "backtrace", "bytes", "libc", - "memchr", "mio", "pin-project-lite", "signal-hook-registry", "socket2", "tokio-macros", - "windows-sys", + "windows-sys 0.48.0", ] [[package]] name = "tokio-macros" -version = "1.8.2" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d266c00fde287f55d3f1c3e96c500c362a2b8c695076ec180f27918820bc6df8" +checksum = "630bdcf245f78637c13ec01ffae6187cca34625e8c63150d424b59e55af2675e" dependencies = [ "proc-macro2", "quote", - "syn 1.0.109", + "syn 2.0.25", ] [[package]] @@ -1423,7 +1442,16 @@ version = "0.45.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" dependencies = [ - "windows-targets", + "windows-targets 0.42.2", +] + +[[package]] +name = "windows-sys" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +dependencies = [ + "windows-targets 0.48.1", ] [[package]] @@ -1432,13 +1460,28 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.42.2", + "windows_aarch64_msvc 0.42.2", + "windows_i686_gnu 0.42.2", + "windows_i686_msvc 0.42.2", + "windows_x86_64_gnu 0.42.2", + "windows_x86_64_gnullvm 0.42.2", + "windows_x86_64_msvc 0.42.2", +] + +[[package]] +name = "windows-targets" +version = "0.48.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05d4b17490f70499f20b9e791dcf6a299785ce8af4d709018206dc5b4953e95f" +dependencies = [ + "windows_aarch64_gnullvm 0.48.0", + "windows_aarch64_msvc 0.48.0", + "windows_i686_gnu 0.48.0", + "windows_i686_msvc 0.48.0", + "windows_x86_64_gnu 0.48.0", + "windows_x86_64_gnullvm 0.48.0", + "windows_x86_64_msvc 0.48.0", ] [[package]] @@ -1447,42 +1490,84 @@ version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" + [[package]] name = "windows_aarch64_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +[[package]] +name = "windows_aarch64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" + [[package]] name = "windows_i686_gnu" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" +[[package]] +name = "windows_i686_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" + [[package]] name = "windows_i686_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" +[[package]] +name = "windows_i686_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" + [[package]] name = "windows_x86_64_gnu" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" +[[package]] +name = "windows_x86_64_gnu" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" + [[package]] name = "windows_x86_64_gnullvm" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" + [[package]] name = "windows_x86_64_msvc" version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +[[package]] +name = "windows_x86_64_msvc" +version = "0.48.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" + [[package]] name = "yansi" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index acbe1d2f..5e3d3893 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,7 +14,6 @@ tokio = { version = "1", features = [ "fs", "process", ] } -futures = "0.3.28" pty-process = { version = "0.3.0", features = ["async"] } psutil = "3.2.2" ring = "0.16.20" @@ -29,14 +28,14 @@ once_cell = "1.18.0" serde_json = "1.0.103" tracing = { version = "0.1.38", features = ["release_max_level_debug"] } tracing-subscriber = "0.3.17" -hyper = { version = "0.14.27", features = ["server", "http1", "tcp"] } +hyper = { version = "0.14.27", features = ["server", "http1"] } tokio-tungstenite = "0.20.0" -tokio-rustls = "0.24.1" -rustls-pemfile = "1.0.3" getrandom = "0.2.10" hex = "0.4.3" vite-embed = { git = "https://github.com/ravenclaw900/vite-embed", version = "0.1.0", features = ["prod"], optional = true } mime_guess = { version = "2.0.4", default-features = false } +flexible-hyper-server-tls = "0.1.1" +futures-util = { version = "0.3.28", default-features = false } [features] default = ["frontend"] diff --git a/src/main.rs b/src/main.rs index f998533d..aa801724 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,7 +16,6 @@ mod routes; mod shared; mod socket_handlers; mod systemdata; -mod tls; #[tokio::main(flavor = "current_thread")] async fn main() -> anyhow::Result<()> { @@ -37,7 +36,7 @@ async fn main() -> anyhow::Result<()> { .await .with_context(|| format!("Couldn't bind to {}", &addr))?; - let make_svc = make_service_fn(|conn: &tls::TlsOrTcpConnection| { + let make_svc = make_service_fn(|conn: &flexible_hyper_server_tls::HttpOrHttpsConnection| { let remote_addr = conn.remote_addr(); async move { Ok::<_, std::convert::Infallible>(service_fn(move |req| async move { @@ -56,51 +55,30 @@ async fn main() -> anyhow::Result<()> { } }); - let mut acceptor = if CONFIG.tls { - let tls_cfg = { - let certs = rustls_pemfile::certs(&mut std::io::BufReader::new( - std::fs::File::open(&CONFIG.cert).context("Couldn't open cert file")?, - )) - .context("Couldn't read certs")? - .into_iter() - .map(tokio_rustls::rustls::Certificate) - .collect(); + let acceptor = if CONFIG.tls { + let tls_acceptor = flexible_hyper_server_tls::tlsconfig::get_tlsacceptor_from_files( + &CONFIG.cert, + &CONFIG.key, + flexible_hyper_server_tls::tlsconfig::HttpProtocol::Http1, + ) + .context("Couldn't get TLS config")?; - let key = match rustls_pemfile::read_one(&mut std::io::BufReader::new( - std::fs::File::open(&CONFIG.key).context("Couldn't open cert file")?, - )) - .context("Couldn't read key")? - .context("No private key")? - { - rustls_pemfile::Item::PKCS8Key(vec) | rustls_pemfile::Item::RSAKey(vec) => { - tokio_rustls::rustls::PrivateKey(vec) - } - _ => anyhow::bail!("No PKCS8 or RSA formatted private key"), - }; - - let mut cfg = tokio_rustls::rustls::ServerConfig::builder() - .with_safe_defaults() - .with_no_client_auth() - .with_single_cert(certs, key) - .context("Couldn't build TLS config")?; - cfg.alpn_protocols = vec![b"http/1.1".to_vec()]; - std::sync::Arc::new(cfg) - }; - - tls::HyperTlsOrTcpAcceptor::new(tcp, Some(tokio_rustls::TlsAcceptor::from(tls_cfg))) + flexible_hyper_server_tls::HyperHttpOrHttpsAcceptor::new_https( + tcp, + tls_acceptor, + std::time::Duration::from_secs(10), + ) } else { - tls::HyperTlsOrTcpAcceptor::new(tcp, None) + flexible_hyper_server_tls::HyperHttpOrHttpsAcceptor::new_http(tcp) }; + let mut server = hyper::server::Server::builder(acceptor).serve(make_svc); + // Ignore result, because it will never be an error loop { - let _res = hyper::server::Server::builder(&mut acceptor) - .serve(make_svc) - .await - .context("Server error") - .or_else(|e| { - tracing::warn!("{:?}", e); - anyhow::Ok(()) - }); + let _res = (&mut server).await.context("Server error").or_else(|e| { + tracing::warn!("{:?}", e); + anyhow::Ok(()) + }); } } diff --git a/src/routes.rs b/src/routes.rs index 8c67f146..6e266e05 100644 --- a/src/routes.rs +++ b/src/routes.rs @@ -1,7 +1,7 @@ use crate::handle_error; use crate::shared::CONFIG; use anyhow::Context; -use futures::Future; +use futures_util::Future; use hyper::http::{header, HeaderValue}; use hyper::{Body, Method, Request, Response, StatusCode}; use ring::digest; diff --git a/src/shared.rs b/src/shared.rs index a69ff20e..3c72e5ef 100644 --- a/src/shared.rs +++ b/src/shared.rs @@ -1,5 +1,5 @@ use anyhow::Context; -use futures::SinkExt; +use futures_util::SinkExt; use serde::{Deserialize, Serialize}; pub static CONFIG: once_cell::sync::Lazy = @@ -64,7 +64,7 @@ pub fn get_fingerprint(req: &hyper::Request) -> anyhow::Result, tokio_tungstenite::tungstenite::Message, >, diff --git a/src/socket_handlers.rs b/src/socket_handlers.rs index e71c35b1..7fc192c2 100644 --- a/src/socket_handlers.rs +++ b/src/socket_handlers.rs @@ -1,5 +1,5 @@ use anyhow::Context; -use futures::{SinkExt, StreamExt}; +use futures_util::{SinkExt, StreamExt}; use std::io::Write; use tokio::io::{AsyncReadExt, AsyncWriteExt}; use tokio::sync::mpsc; diff --git a/src/tls.rs b/src/tls.rs deleted file mode 100644 index 08bef028..00000000 --- a/src/tls.rs +++ /dev/null @@ -1,142 +0,0 @@ -use anyhow::Context; -use futures::FutureExt; -use std::task::Poll; - -#[allow(clippy::module_name_repetitions)] -pub enum TlsOrTcpConnection { - Plain(tokio::net::TcpStream, std::net::SocketAddr), - Tls( - Box>, - std::net::SocketAddr, - ), -} - -pub struct HyperTlsOrTcpAcceptor { - listener: tokio::net::TcpListener, - acceptor: Option, - accept_future: Option>, - remote_addr: Option, -} - -impl HyperTlsOrTcpAcceptor { - pub const fn new( - listener: tokio::net::TcpListener, - acceptor: Option, - ) -> Self { - Self { - listener, - acceptor, - accept_future: None, - remote_addr: None, - } - } -} - -impl TlsOrTcpConnection { - pub const fn remote_addr(&self) -> std::net::SocketAddr { - match self { - Self::Plain(_, remote_addr) | Self::Tls(_, remote_addr) => *remote_addr, - } - } -} - -impl tokio::io::AsyncRead for TlsOrTcpConnection { - fn poll_read( - self: std::pin::Pin<&mut Self>, - cx: &mut std::task::Context<'_>, - buf: &mut tokio::io::ReadBuf<'_>, - ) -> Poll> { - match self.get_mut() { - Self::Plain(tcp, _) => std::pin::Pin::new(tcp).poll_read(cx, buf), - Self::Tls(tls, _) => std::pin::Pin::new(tls).poll_read(cx, buf), - } - } -} - -impl tokio::io::AsyncWrite for TlsOrTcpConnection { - fn poll_write( - self: std::pin::Pin<&mut Self>, - cx: &mut std::task::Context<'_>, - buf: &[u8], - ) -> Poll> { - match self.get_mut() { - Self::Plain(tcp, _) => std::pin::Pin::new(tcp).poll_write(cx, buf), - Self::Tls(tls, _) => std::pin::Pin::new(tls).poll_write(cx, buf), - } - } - - fn poll_flush( - self: std::pin::Pin<&mut Self>, - cx: &mut std::task::Context<'_>, - ) -> Poll> { - match self.get_mut() { - Self::Plain(tcp, _) => std::pin::Pin::new(tcp).poll_flush(cx), - Self::Tls(tls, _) => std::pin::Pin::new(tls).poll_flush(cx), - } - } - - fn poll_shutdown( - self: std::pin::Pin<&mut Self>, - cx: &mut std::task::Context<'_>, - ) -> Poll> { - match self.get_mut() { - Self::Plain(tcp, _) => std::pin::Pin::new(tcp).poll_shutdown(cx), - Self::Tls(tls, _) => std::pin::Pin::new(tls).poll_shutdown(cx), - } - } -} - -impl hyper::server::accept::Accept for &mut HyperTlsOrTcpAcceptor { - type Conn = TlsOrTcpConnection; - type Error = anyhow::Error; - - fn poll_accept( - mut self: std::pin::Pin<&mut Self>, - cx: &mut std::task::Context<'_>, - ) -> Poll>> { - if self.accept_future.is_none() { - match self.listener.poll_accept(cx) { - Poll::Ready(stream) => match stream { - Ok(stream) => { - if let Some(acceptor) = &self.acceptor { - self.accept_future = Some(acceptor.accept(stream.0)); - self.remote_addr = Some(stream.1); - } else { - return Poll::Ready(Some(Ok(TlsOrTcpConnection::Plain( - stream.0, stream.1, - )))); - } - } - Err(err) => { - return Poll::Ready(Some(Err(err).context("Couldn't make TCP connection"))); - } - }, - Poll::Pending => return Poll::Pending, - } - } - if let Some(accept_future) = &mut self.accept_future { - match accept_future.poll_unpin(cx) { - Poll::Pending => return Poll::Pending, - Poll::Ready(tls) => { - self.accept_future = None; - let tls = match tls { - Ok(tls) => tls, - Err(err) => { - return Poll::Ready(Some( - Err(err).context("Couldn't encrypt TCP connection"), - )); - } - }; - let remote_addr = self.remote_addr.take().unwrap_or_else(|| { - std::net::SocketAddr::from((std::net::Ipv4Addr::UNSPECIFIED, 0)) - }); - return Poll::Ready(Some(Ok(TlsOrTcpConnection::Tls( - Box::new(tls), - remote_addr, - )))); - } - } - } - Poll::Pending - } -}