Changes to be committed:
modified: src/client.rs modified: src/server.rs
This commit is contained in:
parent
fb4276b54b
commit
f173bbdc12
@ -11,7 +11,7 @@ use std::collections::HashMap;
|
||||
use std::process::Command;
|
||||
use tokio::io::AsyncReadExt;
|
||||
|
||||
use crate::{UDPVpnPacket, VpnPacket};
|
||||
use crate::{UDPVpnHandshake, UDPVpnPacket, VpnPacket};
|
||||
|
||||
fn configure_routes() {
|
||||
let ip_output = Command::new("ip")
|
||||
@ -90,6 +90,7 @@ pub async fn client_mode(remote_addr: String) {
|
||||
|
||||
tokio::spawn(async move {
|
||||
while let Ok(bytes) = rx.recv() {
|
||||
info!("Write to tun");
|
||||
dev_writer.write_all(&bytes).unwrap();
|
||||
}
|
||||
});
|
||||
@ -110,11 +111,14 @@ pub async fn client_mode(remote_addr: String) {
|
||||
}
|
||||
});
|
||||
|
||||
let handshake = UDPVpnHandshake{};
|
||||
sock_snd.send(&handshake.serialize()).await.unwrap();
|
||||
|
||||
loop {
|
||||
if let Ok(bytes) = mx.recv() {
|
||||
let vpn_packet = UDPVpnPacket{ data: bytes };
|
||||
let serialized_data = vpn_packet.serialize();
|
||||
//info!("Writing to sock: {:?}", serialized_data);
|
||||
info!("Writing to sock: {:?}", serialized_data);
|
||||
sock_snd.send(&serialized_data).await.unwrap();
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,8 @@ pub async fn server_mode(bind_addr: String) {
|
||||
let ip = IpAddr::V4(Ipv4Addr::new(buf[16], buf[17], buf[18], buf[19]));
|
||||
let mp = addrs_cl.lock().await;
|
||||
if let Some(peer) = mp.get(&ip) {
|
||||
sock_snd.send_to(&buf[..n], peer.addr);
|
||||
info!("Sent to client");
|
||||
sock_snd.send_to(&buf[..n], peer.addr).await;
|
||||
} else {
|
||||
mp.values().for_each(| peer | { sock_snd.send_to(&buf[..n], peer.addr); });
|
||||
error!("UDPeer not found {:?}; what we have {:?}", ip, mp.keys().collect::<Vec<&IpAddr>>());
|
||||
@ -76,6 +77,7 @@ pub async fn server_mode(bind_addr: String) {
|
||||
0 => {
|
||||
// (&buf[1..len]).to_vec()
|
||||
let internal_ip = IpAddr::V4(Ipv4Addr::new(10,8,0,2));
|
||||
info!("Got handshake");
|
||||
mp.insert(internal_ip, UDPeer { addr });
|
||||
}, // handshake
|
||||
1 => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user