feat: pending implement quic qinn

This commit is contained in:
2022-08-25 01:40:58 +08:00
parent 87ff030ff0
commit bec4467b54
5 changed files with 319 additions and 848 deletions

View File

@@ -1,7 +1,6 @@
use std::fs;
use rust_util::XResult;
use s2n_quic::Server;
use crate::config::ListenConfig;
use crate::io_util;
@@ -14,31 +13,31 @@ pub async fn run(listen_config: &ListenConfig) -> XResult<()> {
let key_pem = opt_result!(fs::read_to_string(&key_pem_file),
"Read key pem file :{}, failed: {}", &key_pem_file);
let mut server = Server::builder()
.with_tls((cert_pem.as_str(), key_pem.as_str()))?
.with_io(listen_config.listen.as_str())?
.start()?;
// let mut server = Server::builder()
// .with_tls((cert_pem.as_str(), key_pem.as_str()))?
// .with_io(listen_config.listen.as_str())?
// .start()?;
information!("Listen: {}", &listen_config.listen);
while let Some(mut connection) = server.accept().await {
// spawn a new task for the connection
let proxy_address = listen_config.proxy_address.clone();
tokio::spawn(async move {
information!("Connection accepted from {:?}", connection.remote_addr());
while let Ok(Some(stream)) = connection.accept_bidirectional_stream().await {
// spawn a new task for the stream
let connection_id = connection.id();
let proxy_address = proxy_address.clone();
tokio::spawn(async move {
information!("Stream opened from {:?}", stream.connection().remote_addr());
let conn_count = format!("{}-{}-{}", rust_util::util_time::get_current_millis(), connection_id, stream.id());
if let Err(e) = io_util::transfer_for_server_to_remote(stream, proxy_address, conn_count).await {
failure!("Server - Client error: {}", e);
}
});
}
println!("Connection closed from {:?}", connection.remote_addr());
});
}
// while let Some(mut connection) = server.accept().await {
// // spawn a new task for the connection
// let proxy_address = listen_config.proxy_address.clone();
// tokio::spawn(async move {
// information!("Connection accepted from {:?}", connection.remote_addr());
// while let Ok(Some(stream)) = connection.accept_bidirectional_stream().await {
// // spawn a new task for the stream
// let connection_id = connection.id();
// let proxy_address = proxy_address.clone();
// tokio::spawn(async move {
// information!("Stream opened from {:?}", stream.connection().remote_addr());
// let conn_count = format!("{}-{}-{}", rust_util::util_time::get_current_millis(), connection_id, stream.id());
// if let Err(e) = io_util::transfer_for_server_to_remote(stream, proxy_address, conn_count).await {
// failure!("Server - Client error: {}", e);
// }
// });
// }
// println!("Connection closed from {:?}", connection.remote_addr());
// });
// }
Ok(())
}