Skip to main content

Crate erbridge_core

Crate erbridge_core 

Source
Expand description

TCP/UDP port forwarding and reverse tunnels, usable as a library.

Embedding the connect role of a reverse tunnel, with a way to stop it and to observe what it is doing:

use erbridge_core::config::{ConnectConfig, ConnectTunnel};
use erbridge_core::reverse::connect::run_connect_with_shutdown;
use erbridge_core::stats::{Event, Registry};
use tokio_util::sync::CancellationToken;

let cfg = ConnectConfig {
    server: "relay.example.com:9000".into(),
    token: "secret".into(),
    tunnel: vec![ConnectTunnel {
        name: "web".into(),
        target: "127.0.0.1:8080".into(),
    }],
    reconnect_min_secs: 1,
    reconnect_max_secs: 30,
};

let registry = Registry::new();
let mut events = registry.subscribe();
let shutdown = CancellationToken::new();
let task = tokio::spawn(run_connect_with_shutdown(cfg, registry, shutdown.clone()));

while let Ok(event) = events.recv().await {
    if let Event::Error { message } = event {
        eprintln!("tunnel: {message}");
    }
}

shutdown.cancel();
task.await??;

The command-line interface and terminal UI are in the separate erbridge crate, so depending on this one pulls in neither.

Modules§

client
Companion to a forward mapping secured with a transport: listens locally in plaintext, and for every accepted connection dials the far side mapping using that same transport, then relays bytes – letting a plain local client (that doesn’t speak TLS or Noise) reach it.
config
forward
Direct forward mode: external listen port -> internal target host:port, for TCP, UDP, or both, all reachable directly (no reverse hop needed).
reverse
Reverse tunnel: A (serve) listens for an external client’s traffic and for B (connect) to dial in; once B is connected, A multiplexes every external connection as a yamux stream over the single A<->B link, and B dials the locally-configured target for each stream it receives.
sni
Reads the SNI out of a TLS ClientHello without terminating TLS, so a router can pick a destination and then replay the exact bytes it consumed.
stats
tenant
Tenants and enrollment codes for a multi-tenant serve, and the snapshot type the handshake and router consult. Nothing here touches a socket.
tenant_store
Where tenants live. TenantStore is the seam a host can implement to keep them somewhere other than a file (a database, say); MemoryStore and FileStore are the two provided implementations.