Changes to be committed:

modified:   src/client.rs
	modified:   src/main.rs
This commit is contained in:
Michael Wain 2024-08-11 21:01:45 +03:00
parent 81fa1b1db3
commit 9e885b7bf8
2 changed files with 13 additions and 17 deletions

View File

@ -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::<Vec<u8>>(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::<SocketAddr>()
.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]);

View File

@ -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.");
}