Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Commit

Permalink
feat: remove Variant::Ping
Browse files Browse the repository at this point in the history
We no longer explicitly handle lost connections, so this variant is now useless.
  • Loading branch information
madadam committed Sep 29, 2020
1 parent 5e0fdfa commit 18a9d40
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 49 deletions.
3 changes: 0 additions & 3 deletions src/messages/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ pub(crate) enum Variant {
/// Sent from a bootstrapping peer to the section that responded with a
/// `BootstrapResponse::Join` to its `BootstrapRequest`.
JoinRequest(Box<JoinRequest>),
/// Message sent to a disconnected peer to trigger lost peer detection.
Ping,
/// Sent from a node that can't establish the trust of the contained message to its original
/// source in order for them to provide new proof that the node would trust.
BouncedUntrustedMessage(Box<Message>),
Expand Down Expand Up @@ -163,7 +161,6 @@ impl Debug for Variant {
Self::BootstrapRequest(payload) => write!(f, "BootstrapRequest({})", payload),
Self::BootstrapResponse(payload) => write!(f, "BootstrapResponse({:?})", payload),
Self::JoinRequest(payload) => write!(f, "JoinRequest({:?})", payload),
Self::Ping => write!(f, "Ping"),
Self::BouncedUntrustedMessage(message) => f
.debug_tuple("BouncedUntrustedMessage")
.field(message)
Expand Down
45 changes: 2 additions & 43 deletions src/node/stage/approved.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,33 +209,6 @@ impl Approved {
Ok(())
}

// TODO: review if we still need to invoke this function which used to
// be called when couldn't connect to a peer.
/*
async fn handle_connection_failure(&mut self, addr: SocketAddr) -> Result<()> {
let node = self
.shared_state
.our_members
.joined()
.map(|info| &info.p2p_node)
.find(|node| *node.peer_addr() == addr);
if let Some(node) = node {
trace!("ConnectionFailure from member {}", node);
// Ping the peer to trigger lost peer detection.
let addr = *node.peer_addr();
self.comm
.send_direct_message(&self.node_info.full_id, &addr, Variant::Ping)
.await?;
} else {
trace!("ConnectionFailure from non-member {}", addr);
}
Ok(())
}
*/

async fn handle_peer_lost(&mut self, peer_addr: &SocketAddr) -> Result<()> {
let name = if let Some(node) = self.shared_state.find_p2p_node_from_addr(peer_addr) {
debug!("Lost known peer {}", node);
Expand Down Expand Up @@ -345,7 +318,7 @@ impl Approved {
return Ok(MessageStatus::Unknown);
}
}
Variant::NodeApproval(_) | Variant::BootstrapResponse(_) | Variant::Ping => {
Variant::NodeApproval(_) | Variant::BootstrapResponse(_) => {
return Ok(MessageStatus::Useless)
}
Variant::Vote { proof_share, .. } => {
Expand Down Expand Up @@ -516,9 +489,7 @@ impl Approved {

Ok(None)
}
Variant::NodeApproval(_) | Variant::BootstrapResponse(_) | Variant::Ping => {
unreachable!()
}
Variant::NodeApproval(_) | Variant::BootstrapResponse(_) => unreachable!(),
}
}

Expand Down Expand Up @@ -1481,18 +1452,6 @@ impl Approved {
if !old_is_elder && new_is_elder {
info!("Promoted to elder");
self.node_info.send_event(Event::PromotedToElder);

// Ping all members to detect recent lost nodes for which the section might need
// our Offline vote.
for p2p_node in self
.shared_state
.active_members()
.cloned()
.collect::<Vec<_>>()
{
self.send_direct_message(p2p_node.peer_addr(), Variant::Ping)
.await?;
}
}

if old_is_elder && !new_is_elder {
Expand Down
1 change: 0 additions & 1 deletion src/node/stage/bootstrapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ impl Bootstrapping {
| Variant::MessageSignature(_)
| Variant::BootstrapRequest(_)
| Variant::JoinRequest(_)
| Variant::Ping
| Variant::BouncedUnknownMessage { .. }
| Variant::Vote { .. }
| Variant::DKGResult { .. }
Expand Down
3 changes: 1 addition & 2 deletions src/node/stage/joining.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ impl Joining {

Variant::BootstrapRequest(_)
| Variant::BootstrapResponse(_)
| Variant::JoinRequest(_)
| Variant::Ping => Ok(MessageStatus::Useless),
| Variant::JoinRequest(_) => Ok(MessageStatus::Useless),
}
}

Expand Down

0 comments on commit 18a9d40

Please sign in to comment.