This commit is contained in:
Pierre HUBERT 2022-08-30 11:01:24 +02:00
parent 641bc1b992
commit 09b5403390
3 changed files with 33 additions and 1 deletions

View File

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

View File

@ -3,6 +3,7 @@ use std::sync::Arc;
use clap::Parser; use clap::Parser;
use base::RemoteConfig; use base::RemoteConfig;
use tcp_relay_client::relay_client::relay_client;
/// TCP relay client /// TCP relay client
#[derive(Parser, Debug, Clone)] #[derive(Parser, Debug, Clone)]
@ -41,7 +42,23 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
} }
let conf = req.json::<RemoteConfig>() let conf = req.json::<RemoteConfig>()
.await?; .await?;
println!("{:#?}", conf);
// Start to listen port
let mut handles = vec![];
for port in conf {
let listen_address = format!("{}:{}", args.listen_address, port.port);
let args_clone = args.clone();
let handle = std::thread::spawn(move || {
relay_client(&args_clone.token, port.id,
&args_clone.listen_address, &listen_address);
});
handles.push(handle);
}
for h in handles {
h.join().unwrap();
}
Ok(()) Ok(())
} }

View File

@ -0,0 +1,14 @@
use std::future::Future;
use std::net::TcpListener;
pub fn relay_client(token: &str, port_id: usize, server: &str, listen_address: &str) {
log::info!("({}) Start to listen on {}", port_id, listen_address);
let listener = match TcpListener::bind(&listen_address) {
Ok(l) => l,
Err(e) => {
log::error!("Failed to start to listen on {}!", listen_address);
std::process::exit(3);
}
};
}