Refractium
Extensible low-level reverse proxy for port multiplexing and protocol-based routing.
refractium is a high-performance multiplexer that identifies incoming traffic by protocol signature and routes it to the correct backend. It allows Web, SSH, and custom binary services to coexist on the same external port with near-native throughput.
Features
-
Expose one single port for multiple services
- You can run an HTTP server and an SSH daemon on port 80 simultaneously.
- Automatically detects protocols by inspecting the initial bytes of the stream.
-
Load Balancing & Health Checks
- Distributes traffic across multiple backend instances (Round Robin).
- Active monitoring: automatically skips dead backends to ensure zero-downtime routing.
-
TCP & UDP Support
- Handles both stream-based (TCP) and packet-based (UDP) traffic within the same engine.
- Optimized for low-latency infrastructure and high-throughput applications.
-
Extensible
- You can define new protocols in the
refractium.tomlfile. Or use Refractium as a library and define new built-in protocols.
- You can define new protocols in the
-
Hot Reload
- Update your routing table without dropping active connections or restarting the server.
-
Graceful Shutdown
- Built-in support for cancellation tokens to ensure clean termination.
How it works
refractium operates at the edge of the transport layer. Unlike Layer 7 proxies (Nginx, HAProxy) that often parse the entire request, refractium:
- Peeks: It briefly inspects the very first bytes of a connection without consuming them.
- Identifies: Matches the signature against its protocol registry in nanoseconds.
- Welds: Once the destination is known, it "welds" the incoming stream directly to the backend.
By using zero-copy techniques, data flows through the proxy with near-native throughput, as if the client were directly connected to the target service.
Why Refractium?
Because managing multiple open ports on a firewall is tedious and restricts your architectural flexibility.
refractium lets you:
- Bypass Firewall Restrictions: Expose services that would normally be blocked by using standard ports (80, 443).
- Consolidate IP Resources: Multiplex diverse protocols on a single public IP address.
- Scale Transparently: Your backends receive traffic as if they were directly connected; they don't need to be "Refractium-aware."
Installation
Direct Download
Grab the pre-built binary for your operating system from the Latest Releases.
From Source (Cargo)
Cargo Features:
default/full(contains:cli,logging,protocols,watchfeatures)protocols(contains:proto-http,proto-https,proto-ssh,proto-dns,proto-ftpfeatures)cli: Includes the command line interface modules.logging: Includestracingandtracing-subscriberlibrarieswatch: Includes hot-reload functions.
Command Reference
| Command | Description | Details |
|---|---|---|
init |
Generate default config | Creates a refractium.toml in the current directory. |
tcp |
Run TCP server only | Ignores UDP routes defined in the config. |
udp |
Run UDP server only | Ignores TCP routes defined in the config. |
| (none) | Run both TCP & UDP | Default behavior. Listen on both protocols. |
Global Options:
-b,--bind: Address to bind to (Default:0.0.0.0).-p,--port: Port to listen on (Default:8080).-c,--config: Path to configuration file (Default:refractium.toml).-f,--forward: Inline routing rules (e.g.,ssh=127.0.0.1:22).--debug: Enable verbose logging.
Usage Examples
Zero-Config (CLI only)
You don't need a refractium.toml file to start using Refractium. Use the -f flag to define routes on the fly:
# Route HTTP and SSH on port 80
# Load balance HTTP across multiple backends
Using a Configuration File
Create a refractium.toml to define more complex routing, including custom byte patterns and transport settings.
1. Initialize the config:
2. Edit refractium.toml:
[]
= "0.0.0.0"
= 8080
[[]]
= "http"
= "127.0.0.1:3000"
[[]]
= "ssh"
= "127.0.0.1:22"
[[]]
= "dns"
= "1.1.1.1:53"
# Custom protocol via magic bytes
[[]]
= "my_app"
= ["\x01\x02\x03", "MY_PROTO_V1"]
= "127.0.0.1:9000"
= "udp"
3. Run with the config:
# Or if you want to define the route to the config file:
Built-in Protocols
| Protocol | Transport | Support | Features |
|---|---|---|---|
| HTTP | TCP | ✅ | Standard method detection (GET, POST, etc.) |
| HTTPS | TCP | ✅ | SNI Extraction for domain-based routing |
| SSH | TCP | ✅ | Handshake version string identification |
| DNS | UDP | ✅ | Packet-level classification |
| FTP | TCP | ✅ | Protocol signature matching |
Performance
Refractium is designed for extreme speed. Protocol identification happens in nanoseconds, adding negligible overhead to your connections.
Identification Benchmarks:
- HTTP: ~16 ns
- HTTPS (SNI): ~47 ns
- SSH: ~24 ns
- DNS (UDP): ~25 ns
- Mixed Traffic: ~56 ns
Environment: Intel Core i7-7700 @ 3.60GHz. Run cargo bench to verify on your own hardware.
Library Usage (Extensibility)
Refractium is also a modular engine. You can define complex identification logic in Rust by implementing the RefractiumProtocol trait or using the provided macro:
use ;
use Arc;
// Define a new protocol outside the project
define_protocol!;
async
Reliability
- Memory Safety: Built 100% in Rust with zero
unsafeblocks. - Panic-Free: Rigorous use of
clippydenials to ensure the proxy never crashes in production. - Resource Protection: Configurable peek buffers and timeouts to mitigate slow-loris style attacks.