Changes to be committed:
modified: src/client.rs
This commit is contained in:
parent
52eb094aa5
commit
1887d32241
@ -38,14 +38,14 @@ pub async fn client_mode(client_config: ClientConfiguration, fd: i32) {
|
|||||||
|
|
||||||
let cipher_shared = Arc::new(Mutex::new(None));
|
let cipher_shared = Arc::new(Mutex::new(None));
|
||||||
|
|
||||||
tokio::spawn(async move {
|
let tun_writer_task = tokio::spawn(async move {
|
||||||
while let Ok(bytes) = rx.recv() {
|
while let Ok(bytes) = rx.recv() {
|
||||||
info!("Write to tun");
|
info!("Write to tun");
|
||||||
dev_writer.write_all(&bytes).unwrap();
|
dev_writer.write_all(&bytes).unwrap();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
tokio::spawn(async move {
|
let tun_reader_task = tokio::spawn(async move {
|
||||||
let mut buf = vec![0; 8192];
|
let mut buf = vec![0; 8192];
|
||||||
while let Ok(n) = dev_reader.read(&mut buf) {
|
while let Ok(n) = dev_reader.read(&mut buf) {
|
||||||
dx.send(buf[..n].to_vec()).unwrap();
|
dx.send(buf[..n].to_vec()).unwrap();
|
||||||
@ -55,7 +55,7 @@ pub async fn client_mode(client_config: ClientConfiguration, fd: i32) {
|
|||||||
let priv_key = BASE64_STANDARD.decode(client_config.client.private_key).unwrap();
|
let priv_key = BASE64_STANDARD.decode(client_config.client.private_key).unwrap();
|
||||||
|
|
||||||
let cipher_shared_clone = cipher_shared.clone();
|
let cipher_shared_clone = cipher_shared.clone();
|
||||||
tokio::spawn(async move {
|
let socket_reader_task = tokio::spawn(async move {
|
||||||
let mut buf = vec![0; 4096];
|
let mut buf = vec![0; 4096];
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
@ -101,6 +101,9 @@ pub async fn client_mode(client_config: ClientConfiguration, fd: i32) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let s_cipher = cipher_shared.clone();
|
||||||
|
|
||||||
|
let socket_writer_task = tokio::spawn(async move {
|
||||||
let pkey = BASE64_STANDARD.decode(client_config.client.public_key).unwrap();
|
let pkey = BASE64_STANDARD.decode(client_config.client.public_key).unwrap();
|
||||||
let handshake = UDPVpnHandshake{ public_key: pkey, request_ip: client_config.client.address.parse::<Ipv4Addr>().unwrap() };
|
let handshake = UDPVpnHandshake{ public_key: pkey, request_ip: client_config.client.address.parse::<Ipv4Addr>().unwrap() };
|
||||||
let mut nz = 0;
|
let mut nz = 0;
|
||||||
@ -110,7 +113,6 @@ pub async fn client_mode(client_config: ClientConfiguration, fd: i32) {
|
|||||||
}
|
}
|
||||||
//sock_snd.send(&handshake.serialize()).await.unwrap();
|
//sock_snd.send(&handshake.serialize()).await.unwrap();
|
||||||
|
|
||||||
let s_cipher = cipher_shared.clone();
|
|
||||||
loop {
|
loop {
|
||||||
if let Ok(bytes) = mx.recv() {
|
if let Ok(bytes) = mx.recv() {
|
||||||
let s_c = s_cipher.lock().await;
|
let s_c = s_cipher.lock().await;
|
||||||
@ -133,4 +135,7 @@ pub async fn client_mode(client_config: ClientConfiguration, fd: i32) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
tokio::join!(tun_writer_task, tun_reader_task, socket_writer_task, socket_reader_task);
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user