diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/rendezvous_server.rs | 16 | ||||
-rw-r--r-- | src/utils.rs | 88 | ||||
-rw-r--r-- | src/version.rs | 1 |
3 files changed, 91 insertions, 14 deletions
diff --git a/src/rendezvous_server.rs b/src/rendezvous_server.rs index da69540..7a63c11 100644 --- a/src/rendezvous_server.rs +++ b/src/rendezvous_server.rs @@ -766,15 +766,11 @@ impl RendezvousServer { ) -> ResultType<()> { let mut states = BytesMut::zeroed((peers.len() + 7) / 8); for i in 0..peers.len() { - let peer_id = &peers[i]; - // bytes index from left to right - let states_idx = i / 8; - let bit_idx = 7 - i % 8; - if let Some(peer) = self.pm.get_in_memory(&peer_id).await { - let (elapsed, _) = { - let r = peer.read().await; - (r.last_reg_time.elapsed().as_millis() as i32, r.socket_addr) - }; + if let Some(peer) = self.pm.get_in_memory(&peers[i]).await { + let elapsed = peer.read().await.last_reg_time.elapsed().as_millis() as i32; + // bytes index from left to right + let states_idx = i / 8; + let bit_idx = 7 - i % 8; if elapsed < REG_TIMEOUT { states[states_idx] |= 0x01 << bit_idx; } @@ -1213,7 +1209,7 @@ async fn check_relay_servers(rs0: Arc<RelayServers>, tx: Sender) { let rs = rs.clone(); let x = x.clone(); futs.push(tokio::spawn(async move { - if FramedStream::new(&host, "0.0.0.0:0", CHECK_RELAY_TIMEOUT) + if FramedStream::new(&host, None, CHECK_RELAY_TIMEOUT) .await .is_ok() { diff --git a/src/utils.rs b/src/utils.rs index 7eb7a58..7b36aed 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,8 +1,11 @@ +use dns_lookup::{lookup_addr, lookup_host}; use hbb_common::{bail, ResultType}; use sodiumoxide::crypto::sign; -use std::env; -use std::process; -use std::str; +use std::{ + env, + net::{IpAddr, TcpStream}, + process, str, +}; fn print_help() { println!( @@ -10,7 +13,8 @@ fn print_help() { rustdesk-util [command]\n Available Commands: genkeypair Generate a new keypair - validatekeypair [public key] [secret key] Validate an existing keypair" + validatekeypair [public key] [secret key] Validate an existing keypair + doctor [rustdesk-server] Check for server connection problems" ); process::exit(0x0001); } @@ -68,6 +72,76 @@ fn validate_keypair(pk: &str, sk: &str) -> ResultType<()> { Ok(()) } +fn doctor_tcp(address: std::net::IpAddr, port: &str, desc: &str) { + let start = std::time::Instant::now(); + let conn = format!("{}:{}", address, port); + if let Ok(_stream) = TcpStream::connect(conn.as_str()) { + let elapsed = std::time::Instant::now().duration_since(start); + println!( + "TCP Port {} ({}): OK in {} ms", + port, + desc, + elapsed.as_millis() + ); + } else { + println!("TCP Port {} ({}): ERROR", port, desc); + } +} + +fn doctor_ip(server_ip_address: std::net::IpAddr, server_address: Option<&str>) { + println!("\nChecking IP address: {}", server_ip_address); + println!("Is IPV4: {}", server_ip_address.is_ipv4()); + println!("Is IPV6: {}", server_ip_address.is_ipv6()); + + // reverse dns lookup + // TODO: (check) doesn't seem to do reverse lookup on OSX... + let reverse = lookup_addr(&server_ip_address).unwrap(); + if server_address.is_some() { + if reverse == server_address.unwrap() { + println!("Reverse DNS lookup: '{}' MATCHES server address", reverse); + } else { + println!( + "Reverse DNS lookup: '{}' DOESN'T MATCH server address '{}'", + reverse, + server_address.unwrap() + ); + } + } + + // TODO: ICMP ping? + + // port check TCP (UDP is hard to check) + doctor_tcp(server_ip_address, "21114", "API"); + doctor_tcp(server_ip_address, "21115", "hbbs extra port for nat test"); + doctor_tcp(server_ip_address, "21116", "hbbs"); + doctor_tcp(server_ip_address, "21117", "hbbr tcp"); + doctor_tcp(server_ip_address, "21118", "hbbs websocket"); + doctor_tcp(server_ip_address, "21119", "hbbr websocket"); + + // TODO: key check +} + +fn doctor(server_address_unclean: &str) { + let server_address3 = server_address_unclean.trim(); + let server_address2 = server_address3.to_lowercase(); + let server_address = server_address2.as_str(); + println!("Checking server: {}\n", server_address); + let server_ipaddr = server_address.parse::<IpAddr>(); + if server_ipaddr.is_err() { + // the passed string is not an ip address + let ips: Vec<std::net::IpAddr> = lookup_host(server_address).unwrap(); + println!("Found {} IP addresses: ", ips.iter().count()); + + ips.iter().for_each(|ip| println!(" - {ip}")); + + ips.iter().for_each(|ip| doctor_ip(*ip, Some(server_address))); + + } else { + // user requested an ip address + doctor_ip(server_ipaddr.unwrap(), None); + } +} + fn main() { let args: Vec<_> = env::args().collect(); if args.len() <= 1 { @@ -88,6 +162,12 @@ fn main() { } println!("Key pair is VALID"); } + "doctor" => { + if args.len() <= 2 { + error_then_help("You must supply the rustdesk-server address"); + } + doctor(args[2].as_str()); + } _ => print_help(), } } diff --git a/src/version.rs b/src/version.rs index b54facc..3d00084 100644 --- a/src/version.rs +++ b/src/version.rs @@ -1 +1,2 @@ pub const VERSION: &str = "1.1.6"; +pub const BUILD_DATE: &str = "2023-01-06 11:03"; |