fix do nothing packets chaos
This commit is contained in:
parent
d5a5dc33a9
commit
bcff895858
@ -287,7 +287,7 @@ fn main() -> std::io::Result<()> {
|
||||
socket.clone(),
|
||||
data_lenght,
|
||||
))
|
||||
.detach();
|
||||
.await;
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!(
|
||||
|
@ -413,7 +413,7 @@ pub fn P2P_hello(
|
||||
}
|
||||
|
||||
pub async fn handle_incoming_connection(
|
||||
mut buf: [u8; UDP_BUFFER_SIZE],
|
||||
buf: [u8; UDP_BUFFER_SIZE],
|
||||
src: SocketAddr,
|
||||
network: Arc<RwLock<types::Network>>,
|
||||
tun_iface: Arc<tappers::Tun>,
|
||||
@ -425,7 +425,7 @@ pub async fn handle_incoming_connection(
|
||||
match buf[0] {
|
||||
x if x == P2PMethods::PACKET as u8 => {
|
||||
#[cfg(debug_assertions)]
|
||||
println!("PACKET from difernt peer receved");
|
||||
println!("PACKET from different peer receved");
|
||||
|
||||
if network.read().unwrap().encrypted {
|
||||
match shared::crypto::decrypt(
|
||||
@ -511,6 +511,11 @@ pub async fn handle_incoming_connection(
|
||||
x if x == P2PMethods::PEER_HELLO as u8 => {
|
||||
println!("{} peer hello receved from: {}", "[LOG]".blue(), src);
|
||||
|
||||
if data_lenght - 1 < P2PStandardDataPositions::DATA as usize {
|
||||
eprintln!("{} peer hello packet too small", "[ERROR]".red());
|
||||
return;
|
||||
}
|
||||
|
||||
let tmp_data: Vec<u8>;
|
||||
{
|
||||
let mut network_write_lock = network.write().unwrap();
|
||||
@ -677,7 +682,7 @@ pub async fn handle_incoming_connection(
|
||||
}
|
||||
};
|
||||
for _ in 0..MAPPING_SHOT_COUNT {
|
||||
match socket.send_to(&[P2PMethods::PEER_QUERY as u8], peer_addr) {
|
||||
match socket.send_to(&[P2PMethods::DO_NOTHING as u8], peer_addr) {
|
||||
Ok(s) => {
|
||||
#[cfg(debug_assertions)]
|
||||
eprintln!("send {} bytes", s);
|
||||
@ -686,6 +691,12 @@ pub async fn handle_incoming_connection(
|
||||
}
|
||||
}
|
||||
}
|
||||
x if x == P2PMethods::DO_NOTHING as u8 => {
|
||||
println!(
|
||||
"{} punching succesful DO_NOTHING receved",
|
||||
"[SUCCESS]".green()
|
||||
);
|
||||
}
|
||||
_ => {
|
||||
eprintln!(
|
||||
"{} unknown method ID: 0x{:02x}, Droping!",
|
||||
|
@ -122,6 +122,7 @@ pub enum P2PMethods {
|
||||
PEER_GOODBYE = 22, // sends private ip encrypted if on
|
||||
PACKET = 23, // sends IP packet encrypted if on
|
||||
NEW_CLIENT_NOTIFY = 24,
|
||||
DO_NOTHING = 25,
|
||||
}
|
||||
#[repr(usize)]
|
||||
pub enum P2PStandardDataPositions {
|
||||
|
@ -37,15 +37,7 @@ pub async fn handle_request(
|
||||
let mut send_vec: Vec<u8> = client_sock_addr_str.into();
|
||||
send_vec.insert(0, ServerMethods::QUERY as u8);
|
||||
|
||||
match socket.send_to(&send_vec, &src).await {
|
||||
Ok(s) => {
|
||||
#[cfg(debug_assertions)]
|
||||
eprintln!("send {} bytes", s);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Error snding data: {}", e);
|
||||
}
|
||||
}
|
||||
send_with_count(socket, &src, &send_vec).await;
|
||||
}
|
||||
|
||||
x if x == ServerMethods::GET as u8 => {
|
||||
@ -135,15 +127,7 @@ pub async fn handle_request(
|
||||
return;
|
||||
}
|
||||
|
||||
match socket.send_to(&send_vec, &src).await {
|
||||
Ok(s) => {
|
||||
#[cfg(debug_assertions)]
|
||||
eprintln!("send {} bytes", s);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Error snding data: {}", e);
|
||||
}
|
||||
}
|
||||
send_with_count(socket, &src, &send_vec).await;
|
||||
}
|
||||
x if x == ServerMethods::REGISTER as u8 => {
|
||||
#[cfg(debug_assertions)]
|
||||
@ -241,15 +225,7 @@ pub async fn handle_request(
|
||||
iv,
|
||||
src
|
||||
));
|
||||
match socket.send_to(&[ServerMethods::REGISTER as u8], src).await {
|
||||
Ok(s) => {
|
||||
#[cfg(debug_assertions)]
|
||||
eprintln!("send {} bytes", s);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Error sending data: {}", e);
|
||||
}
|
||||
}
|
||||
send_with_count(socket, &src, &[ServerMethods::REGISTER as u8]).await;
|
||||
#[cfg(debug_assertions)]
|
||||
println!("network registered");
|
||||
}
|
||||
@ -341,16 +317,7 @@ pub async fn handle_request(
|
||||
}
|
||||
None => {futures::executor::block_on(send_with_count(socket, &src, &[ServerResponse::ID_DOESNT_EXIST as u8])); return;}
|
||||
}
|
||||
match socket.send_to(&[ServerMethods::HEARTBEAT as u8], src).await {
|
||||
// succes responce
|
||||
Ok(s) => {
|
||||
#[cfg(debug_assertions)]
|
||||
eprintln!("send {} bytes", s);
|
||||
}
|
||||
Err(e) => {
|
||||
eprintln!("Error sending data: {}", e);
|
||||
}
|
||||
}
|
||||
send_with_count(socket, &src, &[ServerMethods::HEARTBEAT as u8]).await;
|
||||
return;
|
||||
}
|
||||
_ => {
|
||||
|
@ -127,8 +127,10 @@ pub fn send_and_recv_with_retry(
|
||||
|
||||
let mut retry_count: usize = 0;
|
||||
|
||||
let mut resend: bool = true;
|
||||
|
||||
loop {
|
||||
match socket.send_to(send_buf, dst) {
|
||||
if resend {match socket.send_to(send_buf, dst) {
|
||||
Ok(s) => {
|
||||
#[cfg(debug_assertions)]
|
||||
eprintln!("send {} bytes", s);
|
||||
@ -145,8 +147,8 @@ pub fn send_and_recv_with_retry(
|
||||
}
|
||||
_ => return Err(ServerErrorResponses::IO(e)),
|
||||
},
|
||||
}
|
||||
|
||||
}} else {resend = true;}
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
if let Err(icmp_error) = check_icmp_error_queue(socket) {
|
||||
return Err(ServerErrorResponses::IO(icmp_error));
|
||||
@ -176,6 +178,10 @@ pub fn send_and_recv_with_retry(
|
||||
x if x == ServerResponse::ID_EXISTS as u8 => {
|
||||
return Err(ServerErrorResponses::ID_EXISTS);
|
||||
}
|
||||
x if x == P2PMethods::DO_NOTHING as u8 => {
|
||||
resend = false;
|
||||
continue;
|
||||
}
|
||||
_ => {
|
||||
continue;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user