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

Commit

Permalink
refactor!: remove the Routing state machine
Browse files Browse the repository at this point in the history
The Bootstrapping and Joining states were removed. The bootstrapping/joining process was extracted into a single async function which returns a node that is fully bootstrapped.

BREAKING CHANGE: some methods of `Routing` that previosuly returned `Option<T>` or `Result<T>` now return just T.
  • Loading branch information
madadam committed Oct 20, 2020
1 parent 2cd28a3 commit cfa19ff
Show file tree
Hide file tree
Showing 12 changed files with 774 additions and 837 deletions.
9 changes: 0 additions & 9 deletions src/messages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,6 @@ pub enum VerifyStatus {
Unknown,
}

impl VerifyStatus {
pub fn require_full(self) -> Result<(), Error> {
match self {
Self::Full => Ok(()),
Self::Unknown => Err(Error::UntrustedMessage),
}
}
}

/// Status of an incomming message.
pub enum MessageStatus {
/// Message is useful and should be handled.
Expand Down
12 changes: 11 additions & 1 deletion src/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@

use crate::{crypto, event::Event, peer::Peer, NetworkParams};
use ed25519_dalek::Keypair;
use std::{net::SocketAddr, sync::Arc};
use std::{
fmt::{self, Display, Formatter},
net::SocketAddr,
sync::Arc,
};
use tokio::sync::mpsc;
use xor_name::XorName;

Expand Down Expand Up @@ -58,3 +62,9 @@ impl Node {
}
}
}

impl Display for Node {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(f, "{:<8}", hex_fmt::HexFmt(self.keypair.public.as_bytes()))
}
}
16 changes: 14 additions & 2 deletions src/relocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ use crate::{
network::Network,
section::{MemberInfo, Section},
};

use bytes::Bytes;
use serde::{de::Error as SerdeDeError, Deserialize, Deserializer, Serialize, Serializer};
use std::net::SocketAddr;
use tokio::sync::mpsc;
use xor_name::XorName;

/// Find all nodes to relocate after a churn event and create the relocate actions for them.
Expand Down Expand Up @@ -169,11 +171,21 @@ impl RelocatePayload {
}

#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Serialize, Deserialize)]
pub struct RelocatePromise {
pub(crate) struct RelocatePromise {
pub name: XorName,
pub destination: XorName,
}

pub(crate) enum RelocateState {
// Node is undergoing delayed relocation. This happens when the node is selected for relocation
// while being an elder. It must keep fulfilling its duties as elder until its demoted, then it
// can send the bytes (which are serialized `RelocatePromise` message) back to the elders who
// will exchange it for an actual `Relocate` message.
Delayed(Bytes),
// Relocation in progress. The sender is used to pass messages to the bootstrap task.
InProgress(mpsc::Sender<(Message, SocketAddr)>),
}

/// Action to relocate a node.
pub(crate) enum RelocateAction {
/// Relocate the node instantly.
Expand Down

0 comments on commit cfa19ff

Please sign in to comment.