feat: switch to JSON with comments (JSONC) for config; docs: update READMEs

This commit is contained in:
ospab 2026-05-16 19:23:17 +03:00
parent acc5e87878
commit f419bfa4ee
6 changed files with 29 additions and 22 deletions

View File

@ -45,12 +45,13 @@ Initialize a default config file:
``` ```
### Server (config.json) ### Server (config.json)
```json ```jsonc
{ {
"_comment": "OSTP Server Configuration", // OSTP Server Configuration
"mode": "server", "mode": "server",
"listen": "0.0.0.0:50000", "listen": "0.0.0.0:50000",
"access_keys": ["YOUR_KEY"], "access_keys": ["YOUR_KEY"],
// Optional: forward traffic to another proxy
"outbound": { "outbound": {
"enabled": false, "enabled": false,
"protocol": "socks5", "protocol": "socks5",
@ -62,13 +63,14 @@ Initialize a default config file:
``` ```
### Client (config.json) ### Client (config.json)
```json ```jsonc
{ {
"_comment": "OSTP Client Configuration", // OSTP Client Configuration
"mode": "client", "mode": "client",
"server": "SERVER_IP:50000", "server": "SERVER_IP:50000",
"access_key": "YOUR_KEY", "access_key": "YOUR_KEY",
"socks5_bind": "127.0.0.1:1088", "socks5_bind": "127.0.0.1:1088",
// Virtual network adapter settings
"tun": { "tun": {
"enable": false, "enable": false,
"wintun_path": "./wintun.dll", "wintun_path": "./wintun.dll",

View File

@ -45,12 +45,13 @@ irm https://raw.githubusercontent.com/ospab/ostp/master/scripts/install.ps1 | ie
``` ```
### Сервер (config.json) ### Сервер (config.json)
```json ```jsonc
{ {
"_comment": "OSTP Server Configuration", // Конфигурация Сервера OSTP
"mode": "server", "mode": "server",
"listen": "0.0.0.0:50000", "listen": "0.0.0.0:50000",
"access_keys": ["ВАШ_КЛЮЧ"], "access_keys": ["ВАШ_КЛЮЧ"],
// Опционально: пересылка трафика через другой прокси
"outbound": { "outbound": {
"enabled": false, "enabled": false,
"protocol": "socks5", "protocol": "socks5",
@ -62,13 +63,14 @@ irm https://raw.githubusercontent.com/ospab/ostp/master/scripts/install.ps1 | ie
``` ```
### Клиент (config.json) ### Клиент (config.json)
```json ```jsonc
{ {
"_comment": "OSTP Client Configuration", // Конфигурация Клиента OSTP
"mode": "client", "mode": "client",
"server": "IP_СЕРВЕРА:50000", "server": "IP_СЕРВЕРА:50000",
"access_key": "ВАШ_КЛЮЧ", "access_key": "ВАШ_КЛЮЧ",
"socks5_bind": "127.0.0.1:1088", "socks5_bind": "127.0.0.1:1088",
// Настройки виртуального сетевого адаптера
"tun": { "tun": {
"enable": false, "enable": false,
"wintun_path": "./wintun.dll", "wintun_path": "./wintun.dll",

View File

@ -13,5 +13,6 @@ ostp-core = { path = "../ostp-core" }
rand.workspace = true rand.workspace = true
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
json-comments = "0.2"
portable-atomic.workspace = true portable-atomic.workspace = true
chrono = "0.4" chrono = "0.4"

View File

@ -160,7 +160,8 @@ impl ClientConfig {
let raw = std::fs::read_to_string(&path) let raw = std::fs::read_to_string(&path)
.with_context(|| format!("failed to read {}", path.display()))?; .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()))?; .with_context(|| format!("failed to parse {}", path.display()))?;
let is_tun = raw.tun.as_ref().and_then(|t| t.enable).unwrap_or(false); let is_tun = raw.tun.as_ref().and_then(|t| t.enable).unwrap_or(false);

View File

@ -12,6 +12,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0" serde_json = "1.0"
anyhow = "1.0" anyhow = "1.0"
clap = { version = "4.4", features = ["derive"] } clap = { version = "4.4", features = ["derive"] }
json-comments = "0.2"
base64 = "0.22" base64 = "0.22"
rand.workspace = true rand.workspace = true
url = "2.5" url = "2.5"

View File

@ -315,27 +315,26 @@ async fn run_app() -> Result<()> {
let key = generate_secure_key("hex"); let key = generate_secure_key("hex");
let content = if is_server { let content = if is_server {
format!(r#"{{ format!(r#"{{
"_comment": "OSTP Server Configuration", // OSTP Server Configuration
"mode": "server", "mode": "server",
"log_level": "info", "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", "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": [ "access_keys": [
"{}" "{}"
], ],
"_comment_outbound": "Optional proxy for outbound traffic. If enabled, the server routes traffic through this proxy.", // Optional proxy for outbound traffic.
"outbound": {{ "outbound": {{
"enabled": false, "enabled": false,
"protocol": "socks5", "protocol": "socks5",
"address": "127.0.0.1", "address": "127.0.0.1",
"port": 9050, "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", "default_action": "proxy",
"_comment_rules": "Specific routing rules. Action can be 'proxy', 'direct', or 'block'.",
"rules": [ "rules": [
{{ {{
"domain_suffix": [".onion"], "domain_suffix": [".onion"],
@ -347,20 +346,20 @@ async fn run_app() -> Result<()> {
}}"#, key) }}"#, key)
} else { } else {
format!(r#"{{ format!(r#"{{
"_comment": "OSTP Client Configuration", // OSTP Client Configuration
"mode": "client", "mode": "client",
"log_level": "info", "log_level": "info",
"_comment_server": "Address of the remote OSTP server", // Address of the remote OSTP server
"server": "127.0.0.1:50000", "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": "{}", "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", "socks5_bind": "127.0.0.1:1088",
"_comment_tun": "Virtual network adapter settings (requires tun2socks.exe to be present)", // Virtual network adapter settings
"tun": {{ "tun": {{
"enable": false, "enable": false,
"wintun_path": "./wintun.dll", "wintun_path": "./wintun.dll",
@ -368,7 +367,7 @@ async fn run_app() -> Result<()> {
"dns": "1.1.1.1" "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": {{ "exclude": {{
"domains": ["localhost", "127.0.0.1"], "domains": ["localhost", "127.0.0.1"],
"ips": [], "ips": [],
@ -411,7 +410,8 @@ async fn run_app() -> Result<()> {
} }
let config_content = fs::read_to_string(&args.config)?; 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))?; .map_err(|e| anyhow!("Failed to parse config: {}", e))?;
config.validate()?; config.validate()?;