5 Commits

Author SHA1 Message Date
PoliEcho 934a053713 bug fixes 2025-08-03 20:23:23 +02:00
PoliEcho a955710350 some more heartbeat modifications 2025-08-03 18:34:31 +02:00
PoliEcho 23dea395d3 Merge branch 'master' of https://git.pupes.org/PoliEcho/pea_2_pea 2025-08-03 15:51:16 +02:00
PoliEcho 8f2c66c195 Update README.md 2025-08-03 13:41:37 +00:00
PoliEcho 6898f946fa Update README.md 2025-08-03 13:38:18 +00:00
6 changed files with 47 additions and 6 deletions
+2
View File
@@ -46,6 +46,8 @@ ar = "/usr/bin/x86_64-w64-mingw32-ar"
linker = "/usr/bin/i686-w64-mingw32-gcc"
ar = "/usr/bin/i686-w64-mingw32-ar"
[target.aarch64-unknown-linux-gnu]
linker = "aarch64-linux-gnu-gcc"
[features]
no-timeout = []
+5 -1
View File
@@ -1,9 +1,13 @@
# Pea 2 Pea
very simple P2P VPN(Virtual Network yes, Private maybe),
this program is intended to help you play LAN games over internet
this program is intended to help you play LAN games over internet and as proof of concept
when all clients are behind Full-cone NAT, does not work with clients behind Symmetric NAT
at least for now
> [!WARNING]
> Piercing NAT may fail based on network configuration
## how to run
> install rustc and cargo or rustup, you will need 2024 edition
> build using
+11
View File
@@ -186,6 +186,17 @@ fn main() -> std::io::Result<()> {
&iv,
)
.unwrap();
let _ = net::send_heartbeat(
// send heart beat to start periodic heart beat
&mut buf,
&server_SocketAddr,
socket.clone(),
&tmp_v_net,
&public_sock_addr,
&iv,
);
tmp_v_net
}
Err(e) => {
+4
View File
@@ -727,6 +727,9 @@ pub async fn handle_incoming_connection(
"[SUCCESS]".green()
);
}
x if x == ServerMethods::HEARTBEAT as u8 => {
println!("{} heart beat recive confirmed", "[OK]".green());
}
_ => {
eprintln!(
"{} unknown method ID: 0x{:02x}, Droping!",
@@ -738,6 +741,7 @@ pub async fn handle_incoming_connection(
}
pub fn periodic_heart_beat(socket: Arc<UdpSocket>, send_buf: Box<[u8]>, dst: SocketAddr) {
println!("{} periodic heartbeat started", "[LOG]".blue());
loop {
std::thread::sleep(std::time::Duration::from_secs(30));
println!("{} sending heartbeat to server", "[LOG]".blue());
+1 -1
View File
@@ -4,7 +4,7 @@ pub const SERVER_PORT: u16 = 3543;
pub const UDP_BUFFER_SIZE: usize = 65527;
pub const IP_BUFFER_SIZE: usize = 65535;
pub const DEFAULT_TIMEOUT: u64 = 30;
pub const VERSION: &str = "v1.1";
pub const VERSION: &str = "v1.1.1";
pub const BLOCK_SIZE: usize = 16;
pub const STANDARD_RETRY_MAX: usize = 10;
+24 -4
View File
@@ -64,7 +64,7 @@ pub async fn handle_request(
let registration = match registration_vector
.iter()
.find(|elem| elem.map(|s| &s.net_id == &net_id)) // find if id exists
.find(|elem| elem.map(|s| &s.net_id == &net_id && !s.invalid)) // find if id exists
{
Some(registration) => registration,
None => {futures::executor::block_on(send_with_count(socket, &src ,&[ServerResponse::ID_DOESNT_EXIST as u8]));
@@ -163,7 +163,7 @@ pub async fn handle_request(
match registration_vector
.iter()
.find(|elem| elem.map(|s| &s.net_id == &net_id)) // find if id exists
.find(|elem| elem.map(|s| &s.net_id == &net_id && !s.invalid)) // find if id exists
{
Some(_) => {
futures::executor::block_on(send_with_count(socket, &src, &[ServerResponse::ID_EXISTS as u8]));
@@ -216,7 +216,25 @@ pub async fn handle_request(
.collect::<String>(),
);
registration_vector.push(types::Registration::new(
let mut first_invalid_registration: Option<usize> = None;
for (i, reg) in registration_vector.iter().enumerate() {
if reg.map(|r| r.invalid) {
first_invalid_registration = Some(i);
break;
}
}
match first_invalid_registration {
Some(i) => registration_vector[i].update(|r|{*r = types::Registration::new(
net_id.clone(),
client_sock_addr.clone(),
encrypted,
chrono::Utc::now().timestamp(),
salt,
iv,
src
);}),
None => {registration_vector.push(types::Registration::new(
net_id,
client_sock_addr,
encrypted,
@@ -224,7 +242,9 @@ pub async fn handle_request(
salt,
iv,
src
));
));},
};
send_with_count(socket, &src, &[ServerMethods::REGISTER as u8]).await;
#[cfg(debug_assertions)]
println!("network registered");