trojan-config
Configuration loading, validation, and CLI override support for trojan-rs.
Overview
This crate handles all configuration concerns:
- Multi-format loading — TOML, YAML, JSON, and JSONC (JSON with comments)
- Typed config structs — Strongly-typed configuration with serde, including defaults for all optional fields
- CLI overrides — Every config option can be overridden via command-line flags
- Validation — Comprehensive config validation with clear error messages
Module Structure
| Module | Description |
|---|---|
types |
Server, TLS, WebSocket, auth, metrics, logging config structs |
analytics |
ClickHouse analytics configuration |
cli |
CLI override struct and apply_overrides() |
loader |
File loading with format detection by extension |
validate |
Configuration validation rules |
defaults |
Default value functions backed by trojan-core constants |
Supported Formats
| Extension | Format |
|---|---|
.toml |
TOML |
.yaml, .yml |
YAML |
.json |
JSON (with comment support) |
.jsonc |
JSON with comments |
Usage
use ;
let mut config = load_config?;
apply_overrides;
validate_config?;
Key Types
Config— Top-level configuration withserver,tls,auth,websocket,metrics,logging,analyticssectionsServerConfig— Listen address, fallback, timeouts, rate limiting, connection pool, TCP optionsTcpConfig— TCP_NODELAY, Keep-Alive, SO_REUSEPORT, TCP Fast OpenTlsConfig— Certificate, key, ALPN, TLS version range, mTLS, cipher suitesCliOverrides— Clap-derived struct for command-line overrides
License
GPL-3.0-only