Initial commit
This commit is contained in:
1
tcp_relay_server/src/lib.rs
Normal file
1
tcp_relay_server/src/lib.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod server;
|
56
tcp_relay_server/src/main.rs
Normal file
56
tcp_relay_server/src/main.rs
Normal file
@ -0,0 +1,56 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use actix_web::{App, HttpServer, web};
|
||||
use clap::Parser;
|
||||
|
||||
use tcp_relay_server::server::*;
|
||||
|
||||
/// TCP relay server
|
||||
#[derive(Parser, Debug, Clone)]
|
||||
#[clap(author, version, about, long_about = None)]
|
||||
struct Args {
|
||||
/// Access tokens
|
||||
#[clap(short, long)]
|
||||
tokens: Vec<String>,
|
||||
|
||||
/// Forwarded ports
|
||||
#[clap(short, long)]
|
||||
ports: Vec<usize>,
|
||||
|
||||
/// HTTP server listen address
|
||||
#[clap(short, long, default_value = "0.0.0.0:8000")]
|
||||
listen_address: String,
|
||||
|
||||
/// Increment ports on client. Useful for debugging and running both client and server
|
||||
/// on the same machine
|
||||
#[clap(short, long, default_value_t = 0)]
|
||||
increment_ports: usize,
|
||||
}
|
||||
|
||||
#[actix_web::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
env_logger::init_from_env(env_logger::Env::new().default_filter_or("info"));
|
||||
|
||||
let args: Args = Args::parse();
|
||||
let args = Arc::new(args);
|
||||
|
||||
if args.ports.len() == 0 {
|
||||
log::error!("No port to forward!");
|
||||
std::process::exit(2);
|
||||
}
|
||||
|
||||
if args.tokens.len() == 0 {
|
||||
log::error!("No tokens specified!");
|
||||
std::process::exit(3);
|
||||
}
|
||||
|
||||
log::info!("Starting relay on http://{}", args.listen_address);
|
||||
|
||||
HttpServer::new(|| {
|
||||
App::new()
|
||||
.route("/", web::get().to(hello_route))
|
||||
})
|
||||
.bind(&args.listen_address)?
|
||||
.run()
|
||||
.await
|
||||
}
|
3
tcp_relay_server/src/server.rs
Normal file
3
tcp_relay_server/src/server.rs
Normal file
@ -0,0 +1,3 @@
|
||||
pub async fn hello_route() -> &'static str {
|
||||
"TCP relay. Hello world!"
|
||||
}
|
Reference in New Issue
Block a user