feat: update client

This commit is contained in:
2022-08-22 00:19:37 +08:00
parent 983a742c5b
commit 391f6f3fb6

View File

@@ -32,12 +32,13 @@ pub async fn run(listen_config: &ListenConfig) -> XResult<()> {
} }
}); });
information!("Start connect to server"); information!("Start connect to server, proxy address: {}, with server name: {:?}",
listen_config.proxy_address, listen_config.proxy_server_name);
let cert_pem = opt_result!(fs::read_to_string(&listen_config.cert_pem_file), let cert_pem = opt_result!(fs::read_to_string(&listen_config.cert_pem_file),
"Read cert pem file: {}, failed: {}", &listen_config.cert_pem_file); "Read cert pem file: {}, failed: {}", &listen_config.cert_pem_file);
let client = Client::builder() let client = Client::builder()
.with_tls(cert_pem.as_str())? .with_tls(cert_pem.as_str())?
.with_io(listen_config.listen.as_str())? .with_io("0.0.0.0:0")?
.start()?; .start()?;
let addr: SocketAddr = listen_config.proxy_address.parse()?; let addr: SocketAddr = listen_config.proxy_address.parse()?;
let server_name = opt_value_result!(&listen_config.proxy_server_name, let server_name = opt_value_result!(&listen_config.proxy_server_name,
@@ -72,6 +73,7 @@ pub async fn run(listen_config: &ListenConfig) -> XResult<()> {
} }
}; };
information!("Get connection: {} - {}", client_stream_time, client_stream.peer_addr().unwrap());
let time = util_time::get_current_millis(); let time = util_time::get_current_millis();
if (time as i128 - client_stream_time as i128).abs() > 3_000 { if (time as i128 - client_stream_time as i128).abs() > 3_000 {
warning!("Connection is more than 3 second, abandon connection"); warning!("Connection is more than 3 second, abandon connection");
@@ -81,7 +83,7 @@ pub async fn run(listen_config: &ListenConfig) -> XResult<()> {
let server_stream = match connection.open_bidirectional_stream().await { let server_stream = match connection.open_bidirectional_stream().await {
Ok(stream) => stream, Ok(stream) => stream,
Err(e) => { Err(e) => {
failure!("Connect to server failed: {}", e); failure!("Open stream in connection to server failed: {}", e);
continue 're_connect; continue 're_connect;
} }
}; };