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(),
|
socket.clone(),
|
||||||
data_lenght,
|
data_lenght,
|
||||||
))
|
))
|
||||||
.detach();
|
.await;
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
|
|||||||
@ -413,7 +413,7 @@ pub fn P2P_hello(
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn handle_incoming_connection(
|
pub async fn handle_incoming_connection(
|
||||||
mut buf: [u8; UDP_BUFFER_SIZE],
|
buf: [u8; UDP_BUFFER_SIZE],
|
||||||
src: SocketAddr,
|
src: SocketAddr,
|
||||||
network: Arc<RwLock<types::Network>>,
|
network: Arc<RwLock<types::Network>>,
|
||||||
tun_iface: Arc<tappers::Tun>,
|
tun_iface: Arc<tappers::Tun>,
|
||||||
@ -425,7 +425,7 @@ pub async fn handle_incoming_connection(
|
|||||||
match buf[0] {
|
match buf[0] {
|
||||||
x if x == P2PMethods::PACKET as u8 => {
|
x if x == P2PMethods::PACKET as u8 => {
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
println!("PACKET from difernt peer receved");
|
println!("PACKET from different peer receved");
|
||||||
|
|
||||||
if network.read().unwrap().encrypted {
|
if network.read().unwrap().encrypted {
|
||||||
match shared::crypto::decrypt(
|
match shared::crypto::decrypt(
|
||||||
@ -511,6 +511,11 @@ pub async fn handle_incoming_connection(
|
|||||||
x if x == P2PMethods::PEER_HELLO as u8 => {
|
x if x == P2PMethods::PEER_HELLO as u8 => {
|
||||||
println!("{} peer hello receved from: {}", "[LOG]".blue(), src);
|
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 tmp_data: Vec<u8>;
|
||||||
{
|
{
|
||||||
let mut network_write_lock = network.write().unwrap();
|
let mut network_write_lock = network.write().unwrap();
|
||||||
@ -677,7 +682,7 @@ pub async fn handle_incoming_connection(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
for _ in 0..MAPPING_SHOT_COUNT {
|
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) => {
|
Ok(s) => {
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
eprintln!("send {} bytes", s);
|
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!(
|
eprintln!(
|
||||||
"{} unknown method ID: 0x{:02x}, Droping!",
|
"{} unknown method ID: 0x{:02x}, Droping!",
|
||||||
|
|||||||
@ -122,6 +122,7 @@ pub enum P2PMethods {
|
|||||||
PEER_GOODBYE = 22, // sends private ip encrypted if on
|
PEER_GOODBYE = 22, // sends private ip encrypted if on
|
||||||
PACKET = 23, // sends IP packet encrypted if on
|
PACKET = 23, // sends IP packet encrypted if on
|
||||||
NEW_CLIENT_NOTIFY = 24,
|
NEW_CLIENT_NOTIFY = 24,
|
||||||
|
DO_NOTHING = 25,
|
||||||
}
|
}
|
||||||
#[repr(usize)]
|
#[repr(usize)]
|
||||||
pub enum P2PStandardDataPositions {
|
pub enum P2PStandardDataPositions {
|
||||||
|
|||||||
@ -37,15 +37,7 @@ pub async fn handle_request(
|
|||||||
let mut send_vec: Vec<u8> = client_sock_addr_str.into();
|
let mut send_vec: Vec<u8> = client_sock_addr_str.into();
|
||||||
send_vec.insert(0, ServerMethods::QUERY as u8);
|
send_vec.insert(0, ServerMethods::QUERY as u8);
|
||||||
|
|
||||||
match socket.send_to(&send_vec, &src).await {
|
send_with_count(socket, &src, &send_vec).await;
|
||||||
Ok(s) => {
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
eprintln!("send {} bytes", s);
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
eprintln!("Error snding data: {}", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
x if x == ServerMethods::GET as u8 => {
|
x if x == ServerMethods::GET as u8 => {
|
||||||
@ -135,15 +127,7 @@ pub async fn handle_request(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
match socket.send_to(&send_vec, &src).await {
|
send_with_count(socket, &src, &send_vec).await;
|
||||||
Ok(s) => {
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
eprintln!("send {} bytes", s);
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
eprintln!("Error snding data: {}", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
x if x == ServerMethods::REGISTER as u8 => {
|
x if x == ServerMethods::REGISTER as u8 => {
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
@ -241,15 +225,7 @@ pub async fn handle_request(
|
|||||||
iv,
|
iv,
|
||||||
src
|
src
|
||||||
));
|
));
|
||||||
match socket.send_to(&[ServerMethods::REGISTER as u8], src).await {
|
send_with_count(socket, &src, &[ServerMethods::REGISTER as u8]).await;
|
||||||
Ok(s) => {
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
eprintln!("send {} bytes", s);
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
eprintln!("Error sending data: {}", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
println!("network registered");
|
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;}
|
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 {
|
send_with_count(socket, &src, &[ServerMethods::HEARTBEAT as u8]).await;
|
||||||
// succes responce
|
|
||||||
Ok(s) => {
|
|
||||||
#[cfg(debug_assertions)]
|
|
||||||
eprintln!("send {} bytes", s);
|
|
||||||
}
|
|
||||||
Err(e) => {
|
|
||||||
eprintln!("Error sending data: {}", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
|
|||||||
@ -127,8 +127,10 @@ pub fn send_and_recv_with_retry(
|
|||||||
|
|
||||||
let mut retry_count: usize = 0;
|
let mut retry_count: usize = 0;
|
||||||
|
|
||||||
|
let mut resend: bool = true;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
match socket.send_to(send_buf, dst) {
|
if resend {match socket.send_to(send_buf, dst) {
|
||||||
Ok(s) => {
|
Ok(s) => {
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
eprintln!("send {} bytes", s);
|
eprintln!("send {} bytes", s);
|
||||||
@ -145,8 +147,8 @@ pub fn send_and_recv_with_retry(
|
|||||||
}
|
}
|
||||||
_ => return Err(ServerErrorResponses::IO(e)),
|
_ => return Err(ServerErrorResponses::IO(e)),
|
||||||
},
|
},
|
||||||
}
|
}} else {resend = true;}
|
||||||
|
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
if let Err(icmp_error) = check_icmp_error_queue(socket) {
|
if let Err(icmp_error) = check_icmp_error_queue(socket) {
|
||||||
return Err(ServerErrorResponses::IO(icmp_error));
|
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 => {
|
x if x == ServerResponse::ID_EXISTS as u8 => {
|
||||||
return Err(ServerErrorResponses::ID_EXISTS);
|
return Err(ServerErrorResponses::ID_EXISTS);
|
||||||
}
|
}
|
||||||
|
x if x == P2PMethods::DO_NOTHING as u8 => {
|
||||||
|
resend = false;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user