ferrotunnel-core
Core tunnel implementation for FerroTunnel.
Overview
This crate provides the core tunnel logic:
TunnelClient- Client-side tunnel connectionTunnelServer- Server-side tunnel listenerMultiplexer- Stream multiplexing over a single connectionSession- Session management with heartbeat trackingTlsTransport- Encrypted transport support
Components
Tunnel
- TunnelClient - Connects to server, handles handshake, runs message loop
- TunnelServer - Listens for connections, authenticates clients, manages sessions
Stream
- Multiplexer - Multiplexes virtual streams over one TCP connection; frames are sent in priority order (Critical → High → Normal → Low).
- VirtualStream - AsyncRead/AsyncWrite implementation for tunneled data; created with a stream priority for QoS.
- open_stream / open_stream_with_priority - Open streams with default or specified priority.
- Bytes pool - Thread-local buffer pooling for zero-copy transfers (configurable via env).
Transport
- TCP transport - Standard TCP connection
- TLS support - Native TLS 1.3 encryption (rustls)
Usage
use ;
// Server
let server = new;
server.run.await?;
// Client
let mut client = new;
client.connect_and_run.await?;
Configuration
Buffer pool limits (used by the stream layer) can be tuned via environment variables. Values are read once at first use.
| Variable | Default | Description |
|---|---|---|
FERROTUNNEL_POOL_MAX_SIZE |
32 | Max number of buffers per thread in the pool |
FERROTUNNEL_POOL_MAX_CAPACITY_BYTES |
65536 | Max capacity (bytes) of a buffer that is pooled; larger buffers are not reused |
FERROTUNNEL_POOL_DEFAULT_CAPACITY_BYTES |
4096 | Default capacity for newly allocated buffers |
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.