forked from kaichaosun/rlt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.rs
More file actions
116 lines (107 loc) · 3.15 KB
/
Copy pathmain.rs
File metadata and controls
116 lines (107 loc) · 3.15 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
use anyhow::Result;
use clap::{Parser, Subcommand};
use localtunnel_client::{broadcast, open_tunnel, ClientConfig};
use localtunnel_server::{start, ServerConfig};
use tokio::signal;
mod config;
#[derive(Parser)]
#[clap(author, version, about)]
#[clap(propagate_version = true)]
struct Cli {
#[clap(subcommand)]
command: Command,
}
#[derive(Subcommand)]
enum Command {
/// Builds connection between remote proxy server and local api.
Client {
/// Address of proxy server
#[clap(long)]
host: String,
/// Subdomain of the proxied url
#[clap(long)]
subdomain: String,
/// The local host to expose.
#[clap(long, default_value = "127.0.0.1")]
local_host: String,
/// The local port to expose.
#[clap(short, long)]
port: u16,
/// Max connections allowed to server.
#[clap(long, default_value = "10")]
max_conn: u8,
#[clap(long)]
credential: Option<String>,
},
/// Starts proxy server to accept user connections and proxy setup connection.
Server {
/// Domain name of the proxy server, required if use subdomain like lt.example.com.
#[clap(long)]
domain: String,
/// The port to accept initialize proxy endpoint.
#[clap(short, long, default_value = "3000")]
port: u16,
/// The flag to indicate proxy over https.
#[clap(long)]
secure: bool,
/// Maximum number of tcp sockets each client to establish at one time.
#[clap(long, default_value = "10")]
max_sockets: u8,
/// The port to accept user request for proxying.
#[clap(long, default_value = "3001")]
proxy_port: u16,
#[clap(long)]
require_auth: bool,
},
}
#[tokio::main]
async fn main() -> Result<()> {
config::setup();
log::info!("Run localtunnel CLI!");
let command = Cli::parse().command;
match command {
Command::Client {
host,
subdomain,
local_host,
port,
max_conn,
credential,
} => {
let (notify_shutdown, _) = broadcast::channel(1);
let config = ClientConfig {
server: Some(host),
subdomain: Some(subdomain),
local_host: Some(local_host),
local_port: port,
shutdown_signal: notify_shutdown.clone(),
max_conn,
credential,
reregister_after: None,
};
let result = open_tunnel(config).await?;
log::info!("Tunnel url: {:?}", result);
signal::ctrl_c().await?;
log::info!("Quit");
}
Command::Server {
domain,
port,
secure,
max_sockets,
proxy_port,
require_auth,
} => {
let config = ServerConfig {
domain,
api_port: port,
secure,
max_sockets,
proxy_port,
require_auth,
};
start(config).await?;
}
}
Ok(())
}