Initial commit

This commit is contained in:
Pierre HUBERT 2022-08-30 09:43:53 +02:00
commit 2441552165
11 changed files with 1405 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
target
.idea

1308
Cargo.lock generated Normal file

File diff suppressed because it is too large Load Diff

7
Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[workspace]
members = [
"base",
"tcp_relay_server",
"tcp_relay_client"
]

7
base/Cargo.toml Normal file
View File

@ -0,0 +1,7 @@
[package]
name = "base"
version = "0.1.0"
edition = "2021"
[dependencies]
serde = { version = "1.0.144", features = ["derive"] }

5
base/src/lib.rs Normal file
View File

@ -0,0 +1,5 @@
#[derive(serde::Serialize, serde::Deserialize)]
pub struct RelayedPort {
pub id: u64,
pub port: u16,
}

View File

@ -0,0 +1,6 @@
[package]
name = "tcp_realy_client"
version = "0.1.0"
edition = "2021"
[dependencies]

View File

View File

@ -0,0 +1,10 @@
[package]
name = "tcp_relay_server"
version = "0.1.0"
edition = "2021"
[dependencies]
clap = { version = "3.2.18", features = ["derive", "env"] }
log = "0.4.17"
env_logger = "0.9.0"
actix-web = "4"

View File

@ -0,0 +1 @@
pub mod server;

View 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
}

View File

@ -0,0 +1,3 @@
pub async fn hello_route() -> &'static str {
"TCP relay. Hello world!"
}