// Create a TCP connection to host:port, build a tunnel between the connection and
// the upgraded connection
Create a TCP connection to host:port, build a tunnel between the connection and
the upgraded connection
Create a TCP connection to host : port build a tunnel between the connection and the upgraded connection
async fn tunnel(mut upgraded: Upgraded, addr: String) -> std::io::Result<()> {
  // Connect to remote server
  let mut server = TcpStream::connect(addr).await?;
  // Proxying data
  match tokio::io::copy_bidirectional(&mut upgraded, &mut server).await {
    Ok((from_client, from_server)) => {
      // Print message when done
      println!(
        "client wrote {} bytes and received {} bytes",
        from_client, from_server
      );
      EGRESS_BYTES.inc_by(from_client);
      INGRESS_BYTES.inc_by(from_server);
    }
    Err(e) => {
      // not connected error are harmless, so we're simply ignoring them here,
      // returning any other kind of errors.
      if e.kind() != ErrorKind::NotConnected {
        return Err(e);
      }
    }
  }
  Ok(())
}
async fn tunnel ( mut upgraded : Upgraded , addr : String ) -> std :: io :: Result < ( ) > { // Connect to remote server let mut server = TcpStream :: connect ( addr ) . await ? ; // Proxying data match tokio :: io :: copy_bidirectional ( & mut upgraded , & mut server ) . await { Ok ( ( from_client , from_server ) ) => { // Print message when done println ! ( " " from_client from_server ) ; EGRESS_BYTES . inc_by ( from_client ) ; INGRESS_BYTES . inc_by ( from_server ) ; } Err ( e ) => { // not connected error are harmless, so we're simply ignoring them here, // returning any other kind of errors. if e . kind ( ) != ErrorKind :: NotConnected { return Err ( e ) ; } } } Ok ( ( ) ) }
Create a TCP connection to host:port, build a tunnel between the connection and
the upgraded connection
Create a TCP connection to host : port build a tunnel between the connection and the upgraded connection
upgraded
Upgraded
addr
String