Initial commit
This commit is contained in:
commit
2441552165
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
target
|
||||
.idea
|
1308
Cargo.lock
generated
Normal file
1308
Cargo.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
7
Cargo.toml
Normal file
7
Cargo.toml
Normal file
@ -0,0 +1,7 @@
|
||||
[workspace]
|
||||
|
||||
members = [
|
||||
"base",
|
||||
"tcp_relay_server",
|
||||
"tcp_relay_client"
|
||||
]
|
7
base/Cargo.toml
Normal file
7
base/Cargo.toml
Normal 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
5
base/src/lib.rs
Normal file
@ -0,0 +1,5 @@
|
||||
#[derive(serde::Serialize, serde::Deserialize)]
|
||||
pub struct RelayedPort {
|
||||
pub id: u64,
|
||||
pub port: u16,
|
||||
}
|
6
tcp_relay_client/Cargo.toml
Normal file
6
tcp_relay_client/Cargo.toml
Normal file
@ -0,0 +1,6 @@
|
||||
[package]
|
||||
name = "tcp_realy_client"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
|
||||
[dependencies]
|
0
tcp_relay_client/src/lib.rs
Normal file
0
tcp_relay_client/src/lib.rs
Normal file
10
tcp_relay_server/Cargo.toml
Normal file
10
tcp_relay_server/Cargo.toml
Normal 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"
|
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!"
|
||||
}
|
Loading…
Reference in New Issue
Block a user