Compare commits
4 Commits
8f2c66c195
...
v1.1.1
| Author | SHA1 | Date | |
|---|---|---|---|
| 934a053713 | |||
| a955710350 | |||
| 23dea395d3 | |||
| 6ede42a096 |
@@ -46,6 +46,8 @@ ar = "/usr/bin/x86_64-w64-mingw32-ar"
|
|||||||
linker = "/usr/bin/i686-w64-mingw32-gcc"
|
linker = "/usr/bin/i686-w64-mingw32-gcc"
|
||||||
ar = "/usr/bin/i686-w64-mingw32-ar"
|
ar = "/usr/bin/i686-w64-mingw32-ar"
|
||||||
|
|
||||||
|
[target.aarch64-unknown-linux-gnu]
|
||||||
|
linker = "aarch64-linux-gnu-gcc"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
no-timeout = []
|
no-timeout = []
|
||||||
|
|||||||
+30
-7
@@ -21,7 +21,8 @@ use crate::types::Network;
|
|||||||
struct Cli {
|
struct Cli {
|
||||||
#[arg(short = 'r', long = "registrar")]
|
#[arg(short = 'r', long = "registrar")]
|
||||||
#[arg(help = "registrar ip address or hostname")]
|
#[arg(help = "registrar ip address or hostname")]
|
||||||
registrar: String,
|
#[arg(required_unless_present = "version")]
|
||||||
|
registrar: Option<String>,
|
||||||
|
|
||||||
#[arg(short = 'p', long = "registrar-port")]
|
#[arg(short = 'p', long = "registrar-port")]
|
||||||
#[arg(help = format!("optional Port number for the registrar service (1-65535) Default: {}", SERVER_PORT))]
|
#[arg(help = format!("optional Port number for the registrar service (1-65535) Default: {}", SERVER_PORT))]
|
||||||
@@ -29,7 +30,8 @@ struct Cli {
|
|||||||
|
|
||||||
#[arg(short = 'n', long = "network-id")]
|
#[arg(short = 'n', long = "network-id")]
|
||||||
#[arg(help = "your virtual network id that allows other people to connect to you")]
|
#[arg(help = "your virtual network id that allows other people to connect to you")]
|
||||||
network_id: String,
|
#[arg(required_unless_present = "version")]
|
||||||
|
network_id: Option<String>,
|
||||||
|
|
||||||
#[arg(short = 'P', long = "password")]
|
#[arg(short = 'P', long = "password")]
|
||||||
#[arg(
|
#[arg(
|
||||||
@@ -52,9 +54,19 @@ struct Cli {
|
|||||||
symmetric_nat_bypass_mode: bool,
|
symmetric_nat_bypass_mode: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn print_version() {
|
||||||
|
println!("Pea 2 Pea {}", VERSION);
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> std::io::Result<()> {
|
fn main() -> std::io::Result<()> {
|
||||||
let cli = <Cli as clap::Parser>::parse();
|
let cli = <Cli as clap::Parser>::parse();
|
||||||
if cli.network_id.len() > 0xff {
|
if cli.version {
|
||||||
|
print_version();
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
let network_id = cli.network_id.unwrap();
|
||||||
|
let registrar = cli.registrar.unwrap();
|
||||||
|
if network_id.len() > 0xff {
|
||||||
eprintln!("network id cannot have more then 255 charactes");
|
eprintln!("network id cannot have more then 255 charactes");
|
||||||
exit(7); // posix for E2BIG
|
exit(7); // posix for E2BIG
|
||||||
}
|
}
|
||||||
@@ -81,11 +93,11 @@ fn main() -> std::io::Result<()> {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
#[allow(non_snake_case)] // i think this is valid snake case but rustc doesnt think so
|
#[allow(non_snake_case)] // i think this is valid snake case but rustc doesnt think so
|
||||||
let server_SocketAddr: core::net::SocketAddr = format!("{}:{}", cli.registrar, server_port)
|
let server_SocketAddr: core::net::SocketAddr = format!("{}:{}", registrar, server_port)
|
||||||
.parse()
|
.parse()
|
||||||
.expect(&format!(
|
.expect(&format!(
|
||||||
"{}:{} is invalid sock addr",
|
"{}:{} is invalid sock addr",
|
||||||
cli.registrar, server_port
|
registrar, server_port
|
||||||
));
|
));
|
||||||
|
|
||||||
// query here
|
// query here
|
||||||
@@ -134,7 +146,7 @@ fn main() -> std::io::Result<()> {
|
|||||||
&mut buf,
|
&mut buf,
|
||||||
&server_SocketAddr,
|
&server_SocketAddr,
|
||||||
&socket,
|
&socket,
|
||||||
&cli.network_id,
|
&network_id,
|
||||||
&cli.password,
|
&cli.password,
|
||||||
) {
|
) {
|
||||||
Ok(n) => {
|
Ok(n) => {
|
||||||
@@ -161,7 +173,7 @@ fn main() -> std::io::Result<()> {
|
|||||||
None => false,
|
None => false,
|
||||||
},
|
},
|
||||||
encryption_key,
|
encryption_key,
|
||||||
cli.network_id,
|
network_id,
|
||||||
salt,
|
salt,
|
||||||
Vec::with_capacity(1),
|
Vec::with_capacity(1),
|
||||||
);
|
);
|
||||||
@@ -174,6 +186,17 @@ fn main() -> std::io::Result<()> {
|
|||||||
&iv,
|
&iv,
|
||||||
)
|
)
|
||||||
.unwrap();
|
.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
|
tmp_v_net
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|||||||
@@ -727,6 +727,9 @@ pub async fn handle_incoming_connection(
|
|||||||
"[SUCCESS]".green()
|
"[SUCCESS]".green()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
x if x == ServerMethods::HEARTBEAT as u8 => {
|
||||||
|
println!("{} heart beat recive confirmed", "[OK]".green());
|
||||||
|
}
|
||||||
_ => {
|
_ => {
|
||||||
eprintln!(
|
eprintln!(
|
||||||
"{} unknown method ID: 0x{:02x}, Droping!",
|
"{} 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) {
|
pub fn periodic_heart_beat(socket: Arc<UdpSocket>, send_buf: Box<[u8]>, dst: SocketAddr) {
|
||||||
|
println!("{} periodic heartbeat started", "[LOG]".blue());
|
||||||
loop {
|
loop {
|
||||||
std::thread::sleep(std::time::Duration::from_secs(30));
|
std::thread::sleep(std::time::Duration::from_secs(30));
|
||||||
println!("{} sending heartbeat to server", "[LOG]".blue());
|
println!("{} sending heartbeat to server", "[LOG]".blue());
|
||||||
|
|||||||
+1
-1
@@ -4,7 +4,7 @@ pub const SERVER_PORT: u16 = 3543;
|
|||||||
pub const UDP_BUFFER_SIZE: usize = 65527;
|
pub const UDP_BUFFER_SIZE: usize = 65527;
|
||||||
pub const IP_BUFFER_SIZE: usize = 65535;
|
pub const IP_BUFFER_SIZE: usize = 65535;
|
||||||
pub const DEFAULT_TIMEOUT: u64 = 30;
|
pub const DEFAULT_TIMEOUT: u64 = 30;
|
||||||
pub const VERSION: &str = "v1.0";
|
pub const VERSION: &str = "v1.1.1";
|
||||||
pub const BLOCK_SIZE: usize = 16;
|
pub const BLOCK_SIZE: usize = 16;
|
||||||
pub const STANDARD_RETRY_MAX: usize = 10;
|
pub const STANDARD_RETRY_MAX: usize = 10;
|
||||||
|
|
||||||
|
|||||||
+24
-4
@@ -64,7 +64,7 @@ pub async fn handle_request(
|
|||||||
|
|
||||||
let registration = match registration_vector
|
let registration = match registration_vector
|
||||||
.iter()
|
.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,
|
Some(registration) => registration,
|
||||||
None => {futures::executor::block_on(send_with_count(socket, &src ,&[ServerResponse::ID_DOESNT_EXIST as u8]));
|
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
|
match registration_vector
|
||||||
.iter()
|
.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(_) => {
|
Some(_) => {
|
||||||
futures::executor::block_on(send_with_count(socket, &src, &[ServerResponse::ID_EXISTS as u8]));
|
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>(),
|
.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,
|
net_id,
|
||||||
client_sock_addr,
|
client_sock_addr,
|
||||||
encrypted,
|
encrypted,
|
||||||
@@ -224,7 +242,9 @@ pub async fn handle_request(
|
|||||||
salt,
|
salt,
|
||||||
iv,
|
iv,
|
||||||
src
|
src
|
||||||
));
|
));},
|
||||||
|
};
|
||||||
|
|
||||||
send_with_count(socket, &src, &[ServerMethods::REGISTER as u8]).await;
|
send_with_count(socket, &src, &[ServerMethods::REGISTER as u8]).await;
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
println!("network registered");
|
println!("network registered");
|
||||||
|
|||||||
Reference in New Issue
Block a user