3 Commits
v0.3.0 ... main

Author SHA1 Message Date
8706733610 chore: update log and comment 2022-08-27 00:35:37 +08:00
47d2937c45 feat: update client&server 2022-08-27 00:33:22 +08:00
9fbc498615 feat: v0.3.1, fix panic 2022-08-26 00:33:40 +08:00
5 changed files with 32 additions and 18 deletions

2
Cargo.lock generated
View File

@@ -718,7 +718,7 @@ dependencies = [
[[package]]
name = "simple-rust-http3-proxy"
version = "0.3.0"
version = "0.3.1"
dependencies = [
"clap",
"deser-hjson",

View File

@@ -1,6 +1,6 @@
[package]
name = "simple-rust-http3-proxy"
version = "0.3.0"
version = "0.3.1"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

View File

@@ -21,9 +21,7 @@ pub async fn run(listen_config: &ListenConfig) -> XResult<()> {
tokio::spawn(async move {
while let Ok((inbound, _)) = listener.accept().await {
information!("Receive connection: {}", inbound.peer_addr().map(|addr| format!("{}", addr)).unwrap_or_else(|_| "n/a".to_string()));
// if is_in_peer_addr_matches(&inbound, &allow_ips, sender_tx.clone()) {
// } else {
// }
// TODO if is_in_peer_addr_matches(&inbound, &allow_ips) {
if let Err(e) = inbound_stream_channel_sender.send((util_time::get_current_millis(), inbound)).await {
failure!("Send tcp stream to channel failed: {}", e);
}
@@ -69,9 +67,30 @@ pub async fn run(listen_config: &ListenConfig) -> XResult<()> {
let endpoint = endpoint_opt.as_mut().unwrap();
let connect = endpoint.connect(addr, &server_name).unwrap();
let quinn::NewConnection { connection, .. } = connect.await.unwrap();
let (send, recv) = connection.open_bi().await.unwrap();
let connect = match endpoint.connect(addr, &server_name) {
Ok(connect) => connect,
Err(e) => {
failure!("Connect failed: {:?}", e);
endpoint_opt = None;
continue;
}
};
let quinn::NewConnection { connection, .. } = match connect.await {
Ok(connection) => connection,
Err(e) => {
failure!("Connect failed: {:?}", e);
endpoint_opt = None;
continue;
}
};
let (send, recv) = match connection.open_bi().await {
Ok(stream) => stream,
Err(e) => {
failure!("Connect failed: {:?}", e);
endpoint_opt = None;
continue;
}
};
let remote_addr = format!("{}", connection.remote_address());
let local_addr = connection.local_ip().map(|ip| format!("{}", ip)).unwrap_or_else(|| "".to_string());
tokio::spawn(async move {
@@ -85,10 +104,7 @@ pub async fn run(listen_config: &ListenConfig) -> XResult<()> {
}
}
fn make_client_endpoint(
bind_addr: SocketAddr,
server_certs: &[&[u8]],
) -> Result<Endpoint, Box<dyn Error>> {
fn make_client_endpoint(bind_addr: SocketAddr, server_certs: &[&[u8]]) -> Result<Endpoint, Box<dyn Error>> {
let client_cfg = configure_client(server_certs)?;
let mut endpoint = Endpoint::client(bind_addr)?;
endpoint.set_default_client_config(client_cfg);
@@ -100,6 +116,5 @@ fn configure_client(server_certs: &[&[u8]]) -> Result<ClientConfig, Box<dyn Erro
for cert in server_certs {
certs.add(&rustls::Certificate(cert.to_vec()))?;
}
Ok(ClientConfig::with_root_certificates(certs))
}

View File

@@ -37,7 +37,7 @@ async fn main() -> XResult<()> {
failure_and_exit!("Cannot run in both server and client mode");
}
if !server_mode && !client_mode {
failure_and_exit!("Must run in server on client mode")
failure_and_exit!("Must run in server or client mode")
}
let config_file = opt_value_result!(matches.value_of("config"), "--config is required");

View File

@@ -26,8 +26,7 @@ pub async fn run(listen_config: &ListenConfig) -> XResult<()> {
let cert_chain = vec![rustls::Certificate(cert_bytes)];
let mut server_config = opt_result!(ServerConfig::with_single_cert(cert_chain, priv_key), "Create server config failed: {}");
Arc::get_mut(&mut server_config.transport)
.unwrap()
Arc::get_mut(&mut server_config.transport).unwrap()
.max_concurrent_uni_streams(0_u8.into());
information!("Listen: {}", &listen_config.listen);
let listen_addr: SocketAddr = opt_result!(listen_config.listen.parse(), "Parse listen address: {} failed: {}", &listen_config.listen);
@@ -45,7 +44,7 @@ pub async fn run(listen_config: &ListenConfig) -> XResult<()> {
let connection = match connection.await {
Ok(connection) => connection,
Err(e) => {
warning!("Create connection failed: {}", e);
warning!("Create connection failed: {:?}", e);
sleep(Duration::from_secs(3)).await;
continue;
}
@@ -67,7 +66,7 @@ pub async fn run(listen_config: &ListenConfig) -> XResult<()> {
break;
}
Some(Err(e)) => {
information!("Connection ended: {}", e);
information!("Connection ended: {:?}", e);
break;
}
Some(Ok((send, recv))) => {