Skip to content

Commit

Permalink
feat(viz): implement Accept for tls
Browse files Browse the repository at this point in the history
  • Loading branch information
fundon committed Dec 30, 2023
1 parent 00d9c00 commit fe0135f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
19 changes: 15 additions & 4 deletions viz/src/tls/native_tls.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
use std::{fmt, net::SocketAddr};
use std::{
fmt,
io::{Error as IoError, ErrorKind},
net::SocketAddr,
};

use tokio::net::{TcpListener, TcpStream};
use tokio_native_tls::{native_tls::TlsAcceptor as TlsAcceptorWrapper, TlsStream};
Expand Down Expand Up @@ -38,15 +42,22 @@ impl Config {
}
}

impl Listener<TcpListener, TlsAcceptor> {
impl crate::Accept for Listener<TcpListener, TlsAcceptor> {
type Conn = TlsStream<TcpStream>;
type Addr = SocketAddr;

/// A [`TlsStream`] and [`SocketAddr`] part for accepting TLS.
///
/// # Errors
///
/// Will return `Err` if accepting the stream fails.
pub async fn accept(&self) -> Result<(TlsStream<TcpStream>, SocketAddr)> {
async fn accept(&self) -> std::io::Result<(Self::Conn, Self::Addr)> {

Check warning on line 54 in viz/src/tls/native_tls.rs

View check run for this annotation

Codecov / codecov/patch

viz/src/tls/native_tls.rs#L54

Added line #L54 was not covered by tests
let (stream, addr) = self.inner.accept().await?;
let tls_stream = self.acceptor.accept(stream).await.map_err(Error::boxed)?;
let tls_stream = self
.acceptor
.accept(stream)
.await
.map_err(|e| IoError::new(ErrorKind::Other, e))?;

Check warning on line 60 in viz/src/tls/native_tls.rs

View check run for this annotation

Codecov / codecov/patch

viz/src/tls/native_tls.rs#L56-L60

Added lines #L56 - L60 were not covered by tests
Ok((tls_stream, addr))
}
}
13 changes: 7 additions & 6 deletions viz/src/tls/rustls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,16 @@ impl Config {
}
}

impl Listener<TcpListener, TlsAcceptor> {
/// Accepts a new incoming connection from this listener.
///
/// Returns a [`TlsStream`] and [`SocketAddr`] part.
impl crate::Accept for Listener<TcpListener, TlsAcceptor> {
type Conn = TlsStream<TcpStream>;
type Addr = SocketAddr;

/// A [`TlsStream`] and [`SocketAddr`] part for accepting TLS.
///
/// # Errors
///
/// This function throws if it is not accepted from the listener.
pub async fn accept(&self) -> Result<(TlsStream<TcpStream>, SocketAddr)> {
/// Will return `Err` if accepting the stream fails.
async fn accept(&self) -> std::io::Result<(Self::Conn, Self::Addr)> {

Check warning on line 161 in viz/src/tls/rustls.rs

View check run for this annotation

Codecov / codecov/patch

viz/src/tls/rustls.rs#L161

Added line #L161 was not covered by tests
let (stream, addr) = self.inner.accept().await?;
let tls_stream = self.acceptor.accept(stream).await?;
Ok((tls_stream, addr))
Expand Down

0 comments on commit fe0135f

Please sign in to comment.