rustfmt, fixed ip hash issue
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use crate::backend::Backend;
|
||||
use std::net::SocketAddr;
|
||||
use std::sync::Arc;
|
||||
use std::time::Instant;
|
||||
use crate::backend::Backend;
|
||||
|
||||
pub mod tcp;
|
||||
|
||||
@@ -32,7 +32,8 @@ impl Drop for ConnectionContext {
|
||||
self.backend.dec_connections();
|
||||
let duration = self.start_time.elapsed();
|
||||
|
||||
println!("info: conn_id={} closed. client={} backend={} bytes={} duration={:.2?}",
|
||||
println!(
|
||||
"info: conn_id={} closed. client={} backend={} bytes={} duration={:.2?}",
|
||||
self.id,
|
||||
self.client_addr,
|
||||
self.backend.address,
|
||||
|
||||
@@ -1,24 +1,28 @@
|
||||
use crate::backend::Backend;
|
||||
use crate::proxy::ConnectionContext;
|
||||
use anywho::Error;
|
||||
use std::sync::Arc;
|
||||
use tokio::io;
|
||||
use tokio::net::TcpStream;
|
||||
use anywho::Error;
|
||||
use crate::backend::Backend;
|
||||
use crate::proxy::ConnectionContext;
|
||||
|
||||
pub async fn proxy_tcp_connection(connection_id: u64, mut client_stream: TcpStream, backend: Arc<Backend>) -> Result<(), Error> {
|
||||
pub async fn proxy_tcp_connection(
|
||||
connection_id: u64,
|
||||
mut client_stream: TcpStream,
|
||||
backend: Arc<Backend>,
|
||||
) -> Result<(), Error> {
|
||||
let client_addr = client_stream.peer_addr()?;
|
||||
|
||||
let mut ctx = ConnectionContext::new(connection_id, client_addr, backend.clone());
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
println!("info: conn_id={} connecting to {}", connection_id, ctx.backend.id);
|
||||
println!(
|
||||
"info: conn_id={} connecting to {}",
|
||||
connection_id, ctx.backend.id
|
||||
);
|
||||
|
||||
let mut backend_stream = TcpStream::connect(&backend.address).await?;
|
||||
|
||||
let (tx, rx) = io::copy_bidirectional(
|
||||
&mut client_stream,
|
||||
&mut backend_stream,
|
||||
).await?;
|
||||
let (tx, rx) = io::copy_bidirectional(&mut client_stream, &mut backend_stream).await?;
|
||||
|
||||
ctx.bytes_transferred = tx + rx;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user