From 1f5315b79d6988fb2bbabcdd9aef8aaab5c99abd Mon Sep 17 00:00:00 2001 From: alterdekim Date: Sun, 13 Oct 2024 18:53:06 +0300 Subject: [PATCH] modified: src/client.rs --- src/client.rs | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/src/client.rs b/src/client.rs index 5d93ed3..9801146 100644 --- a/src/client.rs +++ b/src/client.rs @@ -24,16 +24,13 @@ use network_interface::NetworkInterfaceConfig; use robusta_jni::jni::JNIEnv; use crate::jni::FridaLib; -pub async fn client_mode(client_config: ClientConfiguration, fd: i32, /*env: &JNIEnv<'_>,*/ close_token: CancellationToken) { - let (ltx, mut lrx) = mpsc::unbounded_channel::>(); - info!("Starting client log.."); - ltx.send("Starting client...".as_bytes().to_vec()); +pub async fn client_mode(client_config: ClientConfiguration, fd: i32, close_token: CancellationToken) { + info!("Starting client..."); let sock = UdpSocket::bind("0.0.0.0:25565").await.unwrap(); sock.connect(&client_config.server.endpoint).await.unwrap(); - ltx.send(format!("FD: {:?}", &fd).as_bytes().to_vec()); - ltx.send("So exhausting".as_bytes().to_vec()); + info!("FD: {:?}", &fd); let mut dev = unsafe { File::from_raw_fd(fd) }; let mut dev1 = unsafe { File::from_raw_fd(fd) }; let mut dev_reader = BufReader::new(dev); @@ -47,12 +44,11 @@ pub async fn client_mode(client_config: ClientConfiguration, fd: i32, /*env: &JN let cipher_shared: Arc>> = Arc::new(Mutex::new(None)); - let llltx = ltx.clone(); let dev_read_task = tokio::spawn(async move { let mut buf = vec![0; 1400]; // mtu loop { if let Ok(n) = dev_reader.read(&mut buf).await { - llltx.send(format!("Read from tun. {:?}", hex::encode(&buf[..n])).as_bytes().to_vec()); + info!("Read from tun. {:?}", hex::encode(&buf[..n])); dx.send(buf[..n].to_vec()).unwrap(); } } @@ -61,13 +57,12 @@ pub async fn client_mode(client_config: ClientConfiguration, fd: i32, /*env: &JN let priv_key = BASE64_STANDARD.decode(client_config.client.private_key).unwrap(); let cipher_shared_clone = cipher_shared.clone(); - let sr_ltx = ltx.clone(); let sock_read_task = tokio::spawn(async move { let mut buf = vec![0; 4096]; loop { if let Ok(l) = sock_rec.recv(&mut buf).await { - sr_ltx.send("Read from socket".as_bytes().to_vec()); + info!("Read from socket"); let mut s_cipher = cipher_shared_clone.lock().await; match buf.first() { Some(h) => { @@ -92,17 +87,17 @@ pub async fn client_mode(client_config: ClientConfiguration, fd: i32, /*env: &JN let nonce = Nonce::clone_from_slice(&wrapped_packet.nonce); match aes.decrypt(&nonce, &wrapped_packet.data[..]) { Ok(decrypted) => { let _ = tx.send(decrypted); }, - Err(error) => { sr_ltx.send(format!("Decryption error! {:?}", error).as_bytes().to_vec()); } + Err(error) => { error!("Decryption error! {:?}", error); } } } else { - sr_ltx.send("There is no static_secret".as_bytes().to_vec()); + warn!("There is no static_secret"); } }, // payload - 2 => { sr_ltx.send("Got keepalive packet".as_bytes().to_vec()); }, - _ => { sr_ltx.send("Unexpected header value.".as_bytes().to_vec()); } + 2 => { info!("Got keepalive packet"); }, + _ => { error!("Unexpected header value."); } } }, - None => { sr_ltx.send("There is no header.".as_bytes().to_vec()); } + None => { error!("There is no header."); } } drop(s_cipher); } @@ -128,12 +123,12 @@ pub async fn client_mode(client_config: ClientConfiguration, fd: i32, /*env: &JN } rr = rx.recv() => { if let Some(bytes) = rr { - ltx.send("Write to tun.".as_bytes().to_vec()); + info!("Write to tun."); if let Err(e) = dev_writer.write_all(&bytes).await { - ltx.send(format!("Writing error: {:?}", e).as_bytes().to_vec()); + error!("Writing error: {:?}", e); } if let Err(e) = dev_writer.flush().await { - ltx.send(format!("Flushing error: {:?}", e).as_bytes().to_vec()); + error!("Flushing error: {:?}", e); } } } @@ -155,13 +150,13 @@ pub async fn client_mode(client_config: ClientConfiguration, fd: i32, /*env: &JN if let Ok(ciphered_d) = ciphered_data { let vpn_packet = UDPVpnPacket{ data: ciphered_d, nonce: nonce.to_vec()}; let serialized_data = vpn_packet.serialize(); - ltx.send("Write to socket".as_bytes().to_vec()); + info!("Write to socket"); sock_snd.send(&serialized_data).await.unwrap(); } else { - ltx.send("Socket encryption failed.".as_bytes().to_vec()); + error!("Socket encryption failed."); } } else { - ltx.send("There is no shared_secret in main loop".as_bytes().to_vec()); + error!("There is no shared_secret in main loop"); } } }