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

Commit

Permalink
feat: notify when key got changed during relocation
Browse files Browse the repository at this point in the history
  • Loading branch information
maqi committed Nov 23, 2020
1 parent 9c97008 commit 2540a27
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 9 additions & 1 deletion src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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<Keypair>,
},
/// Disconnected or failed to connect - restart required.
RestartRequired,
Expand Down Expand Up @@ -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!(
Expand Down
6 changes: 5 additions & 1 deletion src/routing/stage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 2540a27

Please sign in to comment.