pub async fn server(
    sock: PathBuf,
    port: u16,
    ready: oneshot::Sender<()>,
) -> Result<(), failure::Error> {
    // wait for client to connect to tcp server
    let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), port);
    let mut listener = TcpListener::bind(&addr).await?;
    let mut incoming = listener.incoming();

    ready.send(()).unwrap();

    while let Some(Ok(inbound)) = incoming.next().await {
        let client_addr = inbound.peer_addr()?;
        info!("Client connected to sock-tcp proxy: {:?}", client_addr);
        if addr.ip() != client_addr.ip() {
            failure::bail!("terminating connection, client is not local");
        }

        let sock = sock.clone();
        tokio::spawn(async move {
            if let Err(e) = transfer(inbound, sock).await {
                error!("connection error: {}", e);
            }
        });
    }
    Ok(())
}
/// Proxy data between a local socket and a local TCP server.
///
/// Adapted from https://github.com/tokio-rs/tokio/blob/master/examples/proxy.rs
Proxy data between a local socket and a local TCP server.
Proxy data between a local socket and a local TCP server .
pub async fn server(
    sock: PathBuf,
    port: u16,
    ready: oneshot::Sender<()>,
) -> Result<(), failure::Error> {
    // wait for client to connect to tcp server
    let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), port);
    let mut listener = TcpListener::bind(&addr).await?;
    let mut incoming = listener.incoming();
    ready.send(()).unwrap();
    while let Some(Ok(inbound)) = incoming.next().await {
        let client_addr = inbound.peer_addr()?;
        info!("Client connected to sock-tcp proxy: {:?}", client_addr);
        if addr.ip() != client_addr.ip() {
            failure::bail!("terminating connection, client is not local");
        }
        let sock = sock.clone();
        tokio::spawn(async move {
            if let Err(e) = transfer(inbound, sock).await {
                error!("connection error: {}", e);
            }
        });
    }
    Ok(())
}
pub async fn server ( sock : PathBuf , port : u16 , ready : oneshot :: Sender < ( ) > , ) -> Result < ( ) , failure :: Error > { // wait for client to connect to tcp server let addr = SocketAddr :: new ( IpAddr :: V4 ( Ipv4Addr :: new ( 127 , 0 , 0 , 1 ) ) , port ) ; let mut listener = TcpListener :: bind ( & addr ) . await ? ; let mut incoming = listener . incoming ( ) ; ready . send ( ( ) ) . unwrap ( ) ; while let Some ( Ok ( inbound ) ) = incoming . next ( ) . await { let client_addr = inbound . peer_addr ( ) ? ; info ! ( " " client_addr ) ; if addr . ip ( ) != client_addr . ip ( ) { failure :: bail ! ( " " ) ; } let sock = sock . clone ( ) ; tokio :: spawn ( async move { if let Err ( e ) = transfer ( inbound , sock ) . await { error ! ( " " e ) ; } } ) ; } Ok ( ( ) ) }
Proxy data between a local socket and a local TCP server.
Proxy data between a local socket and a local TCP server .
sock
PathBuf
port
u16
ready
oneshot::Sender<()>
sock
PathBuf
port
u16
ready
oneshot::Sender<()>