From c348304dc0286a2228fe6074e994c70e80cc1db7 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Mon, 20 May 2019 22:05:11 -0400 Subject: [PATCH] Print old state on updates --- src/datastore.rs | 4 ++-- src/main.rs | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) 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(()) -- 2.39.5