diff --git a/Cargo.lock b/Cargo.lock index a44980d..44b8a28 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -170,6 +170,17 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +[[package]] +name = "backon" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4fa97bb310c33c811334143cf64c5bb2b7b3c06e453db6b095d7061eff8f113" +dependencies = [ + "fastrand", + "gloo-timers", + "tokio", +] + [[package]] name = "backtrace" version = "0.3.73" @@ -484,6 +495,12 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "fastrand" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8c02a5121d4ea3eb16a80748c74f5549a5665e4c21333c6098f283870fbdea6" + [[package]] name = "filetime" version = "0.2.25" @@ -595,6 +612,18 @@ version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" +[[package]] +name = "gloo-timers" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbb143cf96099802033e0d4f4963b19fd2e0b728bcf076cd9cf7f6634f092994" +dependencies = [ + "futures-channel", + "futures-core", + "js-sys", + "wasm-bindgen", +] + [[package]] name = "h2" version = "0.3.26" @@ -1455,13 +1484,15 @@ dependencies = [ [[package]] name = "rstun" -version = "0.5.1" -source = "git+https://github.com/neevek/rstun#6d2057ebdf929de6d58a4dfb1603e2e18c7ea3e0" +version = "0.6.0" +source = "git+https://github.com/neevek/rstun?branch=dev#3c774b92169b07a6a8bd612f03eb9d7a338991ae" dependencies = [ "android_logger", "anyhow", + "backon", "bincode", "byte-pool", + "bytes", "chrono", "clap", "enum-as-inner", diff --git a/Cargo.toml b/Cargo.toml index eeeb48f..f898111 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,7 @@ lazy_static = "1.4" async-trait = "0.1" byte-pool = { git = "https://github.com/neevek/byte-pool" } # rstun = { path = "../rstun" } -rstun = { git = "https://github.com/neevek/rstun" } +rstun = { git = "https://github.com/neevek/rstun", branch = "dev" } hyper = { version = "0.14", features = ["full"]} http = "0.2" http-body = "0.4" diff --git a/src/quic/quic_client.rs b/src/quic/quic_client.rs index e342004..71b85db 100644 --- a/src/quic/quic_client.rs +++ b/src/quic/quic_client.rs @@ -1,4 +1,5 @@ use anyhow::Result; +use rstun::Upstream; use std::{net::SocketAddr, sync::Arc}; use tokio::task::JoinHandle; @@ -23,7 +24,7 @@ impl QuicClient { } pub async fn start_tcp_server(&mut self) -> Result<()> { - self.tcp_server_addr = Some(self.client.start_tcp_server().await?); + self.tcp_server_addr = self.client.start_tcp_server().await?; Ok(()) } @@ -67,7 +68,8 @@ impl QuicClient { config.local_tcp_server_addr = Some(quic_client_config.local_tcp_server_addr); config.login_msg = Some(rstun::TunnelMessage::ReqOutLogin(rstun::LoginInfo { password: quic_client_config.common_cfg.password.clone(), - tcp_server_addr: None, + tcp_upstream: Upstream::PeerDefault, + udp_upstream: Upstream::NotSpecified, })) } } diff --git a/src/quic/quic_server.rs b/src/quic/quic_server.rs index c64c229..0a457ce 100644 --- a/src/quic/quic_server.rs +++ b/src/quic/quic_server.rs @@ -10,15 +10,20 @@ pub struct QuicServer { impl QuicServer { pub fn new(quic_server_config: QuicServerConfig) -> Self { - let mut config = rstun::ServerConfig::default(); - config.addr = quic_server_config.server_addr.to_string(); - config.password = quic_server_config.common_cfg.password.to_string(); - config.cert_path = quic_server_config.common_cfg.cert.to_string(); - config.key_path = quic_server_config.common_cfg.key.to_string(); - config.max_idle_timeout_ms = quic_server_config.common_cfg.max_idle_timeout_ms; - config.upstreams = vec![quic_server_config.upstream_addr]; - let server = rstun::Server::new(config); - QuicServer { server } + let config = rstun::ServerConfig { + addr: quic_server_config.server_addr.to_string(), + password: quic_server_config.common_cfg.password.to_string(), + cert_path: quic_server_config.common_cfg.cert.to_string(), + key_path: quic_server_config.common_cfg.key.to_string(), + max_idle_timeout_ms: quic_server_config.common_cfg.max_idle_timeout_ms, + tcp_upstreams: vec![quic_server_config.upstream_addr], + udp_upstreams: vec![], + dashboard_server: "".to_string(), + dashboard_server_credential: "".to_string(), + }; + QuicServer { + server: rstun::Server::new(config), + } } pub fn bind(&mut self) -> Result {