Skip to content

Commit

Permalink
upgrade rstun to 0.5.1
Browse files Browse the repository at this point in the history
  • Loading branch information
neevek committed Sep 15, 2024
1 parent b355bac commit 8339a1c
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 22 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "omnip"
version = "0.5.0"
version = "0.5.1"
edition = "2021"

[lib]
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ pub struct QuicServerConfig {
#[derive(Debug, Clone)]
pub struct QuicClientConfig {
pub server_addr: NetAddr,
pub local_access_server_addr: SocketAddr,
pub local_tcp_server_addr: SocketAddr,
pub common_cfg: CommonQuicConfig,
}

Expand Down
17 changes: 8 additions & 9 deletions src/quic/quic_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::QuicClientConfig;
pub struct QuicClient {
client: Arc<rstun::Client>,
server_addr: String,
access_server_addr: Option<SocketAddr>,
tcp_server_addr: Option<SocketAddr>,
}

impl QuicClient {
Expand All @@ -18,12 +18,12 @@ impl QuicClient {
QuicClient {
client: rstun::Client::new(config.clone()),
server_addr,
access_server_addr: None,
tcp_server_addr: None,
}
}

pub async fn start_access_server(&mut self) -> Result<()> {
self.access_server_addr = Some(self.client.start_access_server().await?);
pub async fn start_tcp_server(&mut self) -> Result<()> {
self.tcp_server_addr = Some(self.client.start_tcp_server().await?);
Ok(())
}

Expand All @@ -47,8 +47,8 @@ impl QuicClient {
self.server_addr.clone()
}

pub fn access_server_addr(&self) -> Option<SocketAddr> {
self.access_server_addr
pub fn tcp_server_addr(&self) -> Option<SocketAddr> {
self.tcp_server_addr
}

pub fn get_state(&self) -> rstun::ClientState {
Expand All @@ -60,15 +60,14 @@ impl QuicClient {
config.cert_path = quic_client_config.common_cfg.cert.clone();
config.cipher = quic_client_config.common_cfg.cipher.clone();
config.max_idle_timeout_ms = quic_client_config.common_cfg.max_idle_timeout_ms;
config.keep_alive_interval_ms = quic_client_config.common_cfg.max_idle_timeout_ms / 2;
config.threads = quic_client_config.common_cfg.threads;
config.wait_before_retry_ms = quic_client_config.common_cfg.retry_interval_ms;
config.connect_max_retry = 0;
config.mode = rstun::TUNNEL_MODE_OUT;
config.local_access_server_addr = Some(quic_client_config.local_access_server_addr);
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(),
access_server_addr: None,
tcp_server_addr: None,
}))
}
}
13 changes: 5 additions & 8 deletions src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ impl Server {
// with +quic protocols, quic_client will be used to connect to the upstream
let quic_client_config = QuicClientConfig {
server_addr: quic_server_addr,
local_access_server_addr: local_socket_addr_with_unspecified_port(
local_tcp_server_addr: local_socket_addr_with_unspecified_port(
self.config.addr.is_ipv6(),
),
common_cfg: common_quic_config,
Expand All @@ -267,18 +267,15 @@ impl Server {
info_bridge.post_server_log(data);
});
}
client.start_access_server().await?;
client.start_tcp_server().await?;

let access_server_addr = client.access_server_addr();
info!(
"QUIC tunnel access server address: {:?}",
access_server_addr
);
let tcp_server_addr = client.tcp_server_addr();
info!("QUIC tunnel access server address: {:?}", tcp_server_addr);

// will handover the handle to the caller, so we don't block here
let join_handle = client.connect_and_serve_async();

inner_state!(self, upstream) = access_server_addr;
inner_state!(self, upstream) = tcp_server_addr;
inner_state!(self, quic_client) = Some(Arc::new(client));

Ok(join_handle)
Expand Down

0 comments on commit 8339a1c

Please sign in to comment.