Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions crates/tuic-client/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,8 @@ fn default_udp_timeout() -> Duration {

impl Config {
pub fn parse(cli: Cli, env_state: EnvState) -> eyre::Result<Self> {
// Require config file
let path = cli.config.ok_or(ConfigError::NoConfig)?;

// Check if config file exists
if !path.exists() {
return Err(ConfigError::ConfigNotFound(path))?;
}
Expand All @@ -254,7 +252,6 @@ impl Config {
_ => format = ConfigFormat::Unknown,
}
} else {
// Fall back to file extension
match path
.extension()
.and_then(|v| v.to_str())
Expand All @@ -274,7 +271,6 @@ impl Config {
ConfigFormat::Toml => figmet.merge(Toml::file(&path)),
ConfigFormat::Yaml => figmet.merge(Yaml::file(&path)),
ConfigFormat::Unknown => {
// Try to infer format from file content
let content = std::fs::read_to_string(&path)?;
let inferred_format = infer_config_format(&content);

Expand Down Expand Up @@ -306,7 +302,6 @@ enum ConfigFormat {
fn infer_config_format(content: &str) -> ConfigFormat {
let trimmed = content.trim();

// Check for YAML indicators
if trimmed.lines().any(|line| {
let line = line.trim();
// YAML typically has keys followed by colons (not in quotes)
Expand All @@ -322,15 +317,13 @@ fn infer_config_format(content: &str) -> ConfigFormat {
return ConfigFormat::Yaml;
}

// Check for TOML indicators (section headers)
if trimmed.lines().any(|line| {
let line = line.trim();
line.starts_with('[') && line.ends_with(']') && !line.contains('{')
}) {
return ConfigFormat::Toml;
}

// Check for JSON/JSON5 indicators
if trimmed.starts_with('{') || trimmed.starts_with('[') {
return ConfigFormat::Json;
}
Expand Down Expand Up @@ -454,22 +447,18 @@ mod tests {

fs::write(&config_path, config_content).unwrap();

// Temporarily set command line arguments for clap to parse
let os_args = vec![
"test_binary".to_owned(),
"--config".to_owned(),
config_path.to_string_lossy().into_owned(),
];

// Parse CLI with test arguments
let cli = Cli::try_parse_from(os_args).map_err(|e| ConfigError::Figment(figment::Error::from(e.to_string())))?;

// Call parse with the CLI and env_state
Config::parse(cli, env_state)
}
#[test]
fn test_backward_compatibility_standard_json() {
// Test backward compatibility with standard JSON format
let json_config = include_str!("../tests/config/backward_compatibility_standard_json.json");

let config = test_parse_config(json_config, ".json5");
Expand All @@ -483,7 +472,6 @@ mod tests {

#[test]
fn test_json5_comments() {
// Test JSON5 comment support (single-line and multi-line)
let json5_config = include_str!("../tests/config/json5_comments.json5");

let config = test_parse_config(json5_config, ".json5");
Expand All @@ -492,7 +480,6 @@ mod tests {

#[test]
fn test_json5_trailing_commas() {
// Test JSON5 trailing comma support
let json5_config = include_str!("../tests/config/json5_trailing_commas.json5");

let config = test_parse_config(json5_config, ".json5");
Expand All @@ -501,7 +488,6 @@ mod tests {

#[test]
fn test_json5_unquoted_keys() {
// Test JSON5 unquoted object keys
let json5_config = include_str!("../tests/config/json5_unquoted_keys.json5");

let config = test_parse_config(json5_config, ".json5");
Expand All @@ -510,7 +496,6 @@ mod tests {

#[test]
fn test_json5_single_quotes() {
// Test JSON5 single-quoted strings
let json5_config = include_str!("../tests/config/json5_single_quotes.json5");

let config = test_parse_config(json5_config, ".json5");
Expand All @@ -519,7 +504,6 @@ mod tests {

#[test]
fn test_json5_multiline_strings() {
// Test JSON5 multiline strings with escaped newlines
let json5_config = include_str!("../tests/config/json5_multiline_strings.json5");

let config = test_parse_config(json5_config, ".json5");
Expand All @@ -528,7 +512,6 @@ mod tests {

#[test]
fn test_json5_mixed_features() {
// Test multiple JSON5 features combined
let json5_config = include_str!("../tests/config/json5_mixed_features.json5");

let config = test_parse_config(json5_config, ".json5");
Expand All @@ -540,7 +523,6 @@ mod tests {

#[test]
fn test_complex_config_with_all_fields() {
// Test a more complete configuration with various optional fields
let json5_config = include_str!("../tests/config/complex_config_with_all_fields.json5");

let config = test_parse_config(json5_config, ".json5");
Expand All @@ -557,7 +539,6 @@ mod tests {

let config = test_parse_config(json5_config, ".json5").unwrap();

// Check default values
assert_eq!(config.log_level, "info");
assert_eq!(config.relay.ipstack_prefer, StackPrefer::V4first);
assert_eq!(config.relay.udp_relay_mode, UdpRelayMode::Native);
Expand Down Expand Up @@ -680,10 +661,8 @@ server = "127.0.0.1:1081"
let proxy = config.relay.proxy.unwrap();
assert_eq!(proxy.server.0, "proxy.example.com");
assert_eq!(proxy.server.1, 1080);
// username and password should be None when not provided
assert!(proxy.username.is_none());
assert!(proxy.password.is_none());
// Should use default udp_buffer_size
assert_eq!(proxy.udp_buffer_size, 2048);
}

Expand All @@ -697,7 +676,6 @@ server = "127.0.0.1:1081"
assert_eq!(proxy.server.1, 1080);
assert!(proxy.username.is_none());
assert!(proxy.password.is_none());
// Default udp_buffer_size should be 2048
assert_eq!(proxy.udp_buffer_size, 2048);
}

Expand All @@ -706,7 +684,6 @@ server = "127.0.0.1:1081"
let toml_config = include_str!("../tests/config/no_proxy.toml");

let config = test_parse_config(toml_config, ".toml").unwrap();
// proxy should be None when not configured
assert!(config.relay.proxy.is_none());
}

Expand Down Expand Up @@ -748,7 +725,6 @@ server = "127.0.0.1:1081"

let config = test_parse_config(toml_config, ".toml").unwrap();

// Test default values
assert_eq!(config.log_level, "info");
assert_eq!(config.relay.congestion_control, CongestionControl::Bbr);
assert_eq!(config.relay.udp_relay_mode, UdpRelayMode::Native);
Expand Down Expand Up @@ -874,7 +850,6 @@ server = "127.0.0.1:1081"
fn test_env_var_force_toml() {
let config_content = include_str!("../tests/config/env_var_force_toml.toml");

// Create EnvState with force_toml enabled
let env_state = EnvState {
tuic_force_toml: true,
tuic_config_format: None,
Expand All @@ -889,7 +864,6 @@ server = "127.0.0.1:1081"
fn test_env_var_config_format() {
let config_content = include_str!("../tests/config/env_yaml.toml");

// Create EnvState with config_format set to YAML
let env_state = EnvState {
tuic_force_toml: false,
tuic_config_format: Some("yaml".to_string()),
Expand Down Expand Up @@ -927,12 +901,10 @@ server = "127.0.0.1:1081"

#[test]
fn test_backward_compat_json_to_toml() {
// Test that configs can be converted from JSON5 to TOML
let json5_content = include_str!("../tests/config/compat_json.json5");

let json_config = test_parse_config(json5_content, ".json5").unwrap();

// Verify the config is parsed correctly
assert_eq!(json_config.relay.server.0, "compat.example.com");
assert_eq!(json_config.relay.server.1, 8443);
assert_eq!(json_config.log_level, "warn");
Expand Down
1 change: 0 additions & 1 deletion crates/tuic-client/src/forward.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ async fn run_udp_forwarder(entry: UdpForward, cancel: CancellationToken) {
let pkt = Bytes::copy_from_slice(&buf[..n]);
let target = TargetAddr::Domain(entry.remote.0.clone(), entry.remote.1);

// Look up or create the session for this source.
let session = sessions.entry(src_addr).or_insert_with(|| {
let assoc_id = next_assoc_id();
let socket_for_reply = socket.clone();
Expand Down
2 changes: 0 additions & 2 deletions crates/tuic-client/src/socks5/handle_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ impl Server {
}
};

// Spawn wind outbound UDP handler
let outbound_handle = tokio::spawn(async move {
match get_connection() {
Some(adapter) => {
Expand Down Expand Up @@ -149,7 +148,6 @@ impl Server {
// session is gone either way.
let _ = UDP_SESSIONS.get().unwrap().write().await.remove(&assoc_id);

// Cancel the outbound UDP handler
outbound_handle.abort();
}
Err(err) => {
Expand Down
4 changes: 0 additions & 4 deletions crates/tuic-client/src/socks5/udp_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,6 @@ impl UdpSession {
}
}

// ---------------------------------------------------------------------------
// PR1 regression tests
// ---------------------------------------------------------------------------

#[cfg(test)]
mod tests {
use std::net::{Ipv4Addr, SocketAddr};
Expand Down
1 change: 0 additions & 1 deletion crates/tuic-client/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::{
use anyhow::Context;
use rustls::{RootCertStore, pki_types::CertificateDer};
use tokio::net;
// Re-export common types from wind-core and wind-tuic
pub use wind_core::StackPrefer;
pub use wind_tuic::quinn::{CongestionControl, UdpRelayMode};

Expand Down
7 changes: 0 additions & 7 deletions crates/tuic-client/src/wind_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use wind_tuic::quinn::outbound::{TuicOutbound, TuicOutboundOpts};

use crate::config::Relay;

// Global wind-tuic connection
static WIND_CONNECTION: OnceCell<TuicOutboundAdapter> = OnceCell::new();

/// Wind-tuic outbound wrapper for tuic-client
Expand All @@ -21,19 +20,16 @@ pub struct TuicOutboundAdapter {

impl TuicOutboundAdapter {
pub async fn new(ctx: Arc<AppContext>, relay: Relay) -> eyre::Result<Self> {
// Parse server address
let server_addr = if let Some(ip) = relay.ip {
SocketAddr::new(ip, relay.server.1)
} else {
// Resolve domain
let addrs = tokio::net::lookup_host(format!("{}:{}", relay.server.0, relay.server.1)).await?;
addrs
.into_iter()
.next()
.ok_or_else(|| eyre::eyre!("Failed to resolve server address"))?
};

// Convert password to Arc<[u8]>
let password: Arc<[u8]> = relay.password.clone();

// Pick the SNI to send during TLS handshake.
Expand Down Expand Up @@ -66,7 +62,6 @@ impl TuicOutboundAdapter {
}
};

// Create wind-tuic outbound options
let opts = TuicOutboundOpts {
peer_addr: server_addr,
sni,
Expand All @@ -83,10 +78,8 @@ impl TuicOutboundAdapter {
.collect(),
};

// Create outbound
let outbound: TuicOutbound = TuicOutbound::new(ctx, opts).await?;

// Start polling
outbound.start_poll().await?;

Ok(Self { outbound })
Expand Down
20 changes: 0 additions & 20 deletions crates/tuic-core/src/proto/addr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ use wind_core::types::TargetAddr;

use crate::proto::{BytesRemainingSnafu, DomainTooLongSnafu, ProtoError};

//-----------------------------------------------------------------------------
// Type Definitions
//-----------------------------------------------------------------------------

/// Codec for TUIC address encoding and decoding
#[derive(Debug, Clone, Copy)]
pub struct AddressCodec;
Expand Down Expand Up @@ -40,10 +36,6 @@ pub enum AddressType {
Other(u8),
}

//-----------------------------------------------------------------------------
// Implementations
//-----------------------------------------------------------------------------

impl From<TargetAddr> for Address {
fn from(value: TargetAddr) -> Self {
match value {
Expand All @@ -54,10 +46,6 @@ impl From<TargetAddr> for Address {
}
}

//-----------------------------------------------------------------------------
// Codec Implementation
//-----------------------------------------------------------------------------

/// Implementation according to TUIC specification:
/// https://github.com/proxy-rs/wind/blob/main/crates/wind-tuic/SPEC.md#6-address-encoding
#[cfg(feature = "decode")]
Expand Down Expand Up @@ -111,7 +99,6 @@ impl Encoder<Address> for AddressCodec {
dst.put_u16(port);
}
Address::Domain(domain, port) => {
// Validate domain length
if domain.len() > u8::MAX as usize {
return DomainTooLongSnafu { domain }.fail();
}
Expand All @@ -128,10 +115,6 @@ impl Encoder<Address> for AddressCodec {
}
}

//-----------------------------------------------------------------------------
// Tests
//-----------------------------------------------------------------------------

#[cfg(test)]
mod test {
use std::net::{Ipv4Addr, Ipv6Addr};
Expand All @@ -154,7 +137,6 @@ mod test {
Address::Domain(String::from("www.google.com"), 443),
];

// Test encoding
let mut writer = FramedWrite::new(buffer, AddressCodec);
let mut expect_len = 0;
for var in &vars {
Expand All @@ -168,7 +150,6 @@ mod test {
assert_eq!(writer.get_ref().len(), expect_len);
}

// Test decoding
let buffer = writer.get_ref();
let mut reader = FramedRead::new(buffer.as_slice(), AddressCodec);
for var in vars {
Expand All @@ -188,7 +169,6 @@ mod test {
];

for addr in vars {
// Encode the address
let buffer = Vec::with_capacity(128);
let mut writer = FramedWrite::new(buffer, AddressCodec);
writer.send(addr.clone()).await?;
Expand Down
1 change: 0 additions & 1 deletion crates/tuic-core/src/proto/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ pub enum ProtoError {
// Caller should yield
BytesRemaining,
Io {
// #[snafu(backtrace)]
source: std::io::Error,
backtrace: Backtrace,
},
Expand Down
Loading
Loading