Skip to content

Commit

Permalink
test_timeout_secs option
Browse files Browse the repository at this point in the history
  • Loading branch information
ssrlive committed May 9, 2024
1 parent 2d59032 commit 4269b69
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"remarks": "nickname of this config",
"test_timeout_secs": 10,
"method": "none",
"password": "password",
"tunnel_path": "/secret-tunnel-path/",
Expand Down
1 change: 1 addition & 0 deletions install/overtls-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,7 @@ function write_overtls_config_file() {
{
"remarks": "${hostname}-${identity}",
"tunnel_path": "/${reverse_proxy_location}/",
"test_timeout_secs": 5,
"server_settings": {
"forward_addr": "http://127.0.0.1:80",
Expand Down
13 changes: 6 additions & 7 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ use std::{
path::PathBuf,
};

pub(crate) const TEST_TIMEOUT_SECS: u64 = 10;

#[derive(Clone, Serialize, Deserialize, Debug)]
pub struct Config {
#[serde(
Expand All @@ -24,8 +26,8 @@ pub struct Config {
#[serde(skip_serializing_if = "Option::is_none")]
pub password: Option<String>,
pub tunnel_path: TunnelPath,
#[serde(skip)]
pub test_timeout_secs: u64,
#[serde(skip_serializing_if = "Option::is_none")]
pub test_timeout_secs: Option<u64>,
#[serde(skip)]
pub is_server: bool,
}
Expand Down Expand Up @@ -188,7 +190,7 @@ impl Config {
tunnel_path: TunnelPath::default(),
server: None,
client: None,
test_timeout_secs: 5,
test_timeout_secs: Some(TEST_TIMEOUT_SECS),
is_server: false,
}
}
Expand Down Expand Up @@ -296,9 +298,6 @@ impl Config {
return Err("Need server or client settings".into());
}

if self.test_timeout_secs == 0 {
self.test_timeout_secs = 5;
}
if self.tunnel_path.is_empty() {
self.tunnel_path = TunnelPath::default();
} else {
Expand Down Expand Up @@ -338,7 +337,7 @@ impl Config {
let mut addr = (server_host, client.server_port).to_socket_addrs()?;
let addr = addr.next().ok_or("address not available")?;
{
let timeout = std::time::Duration::from_secs(self.test_timeout_secs);
let timeout = std::time::Duration::from_secs(self.test_timeout_secs.unwrap_or(TEST_TIMEOUT_SECS));
crate::tcp_stream::std_create(addr, Some(timeout))?;
}
if client.listen_host.is_empty() {
Expand Down
5 changes: 3 additions & 2 deletions src/server.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
b64str_to_address,
config::Config,
config::{Config, TEST_TIMEOUT_SECS},
error::{Error, Result},
tls::*,
traffic_audit::{TrafficAudit, TrafficAuditPtr},
Expand Down Expand Up @@ -290,10 +290,11 @@ async fn websocket_traffic_handler<S: AsyncRead + AsyncWrite + Unpin>(
} else {
let addr_str = b64str_to_address(&target_address, false)?.to_string();

let time_out = std::time::Duration::from_secs(config.test_timeout_secs.unwrap_or(TEST_TIMEOUT_SECS));
// try to connect to the first available address
let mut successful_addr = None;
for dst_addr in addr_str.to_socket_addrs()? {
match std::net::TcpStream::connect(dst_addr) {
match crate::tcp_stream::std_create(dst_addr, Some(time_out)) {
Ok(_) => {
successful_addr = Some(dst_addr);
break;
Expand Down

0 comments on commit 4269b69

Please sign in to comment.