wip
This commit is contained in:
parent
641bc1b992
commit
09b5403390
@ -0,0 +1 @@
|
||||
pub mod relay_client;
|
@ -3,6 +3,7 @@ use std::sync::Arc;
|
||||
use clap::Parser;
|
||||
|
||||
use base::RemoteConfig;
|
||||
use tcp_relay_client::relay_client::relay_client;
|
||||
|
||||
/// TCP relay client
|
||||
#[derive(Parser, Debug, Clone)]
|
||||
@ -41,7 +42,23 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}
|
||||
let conf = req.json::<RemoteConfig>()
|
||||
.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(())
|
||||
}
|
14
tcp_relay_client/src/relay_client.rs
Normal file
14
tcp_relay_client/src/relay_client.rs
Normal 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);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user