diff --git a/src/routing/core/connectivity.rs b/src/routing/core/connectivity.rs index 50bd8b7710..cb729e1d83 100644 --- a/src/routing/core/connectivity.rs +++ b/src/routing/core/connectivity.rs @@ -130,7 +130,32 @@ impl Core { } } - fn complain_connectivity(&self, name: XorName) -> Result> { + pub fn handle_connection_lost(&self, addr: SocketAddr) -> Result> { + if let Some(peer) = self.section.find_joined_member_by_addr(&addr) { + debug!( + "Possible connection loss detected with known peer {:?}", + peer + ) + } else if let Some(end_user) = self.get_enduser_by_addr(&addr) { + debug!( + "Possible connection loss detected with known client {:?}", + end_user + ) + } else { + debug!("Possible connection loss detected with addr: {:?}", addr); + } + Ok(vec![]) + } + + pub fn handle_peer_lost(&self, addr: &SocketAddr) -> Result> { + let name = if let Some(peer) = self.section.find_joined_member_by_addr(addr) { + debug!("Lost known peer {}", peer); + *peer.name() + } else { + trace!("Lost unknown peer {}", addr); + return Ok(vec![]); + }; + if !self.is_elder() { // When self is not an elder, then the peer has to be an elder, and we shall complaint // the lost to other elders. @@ -159,34 +184,6 @@ impl Core { self.propose_offline(name) } - pub fn handle_connection_lost(&self, addr: SocketAddr) -> Result> { - let name = if let Some(peer) = self.section.find_joined_member_by_addr(&addr) { - debug!("Lost connection to known peer {}", peer); - *peer.name() - } else { - if let Some(end_user) = self.get_enduser_by_addr(&addr) { - debug!("Lost connection to client {:?}", end_user); - } else { - debug!("Lost connection to unknown peer {}", addr); - } - return Ok(vec![]); - }; - - self.complain_connectivity(name) - } - - pub fn handle_peer_lost(&self, addr: &SocketAddr) -> Result> { - let name = if let Some(peer) = self.section.find_joined_member_by_addr(addr) { - debug!("Lost known peer {}", peer); - *peer.name() - } else { - trace!("Lost unknown peer {}", addr); - return Ok(vec![]); - }; - - self.complain_connectivity(name) - } - pub fn propose_offline(&self, name: XorName) -> Result> { self.cast_offline_proposals(&iter::once(name).collect()) } diff --git a/tests/drop.rs b/tests/drop.rs deleted file mode 100644 index 17b815b3d8..0000000000 --- a/tests/drop.rs +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2020 MaidSafe.net limited. -// -// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3. -// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed -// under the GPL Licence is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY -// KIND, either express or implied. Please review the Licences for the specific language governing -// permissions and limitations relating to use of the SAFE Network Software. - -mod utils; - -use self::utils::*; -use anyhow::Result; -use sn_routing::{Event, NodeElderChange}; - -#[tokio::test] -async fn test_node_drop() -> Result<()> { - // NOTE: create at least 4 nodes, so when one is dropped the remaining ones still form a - // supermajority and the `Offline` proposals reach agreement. - let mut nodes = create_connected_nodes(4).await?; - - for (_, events) in &mut nodes[1..] { - assert_event!( - events, - Event::EldersChanged { - self_status_change: NodeElderChange::Promoted, - .. - } - ); - } - - // Wait for the DKG(s) to complete, to make sure there are no more messages being exchanged - // when we drop the node. This is to verify the lost peer detection works even if there is no - // network traffic. - let node_count = nodes.len(); - for (node, events) in &mut nodes { - if node.our_elders().await.len() == node_count { - continue; - } - - assert_event!(events, Event::EldersChanged { elders, .. } if (elders.remaining.len() + elders.added.len()) == node_count); - } - - // Drop one node - let dropped_node = nodes.remove(1).0; - let dropped_name = dropped_node.name().await; - let dropped_addr = dropped_node.our_connection_info(); - drop(dropped_node); - - tracing::info!("Dropped {} at {}", dropped_name, dropped_addr); - - for (_, events) in &mut nodes { - assert_event!(events, Event::MemberLeft { name, .. } if name == dropped_name) - } - - Ok(()) -}