trojan-rs
A high-performance Rust implementation of the Trojan protocol.
Features
- High Performance - Built with async Rust and Tokio for maximum throughput
- TLS 1.3 Support - Modern encryption with configurable TLS versions and mTLS
- WebSocket Transport - Optional WebSocket encapsulation for CDN compatibility
- Multiple Auth Backends - Memory, SQLite, PostgreSQL, and MySQL support
- User Management - Full CLI for managing users with traffic limits
- Prometheus Metrics - Built-in metrics exporter for monitoring
- Analytics - Connection event tracking with ClickHouse backend
- Rate Limiting - Per-IP connection rate limiting
- TCP Tuning - Configurable TCP_NODELAY, Keep-Alive, SO_REUSEPORT, TCP Fast Open
- Fallback Server - Configurable fallback with connection warm pool
- Certificate Management - Self-signed certificate generation (optional feature)
- Self-Upgrade - Auto-update from GitHub releases (optional feature)
- Cross-Platform - Linux, macOS, and Windows support
Installation
Pre-built Binaries
Download from GitHub Releases.
Cargo
From Source
Usage
Server
# Run with config file
# Run with CLI options
Certificate Generation
# Generate a self-signed certificate
User Management (SQL Backend)
# Initialize database
# Add user
# List users
# Remove user
Configuration
Supports TOML, YAML, JSON, and JSONC formats. Create a config.toml file:
[]
= "0.0.0.0:443"
= "127.0.0.1:80"
= 600
= 60
[]
= true
= 300
= false
= false
[]
= "/etc/trojan/cert.pem"
= "/etc/trojan/key.pem"
= ["http/1.1"]
[]
= ["password1", "password2"]
[]
= true
= "mixed"
= "/ws"
[]
= "127.0.0.1:9100"
[]
= "info"
For all available options, see the trojan-config documentation.
Supported Platforms
| Platform | Architecture |
|---|---|
| Linux | x86_64, aarch64, armv7, i686 |
| Linux (musl) | x86_64, aarch64, armv7, i686 |
| macOS | x86_64, aarch64 (Apple Silicon) |
| Windows | x86_64 |
Crates
| Crate | Description |
|---|---|
trojan-core |
Core types and utilities |
trojan-proto |
Protocol encoding/decoding |
trojan-auth |
Authentication backends |
trojan-config |
Configuration parsing |
trojan-metrics |
Prometheus metrics |
trojan-analytics |
Connection tracking |
trojan-server |
Server implementation |
trojan-cert |
Certificate management |
License
GPL-3.0-only