Changes to be committed:
modified: src/server.rs
This commit is contained in:
parent
7043c9bbee
commit
6ce51c0679
@ -96,90 +96,6 @@ pub async fn server_mode() {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/* let sock_main = sock.clone();
|
||||
|
||||
let clients_main = clients.clone();
|
||||
|
||||
|
||||
let tun_device_clone = tun_device.clone();
|
||||
let sock_clone = sock.clone();
|
||||
let clients_clone = clients.clone();
|
||||
let tun_device_clone_second = tun_device.clone();
|
||||
|
||||
let mut set = JoinSet::new();
|
||||
|
||||
set.spawn(async move {
|
||||
let mut buf = [0; 1024];
|
||||
loop {
|
||||
let mut tun = tun_device_clone_second.lock().await;
|
||||
let len = match tun.read(&mut buf) {
|
||||
Ok(l) => l,
|
||||
Err(error) => {
|
||||
error!("Problem with reading from tun: {error:?}");
|
||||
0
|
||||
},
|
||||
};
|
||||
|
||||
if len <= 0 { continue; }
|
||||
|
||||
info!("{:?} bytes received from tun", len);
|
||||
let sock_main_instance = sock_main.lock().await;
|
||||
let clients_main_instance = clients_main.lock().await;
|
||||
match clients_main_instance.get(&"10.8.0.2") {
|
||||
Some(&addr) => {
|
||||
sock_main_instance.send_to(&buf, addr);
|
||||
info!("bytes sent to socket");
|
||||
},
|
||||
None => error!("There is no client..."),
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
set.spawn(async move {
|
||||
let mut buf = [0; 1024];
|
||||
loop {
|
||||
let sock = sock_clone.lock().await;
|
||||
let (len, addr) = match sock.recv_from(&mut buf).await {
|
||||
Err(error) => {
|
||||
error!("Problem with reading from socket: {error:?}");
|
||||
(0, SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), 0))
|
||||
},
|
||||
Ok(l) => l,
|
||||
};
|
||||
|
||||
if len <= 0 { continue; }
|
||||
|
||||
let mut tun = tun_device_clone.lock().await;
|
||||
let mut clients = clients_clone.lock().await;
|
||||
|
||||
clients.insert("10.8.0.2", addr);
|
||||
info!("{:?} bytes received from {:?}", len, addr);
|
||||
|
||||
let len = match tun.write(&buf) {
|
||||
Ok(l) => l,
|
||||
Err(error) => {
|
||||
error!("Problem with writing to tun: {error:?}");
|
||||
0
|
||||
}
|
||||
};
|
||||
|
||||
info!("{:?} bytes sent to tun", len);
|
||||
}
|
||||
});*/
|
||||
|
||||
/* let tasks = vec![
|
||||
tokio::spawn(),
|
||||
|
||||
tokio::spawn()
|
||||
];
|
||||
|
||||
futures::future::join_all(tasks).await;*/
|
||||
|
||||
while let Some(res) = set.join_next().await {}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user