From 2540a27a3aafac61979d6b664e62655796c795ad Mon Sep 17 00:00:00 2001 From: qima Date: Thu, 19 Nov 2020 21:38:44 +0800 Subject: [PATCH] feat: notify when key got changed during relocation --- examples/minimal.rs | 2 +- src/event.rs | 10 +++++++++- src/routing/stage.rs | 6 +++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/examples/minimal.rs b/examples/minimal.rs index 9940088bd6..2d0a8836bb 100644 --- a/examples/minimal.rs +++ b/examples/minimal.rs @@ -268,7 +268,7 @@ async fn handle_event(index: usize, node: &mut Routing, event: Event) -> bool { "Node #{} relocation started - previous_name: {}", index, previous_name ), - Event::Relocated { previous_name } => { + Event::Relocated { previous_name, .. } => { info!( "Node #{} relocated - old name: {}, new name: {}", index, diff --git a/src/event.rs b/src/event.rs index 8d33ece9f8..bf913fa0a5 100644 --- a/src/event.rs +++ b/src/event.rs @@ -9,12 +9,14 @@ use crate::location::{DstLocation, SrcLocation}; use bytes::Bytes; +use ed25519_dalek::Keypair; use hex_fmt::HexFmt; pub use qp2p::{RecvStream, SendStream}; use std::{ collections::BTreeSet, fmt::{self, Debug, Formatter}, net::SocketAddr, + sync::Arc, }; use xor_name::{Prefix, XorName}; @@ -78,6 +80,8 @@ pub enum Event { Relocated { /// Old name before the relocation. previous_name: XorName, + /// New keypair to be used after relocation. + new_keypair: Arc, }, /// Disconnected or failed to connect - restart required. RestartRequired, @@ -136,9 +140,13 @@ impl Debug for Event { .debug_struct("RelocationStarted") .field("previous_name", previous_name) .finish(), - Self::Relocated { previous_name } => formatter + Self::Relocated { + previous_name, + new_keypair, + } => formatter .debug_struct("Relocated") .field("previous_name", previous_name) + .field("new_keypair", new_keypair) .finish(), Self::RestartRequired => write!(formatter, "RestartRequired"), Self::ClientMessageReceived { content, src, .. } => write!( diff --git a/src/routing/stage.rs b/src/routing/stage.rs index 8d0d595ad5..6ea8c4b9df 100644 --- a/src/routing/stage.rs +++ b/src/routing/stage.rs @@ -191,9 +191,13 @@ impl Stage { let mut state = self.state.lock().await; let event_tx = state.event_tx.clone(); + let new_keypair = node.keypair.clone(); *state = Approved::new(node, section, None, event_tx); - state.send_event(Event::Relocated { previous_name }); + state.send_event(Event::Relocated { + previous_name, + new_keypair, + }); let commands = backlog .into_iter()