diff --git a/Cargo.lock b/Cargo.lock index 46ebebf..5996791 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,21 +11,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "android-tzdata" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" - -[[package]] -name = "android_system_properties" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" -dependencies = [ - "libc", -] - [[package]] name = "anstream" version = "0.6.13" @@ -429,20 +414,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" -[[package]] -name = "chrono" -version = "0.4.38" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" -dependencies = [ - "android-tzdata", - "iana-time-zone", - "js-sys", - "num-traits", - "wasm-bindgen", - "windows-targets 0.52.4", -] - [[package]] name = "clap" version = "4.5.13" @@ -530,12 +501,6 @@ dependencies = [ "shared", ] -[[package]] -name = "core-foundation-sys" -version = "0.8.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" - [[package]] name = "cpufeatures" version = "0.2.9" @@ -951,29 +916,6 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" -[[package]] -name = "iana-time-zone" -version = "0.1.61" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" -dependencies = [ - "android_system_properties", - "core-foundation-sys", - "iana-time-zone-haiku", - "js-sys", - "wasm-bindgen", - "windows-core", -] - -[[package]] -name = "iana-time-zone-haiku" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" -dependencies = [ - "cc", -] - [[package]] name = "idna" version = "0.5.0" @@ -1222,15 +1164,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" -[[package]] -name = "num-traits" -version = "0.2.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" -dependencies = [ - "autocfg", -] - [[package]] name = "num_cpus" version = "1.16.0" @@ -1754,10 +1687,7 @@ dependencies = [ name = "spy-detector" version = "0.1.0" dependencies = [ - "chrono", "dashmap", - "log", - "nng", "shared", ] @@ -2140,15 +2070,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows-core" -version = "0.52.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" -dependencies = [ - "windows-targets 0.52.4", -] - [[package]] name = "windows-sys" version = "0.48.0" diff --git a/tools/spy-detector/Cargo.toml b/tools/spy-detector/Cargo.toml index 2b4592c..d62ca6a 100644 --- a/tools/spy-detector/Cargo.toml +++ b/tools/spy-detector/Cargo.toml @@ -4,8 +4,5 @@ version = "0.1.0" edition = "2021" [dependencies] -nng = "1.0.1" dashmap = "6.1.0" -chrono = "0.4.38" -shared = { path = "../../shared" } -log = "0.4.22" \ No newline at end of file +shared = { path = "../../shared" } \ No newline at end of file diff --git a/tools/spy-detector/src/main.rs b/tools/spy-detector/src/main.rs index a90da17..eec2b63 100644 --- a/tools/spy-detector/src/main.rs +++ b/tools/spy-detector/src/main.rs @@ -1,12 +1,13 @@ use dashmap::DashMap; -use nng::options::protocol::pubsub::Subscribe; -use nng::options::Options; -use nng::{Protocol, Socket}; use shared::clap; use shared::clap::Parser; use shared::event_msg; use shared::event_msg::event_msg::Event; +use shared::log; use shared::net_msg; +use shared::nng::options::protocol::pubsub::Subscribe; +use shared::nng::options::Options; +use shared::nng::{Protocol, Socket}; use shared::prost::Message; use shared::simple_logger; use std::sync::atomic; @@ -15,8 +16,8 @@ use std::sync::Arc; use std::time::Duration; use std::time::Instant; -const ADDRESS: &str = "tcp://127.0.0.1:8883"; -const STATS_INTERVAL: Duration = Duration::from_secs(10); // Duration(seconds) to print stats of peers +// const ADDRESS: &str = "tcp://127.0.0.1:8883"; +// const STATS_INTERVAL: Duration = Duration::from_secs(120); // Duration(seconds) to print stats of peers const LOG_TARGET: &str = "main"; @@ -27,6 +28,14 @@ struct Args { #[arg(short, long, default_value = "5")] threshold: u32, + /// The extractor address the tool should connect to. + #[arg(short, long, default_value = "tcp://127.0.0.1:8883")] + address: String, + + /// Duration (in seconds) to print stats of peers + #[arg(short = 'i', long, default_value = "120")] + stats_interval: u64, + /// The log level the tool should run with. Valid log levels /// are "trace", "debug", "info", "warn", "error". See https://docs.rs/log/latest/log/enum.Level.html #[arg(short, long, default_value_t = log::Level::Debug)] @@ -55,6 +64,8 @@ fn main() { //to-do: use threshold at appropriate location let threshold = &args.threshold; + let address = &args.address; + let stats_interval = Duration::from_secs(args.stats_interval); simple_logger::init_with_level(args.log_level).unwrap(); @@ -63,7 +74,7 @@ fn main() { log::info!(target: LOG_TARGET, "Starting spy-detector...",); let sub = Socket::new(Protocol::Sub0).unwrap(); - sub.dial(ADDRESS).unwrap(); + sub.dial(address).unwrap(); let all_topics = vec![]; sub.set_opt::(all_topics).unwrap(); @@ -76,7 +87,7 @@ fn main() { let mut last_display = Instant::now(); loop { let now = Instant::now(); - if now.duration_since(last_display) >= STATS_INTERVAL { + if now.duration_since(last_display) >= stats_interval { display_all_stats(&display_peer_map); last_display = now; } @@ -229,8 +240,7 @@ fn process_connection_event(peer_map: &PeerMap, event: &str) { fn print_peer_stats(peer_addr: &str, stats: &PeerStats) { println!( - "[{}] Peer ID {} stats:\n INV TX sent: {:?}\n INV TX received: {:?}\n INV WTX received: {:?}\n INV WitnessTX received: {:?}\n GetDATA WitnessTX received: {:?}\n GETDATA WitnessTX received: {:?}\n Tx sent: {:?}\n Tx received: {:?}\n Last Activity: {:?}", - chrono::Local::now().format("%Y-%m-%d %H:%M:%S"), + "Peer ID {} stats:\n INV TX sent: {:?}\n INV TX received: {:?}\n INV WTX received: {:?}\n INV WitnessTX received: {:?}\n GetDATA WitnessTX received: {:?}\n GETDATA WitnessTX received: {:?}\n Tx sent: {:?}\n Tx received: {:?}\n Last Activity: {:?}", peer_addr, stats.inv_tx_sent, stats.inv_tx_received, @@ -246,15 +256,11 @@ fn print_peer_stats(peer_addr: &str, stats: &PeerStats) { fn display_all_stats(peer_map: &PeerMap) { let map = peer_map; - println!( - "\n===== Stats for all peers ({}): =====", - chrono::Local::now().format("%Y-%m-%d %H:%M:%S") - ); + println!("\n===== Stats for all peers: ====="); for item in map.iter() { let peer_id = item.key(); let stats = item.value(); - //println!("Key: {}\n", peer_id); print_peer_stats(&peer_id, &stats); println!("----------------------------------------"); }