1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! 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:
//!
//! ```no_run
//! 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;
//!
//! # async fn demo() -> anyhow::Result<()> {
//! 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??;
//! # Ok(())
//! # }
//! ```
//!
//! The command-line interface and terminal UI are in the separate `erbridge`
//! crate, so depending on this one pulls in neither.