]> git.bitcoin.ninja Git - dnsseed-rust/commitdiff
Use AddressState utils more
authorMatt Corallo <git@bluematt.me>
Tue, 21 May 2019 02:03:42 +0000 (22:03 -0400)
committerMatt Corallo <git@bluematt.me>
Tue, 21 May 2019 02:36:47 +0000 (22:36 -0400)
src/datastore.rs
src/printer.rs
src/reader.rs

index c56a86d7b84eebf927c1ad6126dd19f8eda780bf..4782027e8736eb78c6956ab011f7b1dae690b368 100644 (file)
@@ -80,6 +80,10 @@ impl AddressState {
                        AddressState::WasGood => "Was Good",
                }
        }
+
+       pub fn get_count() -> u8 {
+               11
+       }
 }
 
 #[derive(Hash, PartialEq, Eq)]
index 37411274ce9181b0bec0196e5f7ae3dc64cd27dd..c7e902358009a935565211ad62cd57823f7b7652 100644 (file)
@@ -50,28 +50,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!("{}: {}\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 +75,12 @@ impl Printer {
                                                ).as_bytes()).expect("stdout broken?");
 
                                out.write_all(b"\nRetry times (in seconds):\n").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?");
+                               for i in 0..AddressState::get_count() {
+                                       out.write_all(format!(
+                                                       "{} ({}): {}\n", AddressState::from_num(i).unwrap().to_str(), i,
+                                                       store.get_u64(U64Setting::RescanInterval(AddressState::from_num(i).unwrap()))
+                                                       ).as_bytes()).expect("stdout broken?");
+                               }
 
                                out.write_all(b"\nCommands:\n").expect("stdout broken?");
                                out.write_all(b"q: quit\n").expect("stdout broken?");
index 9c6a400375716010415056c72ae76dae169d1f96..208d2241c382ee4309beda50f1ac6df2d55159fc 100644 (file)
@@ -54,19 +54,9 @@ pub fn read(store: &'static Store, printer: &'static Printer) {
                        },
                        "a" => scan_node(Instant::now(), try_parse_next_chunk!(SocketAddr)),
                        "r" => {
-                               match try_parse_next_chunk!(u8) {
-                                       0 => store.set_u64(U64Setting::RescanInterval(AddressState::Untested), try_parse_next_chunk!(u64)),
-                                       1 => store.set_u64(U64Setting::RescanInterval(AddressState::LowBlockCount), try_parse_next_chunk!(u64)),
-                                       2 => store.set_u64(U64Setting::RescanInterval(AddressState::HighBlockCount), try_parse_next_chunk!(u64)),
-                                       3 => store.set_u64(U64Setting::RescanInterval(AddressState::LowVersion), try_parse_next_chunk!(u64)),
-                                       4 => store.set_u64(U64Setting::RescanInterval(AddressState::BadVersion), try_parse_next_chunk!(u64)),
-                                       5 => store.set_u64(U64Setting::RescanInterval(AddressState::NotFullNode), try_parse_next_chunk!(u64)),
-                                       6 => store.set_u64(U64Setting::RescanInterval(AddressState::ProtocolViolation), try_parse_next_chunk!(u64)),
-                                       7 => store.set_u64(U64Setting::RescanInterval(AddressState::Timeout), try_parse_next_chunk!(u64)),
-                                       8 => store.set_u64(U64Setting::RescanInterval(AddressState::TimeoutDuringRequest), try_parse_next_chunk!(u64)),
-                                       9 => store.set_u64(U64Setting::RescanInterval(AddressState::Good), try_parse_next_chunk!(u64)),
-                                       10 => store.set_u64(U64Setting::RescanInterval(AddressState::WasGood), try_parse_next_chunk!(u64)),
-                                       _ => err!(),
+                               match AddressState::from_num(try_parse_next_chunk!(u8)) {
+                                       Some(state) => store.set_u64(U64Setting::RescanInterval(state), try_parse_next_chunk!(u64)),
+                                       None => err!(),
                                }
                        },
                        "q" => {