From: Matt Corallo Date: Mon, 3 Jun 2019 11:59:48 +0000 (-0400) Subject: Track which element timeout was hit for in different categories X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=8b18f78f572b03bc0b69c9648f758066e0b0bc03;p=dnsseed-rust Track which element timeout was hit for in different categories --- diff --git a/src/datastore.rs b/src/datastore.rs index 1a3d7c9..0eb2e8e 100644 --- a/src/datastore.rs +++ b/src/datastore.rs @@ -27,6 +27,8 @@ pub enum AddressState { ProtocolViolation, Timeout, TimeoutDuringRequest, + TimeoutAwaitingAddr, + TimeoutAwaitingBlock, Good, WasGood, } @@ -43,8 +45,10 @@ impl AddressState { 0x6 => Some(AddressState::ProtocolViolation), 0x7 => Some(AddressState::Timeout), 0x8 => Some(AddressState::TimeoutDuringRequest), - 0x9 => Some(AddressState::Good), - 0xa => Some(AddressState::WasGood), + 0x9 => Some(AddressState::TimeoutAwaitingAddr), + 0xa => Some(AddressState::TimeoutAwaitingBlock), + 0xb => Some(AddressState::Good), + 0xc => Some(AddressState::WasGood), _ => None, } } @@ -60,8 +64,10 @@ impl AddressState { AddressState::ProtocolViolation => 6, AddressState::Timeout => 7, AddressState::TimeoutDuringRequest => 8, - AddressState::Good => 9, - AddressState::WasGood => 10, + AddressState::TimeoutAwaitingAddr => 9, + AddressState::TimeoutAwaitingBlock => 10, + AddressState::Good => 11, + AddressState::WasGood => 12, } } @@ -76,13 +82,15 @@ impl AddressState { AddressState::ProtocolViolation => "Protocol Violation", AddressState::Timeout => "Timeout", AddressState::TimeoutDuringRequest => "Timeout During Request", + AddressState::TimeoutAwaitingAddr => "Timeout Awaiting Addr", + AddressState::TimeoutAwaitingBlock => "Timeout Awaiting Block", AddressState::Good => "Good", AddressState::WasGood => "Was Good", } } - pub fn get_count() -> u8 { - 11 + pub const fn get_count() -> u8 { + 13 } } @@ -153,7 +161,7 @@ impl Store { } } } } - let mut u64s = HashMap::with_capacity(15); + let mut u64s = HashMap::with_capacity(AddressState::get_count() as usize + 4); u64s.insert(U64Setting::ConnsPerSec, try_read!(l, u64)); u64s.insert(U64Setting::RunTimeout, try_read!(l, u64)); u64s.insert(U64Setting::WasGoodTimeout, try_read!(l, u64)); @@ -167,6 +175,8 @@ impl Store { u64s.insert(U64Setting::RescanInterval(AddressState::ProtocolViolation), try_read!(l, u64)); u64s.insert(U64Setting::RescanInterval(AddressState::Timeout), try_read!(l, u64)); u64s.insert(U64Setting::RescanInterval(AddressState::TimeoutDuringRequest), try_read!(l, u64)); + u64s.insert(U64Setting::RescanInterval(AddressState::TimeoutAwaitingAddr), try_read!(l, u64)); + u64s.insert(U64Setting::RescanInterval(AddressState::TimeoutAwaitingBlock), try_read!(l, u64)); u64s.insert(U64Setting::RescanInterval(AddressState::Good), try_read!(l, u64)); u64s.insert(U64Setting::RescanInterval(AddressState::WasGood), try_read!(l, u64)); future::ok((u64s, try_read!(l, Regex))) @@ -184,9 +194,11 @@ impl Store { u64s.insert(U64Setting::RescanInterval(AddressState::ProtocolViolation), 86400); u64s.insert(U64Setting::RescanInterval(AddressState::Timeout), 86400); u64s.insert(U64Setting::RescanInterval(AddressState::TimeoutDuringRequest), 21600); + u64s.insert(U64Setting::RescanInterval(AddressState::TimeoutAwaitingAddr), 1800); + u64s.insert(U64Setting::RescanInterval(AddressState::TimeoutAwaitingBlock), 3600); u64s.insert(U64Setting::RescanInterval(AddressState::Good), 1800); u64s.insert(U64Setting::RescanInterval(AddressState::WasGood), 1800); - u64s.insert(U64Setting::MinProtocolVersion, 10000); //XXX + u64s.insert(U64Setting::MinProtocolVersion, 70002); future::ok((u64s, Regex::new(".*").unwrap())) }); @@ -360,7 +372,7 @@ impl Store { pub fn save_data(&'static self) -> impl Future { let settings_file = self.store.clone() + "/settings"; let settings_future = File::create(settings_file.clone() + ".tmp").and_then(move |f| { - let settings_string = format!("{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}", + let settings_string = format!("{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}\n{}", self.get_u64(U64Setting::ConnsPerSec), self.get_u64(U64Setting::RunTimeout), self.get_u64(U64Setting::WasGoodTimeout), @@ -374,6 +386,8 @@ impl Store { self.get_u64(U64Setting::RescanInterval(AddressState::ProtocolViolation)), self.get_u64(U64Setting::RescanInterval(AddressState::Timeout)), self.get_u64(U64Setting::RescanInterval(AddressState::TimeoutDuringRequest)), + self.get_u64(U64Setting::RescanInterval(AddressState::TimeoutAwaitingAddr)), + self.get_u64(U64Setting::RescanInterval(AddressState::TimeoutAwaitingBlock)), self.get_u64(U64Setting::RescanInterval(AddressState::Good)), self.get_u64(U64Setting::RescanInterval(AddressState::WasGood)), self.get_regex(RegexSetting::SubverRegex).as_str()); diff --git a/src/main.rs b/src/main.rs index ae0bb5b..2c19c23 100644 --- a/src/main.rs +++ b/src/main.rs @@ -169,7 +169,7 @@ pub fn scan_node(scan_time: Instant, node: SocketAddr, manual: bool) { let store = unsafe { DATA_STORE.as_ref().unwrap() }; printer.set_stat(Stat::ConnectionClosed); - let state_lock = final_peer_state.lock().unwrap(); + let mut state_lock = final_peer_state.lock().unwrap(); if state_lock.recvd_version && state_lock.recvd_verack && state_lock.recvd_addrs && state_lock.recvd_block { let old_state = store.set_node_state(node, AddressState::Good, state_lock.node_services); @@ -178,10 +178,17 @@ pub fn scan_node(scan_time: Instant, node: SocketAddr, manual: bool) { } } else { assert!(state_lock.fail_reason != AddressState::Good); + if state_lock.fail_reason == AddressState::TimeoutDuringRequest && state_lock.recvd_version && state_lock.recvd_verack { + if !state_lock.recvd_addrs { + state_lock.fail_reason = AddressState::TimeoutAwaitingAddr; + } else if !state_lock.recvd_block { + state_lock.fail_reason = AddressState::TimeoutAwaitingBlock; + } + } let old_state = store.set_node_state(node, state_lock.fail_reason, 0); if (manual || old_state != state_lock.fail_reason) && state_lock.fail_reason == AddressState::TimeoutDuringRequest { - printer.add_line(format!("Updating {} from {} to Timeout During Request (ver: {}, vack: {}, addr: {}, block: {})", - node, old_state.to_str(), state_lock.recvd_version, state_lock.recvd_verack, state_lock.recvd_addrs, state_lock.recvd_block), true); + printer.add_line(format!("Updating {} from {} to Timeout During Request (ver: {}, vack: {})", + node, old_state.to_str(), state_lock.recvd_version, state_lock.recvd_verack), true); } else if manual || (old_state != state_lock.fail_reason && state_lock.msg.0 != "" && state_lock.msg.1) { printer.add_line(format!("Updating {} from {} to {} {}", node, old_state.to_str(), state_lock.fail_reason.to_str(), &state_lock.msg.0), state_lock.msg.1); }