Fix dup block request bug
[dnsseed-rust] / src / printer.rs
index 10d2150fbf432dfec1582854a0fd7f3e102280ad..37411274ce9181b0bec0196e5f7ae3dc64cd27dd 100644 (file)
@@ -1,8 +1,11 @@
+use std::sync::atomic::Ordering;
 use std::collections::LinkedList;
 use std::sync::{Arc, Mutex};
 use std::io::Write;
 
-use crate::datastore::{Store, AddressState, U64Setting, StringSetting};
+use crate::datastore::{Store, AddressState, U64Setting, RegexSetting};
+
+use crate::START_SHUTDOWN;
 
 pub enum Stat {
        HeaderCount(u64),
@@ -36,6 +39,9 @@ impl Printer {
                                let mut out = stdout.lock();
 
                                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() {
@@ -82,7 +88,7 @@ impl Printer {
                                                "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_string(StringSetting::SubverRegex)
+                                               "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?");
@@ -129,7 +135,6 @@ impl Printer {
                                                "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"p: Enable/disable updating these stats\n").expect("stdout broken?");
                                out.write_all(b"a x: Scan node 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?");
@@ -144,9 +149,13 @@ impl Printer {
                }
        }
 
-       pub fn add_line(&self, line: String, _err: bool) {
+       pub fn add_line(&self, line: String, err: bool) {
                let mut stats = self.stats.lock().unwrap();
-               stats.lines.push_back(line);
+               if err {
+                       stats.lines.push_back("\x1b[31m".to_string() + &line + "\x1b[0m");
+               } else {
+                       stats.lines.push_back(line);
+               }
                if stats.lines.len() > 50 {
                        stats.lines.pop_front();
                }