Compare commits
	
		
			2 Commits
		
	
	
		
			6aa9fb27e6
			...
			4ca652cea5
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 4ca652cea5 | |||
| 4a70fb61f9 | 
| @ -37,7 +37,7 @@ pub fn read_tun_iface( | |||||||
|         loop { |         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].to_vec().into(), | ||||||
|                 network.clone(), |                 network.clone(), | ||||||
|                 socket.clone(), |                 socket.clone(), | ||||||
|             )) |             )) | ||||||
| @ -84,22 +84,25 @@ pub async fn handle_ip_packet( | |||||||
|     let mut iv: [u8; BLOCK_SIZE] = [0u8; BLOCK_SIZE]; |     let mut iv: [u8; BLOCK_SIZE] = [0u8; BLOCK_SIZE]; | ||||||
|     rng.fill_bytes(&mut iv); |     rng.fill_bytes(&mut iv); | ||||||
| 
 | 
 | ||||||
|     let mut encrypted_data = |     let mut procesed_data: Vec<u8> = if network.read().unwrap().encrypted { | ||||||
|         match shared::crypto::encrypt(&network.read().unwrap().key, &iv, &packet_data) { |         match shared::crypto::encrypt(&network.read().unwrap().key, &iv, &packet_data) { | ||||||
|             Ok(cr) => cr, |             Ok(cr) => cr, | ||||||
|             Err(e) => { |             Err(e) => { | ||||||
|                 eprintln!("Failed to encrypt packet droping it: {}", e); |                 eprintln!("Failed to encrypt packet droping it: {}", e); | ||||||
|                 return; |                 return; | ||||||
|             } |             } | ||||||
|         }; |         } | ||||||
|  |     } else { | ||||||
|  |         packet_data.to_vec() | ||||||
|  |     }; | ||||||
| 
 | 
 | ||||||
|     encrypted_data.insert(0, P2PMethods::PACKET as u8); |     procesed_data.insert(0, P2PMethods::PACKET as u8); | ||||||
|     encrypted_data.splice(1..1, iv); |     procesed_data.splice(1..1, iv); | ||||||
| 
 | 
 | ||||||
|     if dst_ip.octets()[3] == 255 { |     if dst_ip.octets()[3] == 255 { | ||||||
|         network.read().unwrap().peers.par_iter().for_each(|peer| { |         network.read().unwrap().peers.par_iter().for_each(|peer| { | ||||||
|             // broadcast
 |             // broadcast
 | ||||||
|             match socket.send_to(&encrypted_data, peer.sock_addr) { |             match socket.send_to(&procesed_data, peer.sock_addr) { | ||||||
|                 Ok(_) => {} |                 Ok(_) => {} | ||||||
|                 Err(e) => eprintln!("failed to send packet: {}", e), |                 Err(e) => eprintln!("failed to send packet: {}", e), | ||||||
|             }; |             }; | ||||||
| @ -117,7 +120,7 @@ pub async fn handle_ip_packet( | |||||||
|             None => return, |             None => return, | ||||||
|         }; |         }; | ||||||
| 
 | 
 | ||||||
|         match socket.send_to(&encrypted_data, dst) { |         match socket.send_to(&procesed_data, dst) { | ||||||
|             Ok(_) => {} |             Ok(_) => {} | ||||||
|             Err(e) => eprintln!("failed to send packet: {}", e), |             Err(e) => eprintln!("failed to send packet: {}", e), | ||||||
|         }; |         }; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user