add debuging of packets
This commit is contained in:
parent
20a4907ea0
commit
6aa9fb27e6
@ -8,6 +8,7 @@ use super::types;
|
|||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
use pea_2_pea::{shared::net::send_and_recv_with_retry, *};
|
use pea_2_pea::{shared::net::send_and_recv_with_retry, *};
|
||||||
use rand::{RngCore, rng};
|
use rand::{RngCore, rng};
|
||||||
|
use sha2::Digest;
|
||||||
|
|
||||||
pub fn query_request(
|
pub fn query_request(
|
||||||
buf: &mut [u8; UDP_BUFFER_SIZE],
|
buf: &mut [u8; UDP_BUFFER_SIZE],
|
||||||
@ -434,14 +435,28 @@ pub async fn handle_incoming_connection(
|
|||||||
..P2PStandardDataPositions::IV as usize + BLOCK_SIZE],
|
..P2PStandardDataPositions::IV as usize + BLOCK_SIZE],
|
||||||
&buf[P2PStandardDataPositions::DATA as usize..data_lenght as usize],
|
&buf[P2PStandardDataPositions::DATA as usize..data_lenght as usize],
|
||||||
) {
|
) {
|
||||||
Ok(data) => match tun_iface.send(&data) {
|
Ok(data) => {
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
eprintln!(
|
||||||
|
"packet contets: {}\nhash: {:x}",
|
||||||
|
data.iter()
|
||||||
|
.map(|x| format!("{:02X} ", x))
|
||||||
|
.collect::<String>(),
|
||||||
|
{
|
||||||
|
let mut hasher = sha2::Sha256::new();
|
||||||
|
hasher.update(&data);
|
||||||
|
hasher.finalize()
|
||||||
|
}
|
||||||
|
);
|
||||||
|
match tun_iface.send(&data) {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(e) => eprintln!(
|
Err(e) => eprintln!(
|
||||||
"{} failed to write packet to tun interface, Error: {}",
|
"{} failed to write packet to tun interface, Error: {}",
|
||||||
"[WARNING]".yellow(),
|
"[WARNING]".yellow(),
|
||||||
e
|
e
|
||||||
),
|
),
|
||||||
},
|
}
|
||||||
|
}
|
||||||
Err(e) => eprintln!(
|
Err(e) => eprintln!(
|
||||||
"{} failed to decrypt packet, Error: {}",
|
"{} failed to decrypt packet, Error: {}",
|
||||||
"[WARNING]".yellow(),
|
"[WARNING]".yellow(),
|
||||||
@ -449,9 +464,15 @@ pub async fn handle_incoming_connection(
|
|||||||
),
|
),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
match tun_iface.send(&buf[P2PStandardDataPositions::DATA as usize..data_lenght as usize]) {
|
match tun_iface
|
||||||
Ok(_) => {},
|
.send(&buf[P2PStandardDataPositions::DATA as usize..data_lenght as usize])
|
||||||
Err(e) => eprintln!("{} failed to write packet to tun interface, Error: {}", "[WARNING]".yellow(), e),
|
{
|
||||||
|
Ok(_) => {}
|
||||||
|
Err(e) => eprintln!(
|
||||||
|
"{} failed to write packet to tun interface, Error: {}",
|
||||||
|
"[WARNING]".yellow(),
|
||||||
|
e
|
||||||
|
),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ use std::sync::{Arc, RwLock};
|
|||||||
use pea_2_pea::*;
|
use pea_2_pea::*;
|
||||||
use rand::RngCore;
|
use rand::RngCore;
|
||||||
use rayon::prelude::*;
|
use rayon::prelude::*;
|
||||||
|
use sha2::Digest;
|
||||||
|
|
||||||
use crate::types::Network;
|
use crate::types::Network;
|
||||||
|
|
||||||
@ -31,9 +32,9 @@ pub fn read_tun_iface(
|
|||||||
let mut buf: [u8; IP_BUFFER_SIZE] = [0u8; IP_BUFFER_SIZE];
|
let mut buf: [u8; IP_BUFFER_SIZE] = [0u8; IP_BUFFER_SIZE];
|
||||||
|
|
||||||
smol::block_on(async {
|
smol::block_on(async {
|
||||||
loop {
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
eprintln!("Started listening for ip packets");
|
eprintln!("Started listening for ip packets");
|
||||||
|
loop {
|
||||||
let data_lenght = tun_iface.recv(&mut buf).unwrap(); // build in auto termination, isn't it great
|
let data_lenght = tun_iface.recv(&mut buf).unwrap(); // build in auto termination, isn't it great
|
||||||
smol::spawn(handle_ip_packet(
|
smol::spawn(handle_ip_packet(
|
||||||
buf[..data_lenght - 1].to_vec().into(),
|
buf[..data_lenght - 1].to_vec().into(),
|
||||||
@ -41,8 +42,8 @@ pub fn read_tun_iface(
|
|||||||
socket.clone(),
|
socket.clone(),
|
||||||
))
|
))
|
||||||
.detach();
|
.detach();
|
||||||
}});
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn handle_ip_packet(
|
pub async fn handle_ip_packet(
|
||||||
@ -52,6 +53,21 @@ pub async fn handle_ip_packet(
|
|||||||
) {
|
) {
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
eprintln!("Processing IP packet");
|
eprintln!("Processing IP packet");
|
||||||
|
|
||||||
|
#[cfg(debug_assertions)]
|
||||||
|
eprintln!(
|
||||||
|
"packet contets: {}\nhash: {:x}",
|
||||||
|
packet_data
|
||||||
|
.iter()
|
||||||
|
.map(|x| format!("{:02X} ", x))
|
||||||
|
.collect::<String>(),
|
||||||
|
{
|
||||||
|
let mut hasher = sha2::Sha256::new();
|
||||||
|
hasher.update(&packet_data);
|
||||||
|
hasher.finalize()
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
let dst_ip = std::net::Ipv4Addr::from(
|
let dst_ip = std::net::Ipv4Addr::from(
|
||||||
match <[u8; 4]>::try_from(
|
match <[u8; 4]>::try_from(
|
||||||
&packet_data[DEST_IN_IPV4_OFFSET..DEST_IN_IPV4_OFFSET + IPV4_SIZE],
|
&packet_data[DEST_IN_IPV4_OFFSET..DEST_IN_IPV4_OFFSET + IPV4_SIZE],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user