Print stats about routing table size in UI
[dnsseed-rust] / src / printer.rs
index 37411274ce9181b0bec0196e5f7ae3dc64cd27dd..933603ccc440d65a3af97578b92875f8e9e5f5c8 100644 (file)
@@ -11,12 +11,16 @@ pub enum Stat {
        HeaderCount(u64),
        NewConnection,
        ConnectionClosed,
+       V4RoutingTableSize(usize),
+       V6RoutingTableSize(usize),
 }
 
 struct Stats {
        lines: LinkedList<String>,
        header_count: u64,
        connection_count: u64,
+       v4_table_size: usize,
+       v6_table_size: usize,
 }
 
 pub struct Printer {
@@ -29,6 +33,8 @@ impl Printer {
                        lines: LinkedList::new(),
                        header_count: 0,
                        connection_count: 0,
+                       v4_table_size: 0,
+                       v6_table_size: 0,
                }));
                let thread_arc = Arc::clone(&stats);
                std::thread::spawn(move || {
@@ -50,28 +56,11 @@ impl Printer {
                                }
 
                                out.write_all(b"\nNode counts by status:\n").expect("stdout broken?");
-                               out.write_all(format!("Untested:               {}\n", store.get_node_count(AddressState::Untested)
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!("Low Block Count:        {}\n", store.get_node_count(AddressState::LowBlockCount)
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!("High Block Count:       {}\n", store.get_node_count(AddressState::HighBlockCount)
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!("Low Version:            {}\n", store.get_node_count(AddressState::LowVersion)
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!("Bad Version:            {}\n", store.get_node_count(AddressState::BadVersion)
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!("Not Full Node:          {}\n", store.get_node_count(AddressState::NotFullNode)
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!("Protocol Violation:     {}\n", store.get_node_count(AddressState::ProtocolViolation)
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!("Timeout:                {}\n", store.get_node_count(AddressState::Timeout)
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!("Timeout During Request: {}\n", store.get_node_count(AddressState::TimeoutDuringRequest)
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!("Good:                   {}\n", store.get_node_count(AddressState::Good)
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!("WasGood:                {}\n", store.get_node_count(AddressState::WasGood)
-                                               ).as_bytes()).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?");
+                               }
 
                                out.write_all(format!(
                                                "\nCurrent connections open/in progress: {}\n", stats.connection_count).as_bytes()).expect("stdout broken?");
@@ -92,39 +81,17 @@ impl Printer {
                                                ).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!(
-                                               "Untested:               {}\n", store.get_u64(U64Setting::RescanInterval(AddressState::Untested))
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!(
-                                               "Low Block Count:        {}\n", store.get_u64(U64Setting::RescanInterval(AddressState::LowBlockCount))
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!(
-                                               "High Block Count        {}\n", store.get_u64(U64Setting::RescanInterval(AddressState::HighBlockCount))
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!(
-                                               "Low Version:            {}\n", store.get_u64(U64Setting::RescanInterval(AddressState::LowVersion))
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!(
-                                               "Bad Version:            {}\n", store.get_u64(U64Setting::RescanInterval(AddressState::BadVersion))
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!(
-                                               "Not Full Node:          {}\n", store.get_u64(U64Setting::RescanInterval(AddressState::NotFullNode))
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!(
-                                               "Protocol Violation:     {}\n", store.get_u64(U64Setting::RescanInterval(AddressState::ProtocolViolation))
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!(
-                                               "Timeout:                {}\n", store.get_u64(U64Setting::RescanInterval(AddressState::Timeout))
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!(
-                                               "Timeout During Request: {}\n", store.get_u64(U64Setting::RescanInterval(AddressState::TimeoutDuringRequest))
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!(
-                                               "Good:                   {}\n", store.get_u64(U64Setting::RescanInterval(AddressState::Good))
-                                               ).as_bytes()).expect("stdout broken?");
-                               out.write_all(format!(
-                                               "Was Good:               {}\n", store.get_u64(U64Setting::RescanInterval(AddressState::WasGood))
-                                               ).as_bytes()).expect("stdout broken?");
+                                               "\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?");
@@ -136,6 +103,7 @@ impl Printer {
                                                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?");
@@ -156,7 +124,7 @@ impl Printer {
                } else {
                        stats.lines.push_back(line);
                }
-               if stats.lines.len() > 50 {
+               if stats.lines.len() > 75 {
                        stats.lines.pop_front();
                }
        }
@@ -166,6 +134,8 @@ impl Printer {
                        Stat::HeaderCount(c) => self.stats.lock().unwrap().header_count = c,
                        Stat::NewConnection => self.stats.lock().unwrap().connection_count += 1,
                        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,
                }
        }
 }