Closed jmarshall-com closed 7 months ago
MaybeTlsStream
is currently used on the client side when, e.g., using a connect()
feature. The server's accept_async()
accepts a generic async stream, so you can pass any stream there.
If I understand your use case correctly, you don't need to use MaybeTlsStream
. You can handle the TLS/non-TLS case separately (like you currently do) and just pass the stream to accept_async()
. There is no need to use the crate's TLS features if you handle TLS separately.
OK, thanks for the explanation. It sounds like I can initiate the TLS and non-TLS connections separately, and then subsequently use them in the same way, transparently. This is indeed what I need. Cheers.
I'm writing an async WebSockets server that may or may not use TLS, so I'm trying to use
MaybeTlsStream
to handle both cases the same. Looking at the definition of theMaybeTlsStream
enum instream.rs
, theRustls
variant is defined asRustls(tokio_rustls::client::TlsStream<S>)
, i.e. client-side only, which is incompatible with the return value fromtokio_rustls::TlsAcceptor::accept()
, which istokio_rustls::server::TlsStream<S>
. Is this intentional, or shouldMaybeTlsStream::Rustls
hold the more generictokio_rustls::TlsStream
?The relevant part of the code I'm trying to compile is:
The relevant block of compiler output is:
if this is how it's supposed to work, how can I accept an incoming TLS connection and use
MaybeTlsStream
with it? I'm fairly new to Rust, so please tell me if I'm missing something-- all advice welcome. Thanks!