holepuching fixes

This commit is contained in:
PoliEcho 2025-08-01 10:44:05 +02:00
parent 28dd37bdec
commit 3675650864
3 changed files with 15 additions and 21 deletions

View File

@ -620,7 +620,7 @@ pub async fn handle_incoming_connection(
);
#[cfg(debug_assertions)]
eprintln!(
eprintln!(
"registering network:\niv: {}\nsockaddr: {}",
&buf[P2PStandardDataPositions::IV as usize
..P2PStandardDataPositions::IV as usize + BLOCK_SIZE].iter().map(|x| format!("{:02X} ", x)).collect::<String>(),
@ -637,7 +637,7 @@ pub async fn handle_incoming_connection(
&network.read().unwrap().key,
&buf[P2PStandardDataPositions::IV as usize
..P2PStandardDataPositions::IV as usize + BLOCK_SIZE],
&buf[P2PStandardDataPositions::DATA as usize..data_lenght as usize /*compensate for size and index diference*/],
&buf[P2PStandardDataPositions::DATA as usize..data_lenght as usize /*compensate for size and index diference*/],
) {
Ok(v) => {
data_tmp = v.into_boxed_slice();
@ -676,22 +676,15 @@ pub async fn handle_incoming_connection(
return;
}
};
match P2P_query(
// create NAT mapping
&mut buf,
&peer_addr,
&socket,
network.read().unwrap().encrypted,
network.read().unwrap().key,
) {
Ok(_) => {}
Err(e) => eprintln!(
"{} failed to create NAT mapping to peer connection may not work Error: {}",
"[ERROR]".red(),
e
),
};
for _ in 0..MAPPING_SHOT_COUNT {
match socket.send_to(&[P2PMethods::PEER_QUERY as u8], peer_addr) {
Ok(s) => {
#[cfg(debug_assertions)]
eprintln!("send {} bytes", s);
}
Err(e) => eprintln!("{} failed to send puching packet: {}", "[ERROR]".red(), e),
}
}
}
_ => {
eprintln!(

View File

@ -11,6 +11,8 @@ pub const STANDARD_RETRY_MAX: usize = 10;
pub const DEST_IN_IPV4_OFFSET: usize = 16;
pub const IPV4_SIZE: usize = 4;
pub const MAPPING_SHOT_COUNT: u8 = 5;
pub const DEFAULT_NETWORK_PREFIX: [u8; 3] = [172, 22, 44];
#[repr(u8)]

View File

@ -333,9 +333,8 @@ pub async fn handle_request(
send_buf[0] = P2PMethods::NEW_CLIENT_NOTIFY as u8;
send_buf[P2PStandardDataPositions::IV as usize..P2PStandardDataPositions::IV as usize+ BLOCK_SIZE].copy_from_slice(&iv);
send_buf[P2PStandardDataPositions::DATA as usize..P2PStandardDataPositions::DATA as usize + sock_addr_len as usize].copy_from_slice(&sock_addr);
let mut resp_buf: [u8; UDP_BUFFER_SIZE] = [0u8; UDP_BUFFER_SIZE];
match shared::net::send_and_recv_with_retry(&mut resp_buf, &send_buf, &c.src, &socket, STANDARD_RETRY_MAX) {
Ok((data_lenght, _)) => {
match socket.send_to(&send_buf, src) {
Ok(data_lenght) => {
#[cfg(debug_assertions)]
eprintln!("send {} bytes", data_lenght);
},