feat: pending test
This commit is contained in:
@@ -2,7 +2,7 @@ use std::fs;
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use rust_util::{util_time, XResult};
|
||||
use s2n_quic::Client;
|
||||
use s2n_quic::{Client, Connection};
|
||||
use s2n_quic::client::Connect;
|
||||
use tokio::net::TcpListener;
|
||||
use tokio::sync::mpsc::channel;
|
||||
@@ -42,6 +42,7 @@ pub async fn run(listen_config: &ListenConfig) -> XResult<()> {
|
||||
let server_name = opt_value_result!(&listen_config.proxy_server_name,
|
||||
"proxy_server_name in config is require in client mode");
|
||||
|
||||
let mut connection_opt: Option<Connection> = None;
|
||||
loop {
|
||||
let (client_stream_time, client_stream) = match inbound_stream_channel_receiver.recv().await {
|
||||
Some(time_and_stream) => time_and_stream,
|
||||
@@ -51,34 +52,37 @@ pub async fn run(listen_config: &ListenConfig) -> XResult<()> {
|
||||
}
|
||||
};
|
||||
information!("Get connection: {} - {}", client_stream_time, client_stream.peer_addr().unwrap());
|
||||
let addr = addr.clone();
|
||||
let client = client.clone();
|
||||
let server_name = server_name.clone();
|
||||
tokio::spawn(async move {
|
||||
let time = util_time::get_current_millis();
|
||||
if (time as i128 - client_stream_time as i128).abs() > 3_000 {
|
||||
warning!("Connection is more than 3 second, abandon connection");
|
||||
continue;
|
||||
}
|
||||
|
||||
if let None = connection_opt {
|
||||
let connect = Connect::new(addr).with_server_name(server_name.as_str());
|
||||
let mut connection = match client.connect(connect).await {
|
||||
Ok(connection) => connection,
|
||||
Err(e) => {
|
||||
failure!("Connect to server failed: {}", e);
|
||||
return;
|
||||
continue;
|
||||
}
|
||||
};
|
||||
connection.keep_alive(true).ok();
|
||||
connection_opt = Some(connection);
|
||||
}
|
||||
|
||||
let time = util_time::get_current_millis();
|
||||
if (time as i128 - client_stream_time as i128).abs() > 3_000 {
|
||||
warning!("Connection is more than 3 second, abandon connection");
|
||||
return;
|
||||
let connection = connection_opt.as_mut().unwrap();
|
||||
let server_stream = match connection.open_bidirectional_stream().await {
|
||||
Ok(stream) => stream,
|
||||
Err(e) => {
|
||||
failure!("Open stream in connection to server failed: {}", e);
|
||||
connection_opt = None;
|
||||
continue;
|
||||
}
|
||||
|
||||
let server_stream = match connection.open_bidirectional_stream().await {
|
||||
Ok(stream) => stream,
|
||||
Err(e) => {
|
||||
failure!("Open stream in connection to server failed: {}", e);
|
||||
return;
|
||||
}
|
||||
};
|
||||
let conn_count = format!("{}", util_time::get_current_millis());
|
||||
};
|
||||
let connection_id = connection.id();
|
||||
tokio::spawn(async move {
|
||||
let conn_count = format!("{}-{}-{}", util_time::get_current_millis(), connection_id, server_stream.id());
|
||||
if let Err(e) = io_util::transfer_for_client_to_server(client_stream, server_stream, conn_count).await {
|
||||
failure!("Client - Server error: {}", e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user