X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fprinter.rs;h=c20b925e7f5f83d14316ca9d4a31926dc4c5e9dd;hb=c06ea88b377bd782c96d74028a11d8595112f272;hp=933603ccc440d65a3af97578b92875f8e9e5f5c8;hpb=c49b9c568cbde2bb7d24726deaa66da11a9d8aab;p=dnsseed-rust diff --git a/src/printer.rs b/src/printer.rs index 933603c..c20b925 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -13,6 +13,7 @@ pub enum Stat { ConnectionClosed, V4RoutingTableSize(usize), V6RoutingTableSize(usize), + RoutingTablePaths(usize), } struct Stats { @@ -21,6 +22,7 @@ struct Stats { connection_count: u64, v4_table_size: usize, v6_table_size: usize, + paths: usize, } pub struct Printer { @@ -35,6 +37,7 @@ impl Printer { connection_count: 0, v4_table_size: 0, v6_table_size: 0, + paths: 0, })); let thread_arc = Arc::clone(&stats); std::thread::spawn(move || { @@ -44,71 +47,75 @@ impl Printer { let stdout = std::io::stdout(); let mut out = stdout.lock(); - let stats = thread_arc.lock().unwrap(); - if START_SHUTDOWN.load(Ordering::Relaxed) && stats.connection_count == 0 { - break; - } + { + let stats = thread_arc.lock().unwrap(); + if START_SHUTDOWN.load(Ordering::Relaxed) && stats.connection_count == 0 { + break; + } + + out.write_all(b"\x1b[2J\x1b[;H\n").expect("stdout broken?"); + for line in stats.lines.iter() { + out.write_all(line.as_bytes()).expect("stdout broken?"); + out.write_all(b"\n").expect("stdout broken?"); + } + + out.write_all(b"\nNode counts by status:\n").expect("stdout broken?"); + for i in 0..AddressState::get_count() { + out.write_all(format!("{:22}: {}\n", AddressState::from_num(i).unwrap().to_str(), + store.get_node_count(AddressState::from_num(i).unwrap()) + ).as_bytes()).expect("stdout broken?"); + } + let generations = store.get_bloom_node_count(); + out.write_all(b"Bloom filter generations contain:").expect("stdout broken?"); + for generation in &generations { + out.write_all(format!(" {}", generation).as_bytes()).expect("stdout broken?"); + } - out.write_all(b"\x1b[2J\x1b[;H\n").expect("stdout broken?"); - for line in stats.lines.iter() { - out.write_all(line.as_bytes()).expect("stdout broken?"); - out.write_all(b"\n").expect("stdout broken?"); - } + out.write_all(format!( + "\n\nCurrent connections open/in progress: {}\n", stats.connection_count).as_bytes()).expect("stdout broken?"); + out.write_all(format!( + "Current block count: {}\n", stats.header_count).as_bytes()).expect("stdout broken?"); - out.write_all(b"\nNode counts by status:\n").expect("stdout broken?"); - for i in 0..AddressState::get_count() { - out.write_all(format!("{:22}: {}\n", AddressState::from_num(i).unwrap().to_str(), - store.get_node_count(AddressState::from_num(i).unwrap()) + out.write_all(format!( + "Timeout for full run (in seconds): {} (\"t x\" to change to x seconds)\n", store.get_u64(U64Setting::RunTimeout) ).as_bytes()).expect("stdout broken?"); - } + out.write_all(format!( + "Minimum protocol version: {} (\"v x\" to change value to x)\n", store.get_u64(U64Setting::MinProtocolVersion) + ).as_bytes()).expect("stdout broken?"); + out.write_all(format!( + "Subversion match regex: {} (\"s x\" to change value to x)\n", store.get_regex(RegexSetting::SubverRegex).as_str() + ).as_bytes()).expect("stdout broken?"); + + out.write_all(b"\nRetry times (in seconds):\n").expect("stdout broken?"); + for i in 0..AddressState::get_count() { + let scan_secs = store.get_u64(U64Setting::RescanInterval(AddressState::from_num(i).unwrap())); + out.write_all(format!( + "{:22} ({:2}): {:5} (ie {} hrs, {} min)\n", AddressState::from_num(i).unwrap().to_str(), i, + scan_secs, scan_secs / 60 / 60, (scan_secs / 60) % 60, + ).as_bytes()).expect("stdout broken?"); + } + + out.write_all(format!( + "\nBGP Routing Table: {} v4 nets, {} v6 nets, {} max paths\n", + stats.v4_table_size, stats.v6_table_size, stats.paths).as_bytes()).expect("stdout broken?"); - out.write_all(format!( - "\nCurrent connections open/in progress: {}\n", stats.connection_count).as_bytes()).expect("stdout broken?"); - out.write_all(format!( - "Connections opened each second: {} (\"c x\" to change to x seconds)\n", store.get_u64(U64Setting::ConnsPerSec) - ).as_bytes()).expect("stdout broken?"); - out.write_all(format!( - "Current block count: {}\n", stats.header_count).as_bytes()).expect("stdout broken?"); - - out.write_all(format!( - "Timeout for full run (in seconds): {} (\"t x\" to change to x seconds)\n", store.get_u64(U64Setting::RunTimeout) - ).as_bytes()).expect("stdout broken?"); - out.write_all(format!( - "Minimum protocol version: {} (\"v x\" to change value to x)\n", store.get_u64(U64Setting::MinProtocolVersion) - ).as_bytes()).expect("stdout broken?"); - out.write_all(format!( - "Subversion match regex: {} (\"s x\" to change value to x)\n", store.get_regex(RegexSetting::SubverRegex).as_str() - ).as_bytes()).expect("stdout broken?"); - - out.write_all(b"\nRetry times (in seconds):\n").expect("stdout broken?"); - for i in 0..AddressState::get_count() { - let scan_secs = store.get_u64(U64Setting::RescanInterval(AddressState::from_num(i).unwrap())); + out.write_all(b"\nCommands:\n").expect("stdout broken?"); + out.write_all(b"q: quit\n").expect("stdout broken?"); + out.write_all(format!( + "r x y: Change retry time for status x (int value, see retry times section for name mappings) to y (in seconds)\n" + ).as_bytes()).expect("stdout broken?"); out.write_all(format!( - "{:22} ({:2}): {:5} (ie {} hrs, {} min)\n", AddressState::from_num(i).unwrap().to_str(), i, - scan_secs, scan_secs / 60 / 60, (scan_secs / 60) % 60, + "w x: Change the amount of time a node is considered WAS_GOOD after it fails to x from {} (in seconds)\n", + store.get_u64(U64Setting::WasGoodTimeout) ).as_bytes()).expect("stdout broken?"); + out.write_all(b"a x: Scan node x\n").expect("stdout broken?"); + out.write_all(b"b x: BGP Lookup IP x\n").expect("stdout broken?"); + out.write_all(b"\x1b[s").expect("stdout broken?"); // Save cursor position and provide a blank line before cursor + out.write_all(b"\x1b[;H\x1b[2K").expect("stdout broken?"); + out.write_all(b"Most recent log:\n").expect("stdout broken?"); + out.write_all(b"\x1b[u").expect("stdout broken?"); // Restore cursor position and go up one line } - out.write_all(format!( - "\nBGP Routing Table: {} v4 paths, {} v6 paths\n", - stats.v4_table_size, stats.v6_table_size).as_bytes()).expect("stdout broken?"); - - out.write_all(b"\nCommands:\n").expect("stdout broken?"); - out.write_all(b"q: quit\n").expect("stdout broken?"); - out.write_all(format!( - "r x y: Change retry time for status x (int value, see retry times section for name mappings) to y (in seconds)\n" - ).as_bytes()).expect("stdout broken?"); - out.write_all(format!( - "w x: Change the amount of time a node is considered WAS_GOOD after it fails to x from {} (in seconds)\n", - store.get_u64(U64Setting::WasGoodTimeout) - ).as_bytes()).expect("stdout broken?"); - out.write_all(b"a x: Scan node x\n").expect("stdout broken?"); - out.write_all(b"b x: BGP Lookup IP x\n").expect("stdout broken?"); - out.write_all(b"\x1b[s").expect("stdout broken?"); // Save cursor position and provide a blank line before cursor - out.write_all(b"\x1b[;H\x1b[2K").expect("stdout broken?"); - out.write_all(b"Most recent log:\n").expect("stdout broken?"); - out.write_all(b"\x1b[u").expect("stdout broken?"); // Restore cursor position and go up one line - out.flush().expect("stdout broken?"); } }); @@ -136,6 +143,7 @@ impl Printer { Stat::ConnectionClosed => self.stats.lock().unwrap().connection_count -= 1, Stat::V4RoutingTableSize(c) => self.stats.lock().unwrap().v4_table_size = c, Stat::V6RoutingTableSize(c) => self.stats.lock().unwrap().v6_table_size = c, + Stat::RoutingTablePaths(c) => self.stats.lock().unwrap().paths = c, } } }