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

Commit

Permalink
feat(api): add new API for an Elder node to propose that a node has gone
Browse files Browse the repository at this point in the history
offline
  • Loading branch information
lionel-faber authored and dirvine committed Apr 21, 2021
1 parent 2418d9f commit 2937e59
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/routing/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ pub(crate) enum Command {
// The key of the destination section that the joining node knows, if any.
their_knowledge: Option<bls::PublicKey>,
},
/// Proposes a peer as offline
ProposeOffline(XorName),
}

impl Command {
Expand Down Expand Up @@ -198,6 +200,7 @@ impl Debug for Command {
.field("peer", peer)
.field("previous_name", previous_name)
.finish(),
Self::ProposeOffline(name) => f.debug_tuple("ProposeOffline").field(name).finish(),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/routing/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ impl Core {
self.propose_offline(name)
}

fn propose_offline(&self, name: XorName) -> Result<Vec<Command>> {
pub fn propose_offline(&self, name: XorName) -> Result<Vec<Command>> {
if let Some(info) = self.section.members().get(&name) {
let info = info.clone().leave()?;

Expand Down
1 change: 1 addition & 0 deletions src/routing/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ impl Dispatcher {
.make_online_proposal(peer, previous_name, their_knowledge)
.await
}
Command::ProposeOffline(name) => self.core.lock().await.propose_offline(name),
}
}

Expand Down
12 changes: 11 additions & 1 deletion src/routing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use crate::{
node::Node,
peer::Peer,
section::{EldersInfo, SectionChain},
TransportConfig, MIN_ADULT_AGE,
Error, TransportConfig, MIN_ADULT_AGE,
};
use bytes::Bytes;
use ed25519_dalek::{Keypair, PublicKey, Signature, Signer, KEYPAIR_LENGTH};
Expand Down Expand Up @@ -166,6 +166,16 @@ impl Routing {
self.dispatcher.clone().handle_commands(command).await
}

/// Starts a proposal that a node has gone offline.
/// This can be done only by an Elder.
pub async fn propose_offline(&self, name: XorName) -> Result<()> {
if !self.is_elder().await {
return Err(Error::InvalidState);
}
let command = Command::ProposeOffline(name);
self.dispatcher.clone().handle_commands(command).await
}

/// Returns the current age of this node.
pub async fn age(&self) -> u8 {
self.dispatcher.core.lock().await.node().age()
Expand Down

0 comments on commit 2937e59

Please sign in to comment.