From: Matt Corallo Date: Tue, 21 May 2019 02:05:11 +0000 (-0400) Subject: Print old state on updates X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=c348304dc0286a2228fe6074e994c70e80cc1db7;p=dnsseed-rust Print old state on updates --- diff --git a/src/datastore.rs b/src/datastore.rs index 4782027..ba984d2 100644 --- a/src/datastore.rs +++ b/src/datastore.rs @@ -315,11 +315,11 @@ impl Store { } } - pub fn set_node_state(&self, addr: SocketAddr, state: AddressState, services: u64) -> bool { + pub fn set_node_state(&self, addr: SocketAddr, state: AddressState, services: u64) -> AddressState { let mut nodes_lock = self.nodes.write().unwrap(); let nodes = nodes_lock.borrow_mut(); let state_ref = nodes.nodes_to_state.get_mut(&addr).unwrap(); - let ret = state != state_ref.state; + let ret = state_ref.state; let now = Instant::now(); if (state_ref.state == AddressState::Good || state_ref.state == AddressState::WasGood) && state != AddressState::Good diff --git a/src/main.rs b/src/main.rs index a6b7155..94c7ab8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -173,13 +173,15 @@ pub fn scan_node(scan_time: Instant, node: SocketAddr) { let state_lock = final_peer_state.lock().unwrap(); if state_lock.recvd_version && state_lock.recvd_verack && state_lock.recvd_addrs && state_lock.recvd_block { - if store.set_node_state(node, AddressState::Good, state_lock.node_services) && state_lock.msg.0 != "" { - printer.add_line(state_lock.msg.0.clone(), state_lock.msg.1); + let old_state = store.set_node_state(node, AddressState::Good, state_lock.node_services); + if old_state != AddressState::Good && state_lock.msg.0 != "" { + printer.add_line(state_lock.msg.0.clone() + " from " + old_state.to_str(), state_lock.msg.1); } } else { assert!(state_lock.fail_reason != AddressState::Good); - if store.set_node_state(node, state_lock.fail_reason, 0) && state_lock.msg.0 != "" { - printer.add_line(state_lock.msg.0.clone(), state_lock.msg.1); + let old_state = store.set_node_state(node, state_lock.fail_reason, 0); + if old_state != state_lock.fail_reason && state_lock.msg.0 != "" { + printer.add_line(state_lock.msg.0.clone() + " from " + old_state.to_str(), state_lock.msg.1); } } future::ok(())