Changes to be committed:

modified:   src/main.rs
	modified:   src/tcp_client.rs
	modified:   src/tcp_server.rs
This commit is contained in:
Michael Wain 2024-08-12 18:47:33 +03:00
parent 4b42c23b24
commit fa32e776f2
3 changed files with 10 additions and 9 deletions

View File

@ -18,14 +18,15 @@ const TAIL: [u8;3] = [0x76, 0x66, 0x56];
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
struct VpnPacket { struct VpnPacket {
start: Vec<u8>, //start: Vec<u8>,
data: Vec<u8>, data: Vec<u8>,
end: Vec<u8> //end: Vec<u8>
} }
impl VpnPacket { impl VpnPacket {
fn init(d: Vec<u8>) -> Self { fn init(d: Vec<u8>) -> Self {
VpnPacket{start: (&HEADER).to_vec(), data: d, end: (&TAIL).to_vec()} //VpnPacket{start: (&HEADER).to_vec(), data: d, end: (&TAIL).to_vec()}
VpnPacket { data: d }
} }
} }

View File

@ -92,19 +92,19 @@ pub async fn client_mode(remote_addr: String) {
}); });
tokio::spawn(async move { tokio::spawn(async move {
let mut buf = vec![0; 1024]; let mut buf = vec![0; 4096];
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();
} }
}); });
tokio::spawn(async move { tokio::spawn(async move {
let mut buf = vec![0; 1024]; let mut buf = vec![0; 4096];
loop { loop {
if let Ok(n) = sock_reader.read(&mut buf).await { if let Ok(n) = sock_reader.read(&mut buf).await {
//info!("Catch from socket: {:?}", &buf[..n]); //info!("Catch from socket: {:?}", &buf[..n]);
let vpn_packet: VpnPacket = bincode::deserialize(&buf[..n]).unwrap(); let vpn_packet: VpnPacket = bincode::deserialize(&buf[..n]).unwrap();
if vpn_packet.start != &HEADER || vpn_packet.end != &TAIL { error!("Bad packet"); continue; } //if vpn_packet.start != &HEADER || vpn_packet.end != &TAIL { error!("Bad packet"); continue; }
tx.send(vpn_packet.data).unwrap(); tx.send(vpn_packet.data).unwrap();
} }
} }

View File

@ -38,7 +38,7 @@ pub async fn server_mode() {
}); });
tokio::spawn(async move { tokio::spawn(async move {
let mut buf = vec![0; 1024]; let mut buf = vec![0; 4096];
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();
} }
@ -64,12 +64,12 @@ pub async fn server_mode() {
}); });
tokio::spawn(async move { tokio::spawn(async move {
let mut buf = vec![0; 1024]; let mut buf = vec![0; 4096];
loop { loop {
if let Ok(n) = sock_reader.read(&mut buf).await { if let Ok(n) = sock_reader.read(&mut buf).await {
info!("Catched from sock: {:?}", &buf[..n]); info!("Catched from sock: {:?}", &buf[..n]);
let vpn_packet: VpnPacket = bincode::deserialize(&buf[..n]).unwrap(); let vpn_packet: VpnPacket = bincode::deserialize(&buf[..n]).unwrap();
if vpn_packet.start != &HEADER || vpn_packet.end != &TAIL { error!("Bad packet"); continue; } //if vpn_packet.start != &HEADER || vpn_packet.end != &TAIL { error!("Bad packet"); continue; }
thread_tx.send(vpn_packet.data).unwrap(); thread_tx.send(vpn_packet.data).unwrap();
} }
} }