diff --git a/README.md b/README.md index f7d8a81..c2fbb51 100644 --- a/README.md +++ b/README.md @@ -45,12 +45,13 @@ Initialize a default config file: ``` ### Server (config.json) -```json +```jsonc { - "_comment": "OSTP Server Configuration", + // OSTP Server Configuration "mode": "server", "listen": "0.0.0.0:50000", "access_keys": ["YOUR_KEY"], + // Optional: forward traffic to another proxy "outbound": { "enabled": false, "protocol": "socks5", @@ -62,13 +63,14 @@ Initialize a default config file: ``` ### Client (config.json) -```json +```jsonc { - "_comment": "OSTP Client Configuration", + // OSTP Client Configuration "mode": "client", "server": "SERVER_IP:50000", "access_key": "YOUR_KEY", "socks5_bind": "127.0.0.1:1088", + // Virtual network adapter settings "tun": { "enable": false, "wintun_path": "./wintun.dll", diff --git a/README.ru.md b/README.ru.md index be1227c..b7bf379 100644 --- a/README.ru.md +++ b/README.ru.md @@ -45,12 +45,13 @@ irm https://raw.githubusercontent.com/ospab/ostp/master/scripts/install.ps1 | ie ``` ### Сервер (config.json) -```json +```jsonc { - "_comment": "OSTP Server Configuration", + // Конфигурация Сервера OSTP "mode": "server", "listen": "0.0.0.0:50000", "access_keys": ["ВАШ_КЛЮЧ"], + // Опционально: пересылка трафика через другой прокси "outbound": { "enabled": false, "protocol": "socks5", @@ -62,13 +63,14 @@ irm https://raw.githubusercontent.com/ospab/ostp/master/scripts/install.ps1 | ie ``` ### Клиент (config.json) -```json +```jsonc { - "_comment": "OSTP Client Configuration", + // Конфигурация Клиента OSTP "mode": "client", "server": "IP_СЕРВЕРА:50000", "access_key": "ВАШ_КЛЮЧ", "socks5_bind": "127.0.0.1:1088", + // Настройки виртуального сетевого адаптера "tun": { "enable": false, "wintun_path": "./wintun.dll", diff --git a/ostp-client/Cargo.toml b/ostp-client/Cargo.toml index 12316b3..d6f4e0e 100644 --- a/ostp-client/Cargo.toml +++ b/ostp-client/Cargo.toml @@ -13,5 +13,6 @@ ostp-core = { path = "../ostp-core" } rand.workspace = true serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" +json-comments = "0.2" portable-atomic.workspace = true chrono = "0.4" diff --git a/ostp-client/src/config.rs b/ostp-client/src/config.rs index d21d51e..99fff7c 100644 --- a/ostp-client/src/config.rs +++ b/ostp-client/src/config.rs @@ -160,7 +160,8 @@ impl ClientConfig { let raw = std::fs::read_to_string(&path) .with_context(|| format!("failed to read {}", path.display()))?; - let raw: RawUnifiedConfig = serde_json::from_str(&raw) + let mut stripped = json_comments::StripComments::new(raw.as_bytes()); + let raw: RawUnifiedConfig = serde_json::from_reader(&mut stripped) .with_context(|| format!("failed to parse {}", path.display()))?; let is_tun = raw.tun.as_ref().and_then(|t| t.enable).unwrap_or(false); diff --git a/ostp/Cargo.toml b/ostp/Cargo.toml index f457b79..bb59abc 100644 --- a/ostp/Cargo.toml +++ b/ostp/Cargo.toml @@ -12,6 +12,7 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" anyhow = "1.0" clap = { version = "4.4", features = ["derive"] } +json-comments = "0.2" base64 = "0.22" rand.workspace = true url = "2.5" diff --git a/ostp/src/main.rs b/ostp/src/main.rs index fa94190..ab96e54 100644 --- a/ostp/src/main.rs +++ b/ostp/src/main.rs @@ -315,27 +315,26 @@ async fn run_app() -> Result<()> { let key = generate_secure_key("hex"); let content = if is_server { format!(r#"{{ - "_comment": "OSTP Server Configuration", + // OSTP Server Configuration "mode": "server", "log_level": "info", - "_comment_listen": "The address and port the server listens on for incoming OSTP connections.", + // The address and port the server listens on for incoming OSTP connections. "listen": "0.0.0.0:50000", - "_comment_access_keys": "List of valid keys. Clients must use one of these to connect.", + // List of valid keys. Clients must use one of these to connect. "access_keys": [ "{}" ], - "_comment_outbound": "Optional proxy for outbound traffic. If enabled, the server routes traffic through this proxy.", + // Optional proxy for outbound traffic. "outbound": {{ "enabled": false, "protocol": "socks5", "address": "127.0.0.1", "port": 9050, - "_comment_default_action": "Can be 'proxy' (route all traffic through proxy by default) or 'direct' (bypass proxy by default).", + // default_action: 'proxy' (all through proxy) or 'direct' (bypass proxy by default). "default_action": "proxy", - "_comment_rules": "Specific routing rules. Action can be 'proxy', 'direct', or 'block'.", "rules": [ {{ "domain_suffix": [".onion"], @@ -347,20 +346,20 @@ async fn run_app() -> Result<()> { }}"#, key) } else { format!(r#"{{ - "_comment": "OSTP Client Configuration", + // OSTP Client Configuration "mode": "client", "log_level": "info", - "_comment_server": "Address of the remote OSTP server", + // Address of the remote OSTP server "server": "127.0.0.1:50000", - "_comment_access_key": "Must match one of the access_keys on the server", + // Must match one of the access_keys on the server "access_key": "{}", - "_comment_socks5_bind": "The local port where the system/browser should connect (HTTP/SOCKS5)", + // The local port for HTTP/SOCKS5 proxying "socks5_bind": "127.0.0.1:1088", - "_comment_tun": "Virtual network adapter settings (requires tun2socks.exe to be present)", + // Virtual network adapter settings "tun": {{ "enable": false, "wintun_path": "./wintun.dll", @@ -368,7 +367,7 @@ async fn run_app() -> Result<()> { "dns": "1.1.1.1" }}, - "_comment_exclude": "Bypass tunnel for these domains/IPs (only works in proxy mode)", + // Bypass tunnel for these domains/IPs "exclude": {{ "domains": ["localhost", "127.0.0.1"], "ips": [], @@ -411,7 +410,8 @@ async fn run_app() -> Result<()> { } let config_content = fs::read_to_string(&args.config)?; - let config: UnifiedConfig = serde_json::from_str(&config_content) + let mut stripped = json_comments::StripComments::new(config_content.as_bytes()); + let config: UnifiedConfig = serde_json::from_reader(&mut stripped) .map_err(|e| anyhow!("Failed to parse config: {}", e))?; config.validate()?;