diff --git a/src/client.rs b/src/client.rs index 2bee6e5..b8428b0 100644 --- a/src/client.rs +++ b/src/client.rs @@ -56,18 +56,18 @@ fn configure_routes() { } } -pub async fn client_mode(remote_addr: &str) -> io::Result<()> { +pub async fn client_mode(remote_addr: String) -> io::Result<()> { info!("Starting client..."); let mut config = tun2::Configuration::default(); config.address("10.8.0.2"); config.netmask("128.0.0.0"); config.destination("0.0.0.0"); - config.tun_name("tun0"); + config.name("tun0"); config.up(); #[cfg(target_os = "linux")] - config.platform_config(|config| { + config.platform(|config| { config.packet_information(true); }); @@ -78,13 +78,14 @@ pub async fn client_mode(remote_addr: &str) -> io::Result<()> { configure_routes(); let sock = UdpSocket::bind("0.0.0.0:59611").await?; - sock.connect(remote_addr).await?; - let r = Arc::new(sock); - let s = r.clone(); - let (tx, mut rx) = mpsc::channel::>(1_000); + sock.connect(&remote_addr).await?; + let receive_sock = Arc::new(sock); + let send_sock = Arc::new(UdpSocket::bind("0.0.0.0:59612").await?); let mut set = JoinSet::new(); + let srem = Arc::new(remote_addr.clone()); + set.spawn(async move { let mut buf = [0; 4096]; loop { @@ -92,7 +93,9 @@ pub async fn client_mode(remote_addr: &str) -> io::Result<()> { Ok(size) => { let pkt = &buf[..size]; use std::io::{Error, ErrorKind::Other}; - tx.send(pkt.to_vec()).await.unwrap(); + //tx.send(pkt.to_vec()).await.unwrap(); + send_sock.send_to(pkt, srem.parse::() + .expect("Unable to parse socket address")); info!("Wrote to sock"); } Err(error) => error!("Error with reading from tun") @@ -101,17 +104,10 @@ pub async fn client_mode(remote_addr: &str) -> io::Result<()> { } }); - set.spawn(async move { - while let Some(bytes) = rx.recv().await { - let len = s.send(&bytes).await.unwrap(); - println!("{:?} bytes sent", len); - } - }); - set.spawn(async move { let mut buf = [0; 1024]; loop { - match r.recv_from(&mut buf).await { + match receive_sock.recv_from(&mut buf).await { Ok((len, addr)) => { println!("{:?} bytes received from {:?}", len, addr); writer.write_all(&buf[..len]); diff --git a/src/main.rs b/src/main.rs index d425a28..81478a6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -47,7 +47,7 @@ async fn main() { } else { if let Some(vpn_server_ip) = matches.value_of("vpn-server") { let server_address = format!("{}:8879", vpn_server_ip); - client::client_mode(server_address.as_str()).await; + client::client_mode(server_address).await; } else { eprintln!("Error: For client mode, you shall provide the '--vpn-server' argument."); }