mod dkg;
mod join;
mod node_msgs;
mod section_sig;
use crate::messaging::AuthorityProof;
use crate::network_knowledge::node_state::RelocationTrigger;
use crate::network_knowledge::{NodeState, RelocationProof, SapCandidate};
use crate::SectionAuthorityProvider;
pub use dkg::DkgSessionId;
pub use join::JoinResponse;
pub use node_msgs::{NodeDataCmd, NodeEvent, NodeQueryResponse};
pub use section_sig::{SectionSig, SectionSigShare, SectionSigned};
use sn_consensus::{Decision, Generation, SignedVote};
use sn_sdkg::DkgSignedVote;
use bls::PublicKey as BlsPublicKey;
use ed25519::Signature;
use serde::{Deserialize, Serialize};
use std::{
collections::BTreeMap,
fmt::{Display, Formatter},
};
use xor_name::XorName;
pub type SectionDecisions = Vec<Decision<NodeState>>;
#[derive(Clone, PartialEq, Serialize, Deserialize, custom_debug::Debug)]
#[allow(clippy::large_enum_variant, clippy::derive_partial_eq_without_eq)]
pub enum NodeMsg {
PrepareToRelocate(RelocationTrigger),
ProceedRelocation(RelocationTrigger),
CompleteRelocation(SectionSigned<NodeState>),
MembershipVotes(Vec<SignedVote<NodeState>>),
MembershipAE(Generation),
TryJoin(Option<RelocationProof>),
JoinResponse(JoinResponse),
DkgStart(DkgSessionId, SectionSigShare),
DkgEphemeralPubKey {
session_id: DkgSessionId,
section_auth: AuthorityProof<SectionSig>,
pub_key: BlsPublicKey,
sig: Signature,
},
DkgVotes {
session_id: DkgSessionId,
pub_keys: BTreeMap<XorName, (BlsPublicKey, Signature)>,
votes: Vec<DkgSignedVote>,
},
DkgAE(DkgSessionId),
RequestHandover {
sap: SectionAuthorityProvider,
sig_share: SectionSigShare,
},
HandoverVotes(Vec<SignedVote<SapCandidate>>),
HandoverAE(Generation),
SectionHandoverPromotion {
sap: SectionSigned<SectionAuthorityProvider>,
sig_share: SectionSigShare,
},
SectionSplitPromotion {
sap0: SectionSigned<SectionAuthorityProvider>,
sig_share0: SectionSigShare,
sap1: SectionSigned<SectionAuthorityProvider>,
sig_share1: SectionSigShare,
},
ProposeNodeOff {
vote_node_off: NodeState,
sig_share: SectionSigShare,
},
NodeEvent(NodeEvent),
NodeDataCmd(NodeDataCmd),
}
impl NodeMsg {
pub fn is_join(&self) -> bool {
matches!(self, NodeMsg::TryJoin(_))
}
}
impl Display for NodeMsg {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::PrepareToRelocate { .. } => write!(f, "NodeMsg::PrepareToRelocate"),
Self::ProceedRelocation { .. } => write!(f, "NodeMsg::ProceedRelocation"),
Self::CompleteRelocation { .. } => write!(f, "NodeMsg::CompleteRelocation"),
Self::MembershipVotes { .. } => write!(f, "NodeMsg::MembershipVotes"),
Self::MembershipAE { .. } => write!(f, "NodeMsg::MembershipAE"),
Self::TryJoin(_) => write!(f, "NodeMsg::TryJoin"),
Self::JoinResponse { .. } => write!(f, "NodeMsg::JoinResponse"),
Self::DkgStart { .. } => write!(f, "NodeMsg::DkgStart"),
Self::DkgEphemeralPubKey { .. } => write!(f, "NodeMsg::DkgEphemeralPubKey"),
Self::DkgVotes { .. } => write!(f, "NodeMsg::DkgVotes"),
Self::DkgAE { .. } => write!(f, "NodeMsg::DkgAE"),
Self::RequestHandover { .. } => write!(f, "NodeMsg::RequestHandover"),
Self::HandoverVotes { .. } => write!(f, "NodeMsg::HandoverVotes"),
Self::HandoverAE { .. } => write!(f, "NodeMsg::HandoverAE"),
Self::SectionHandoverPromotion { .. } => write!(f, "NodeMsg::SectionHandoverPromotion"),
Self::SectionSplitPromotion { .. } => write!(f, "NodeMsg::SectionSplitPromotion"),
Self::ProposeNodeOff { .. } => write!(f, "NodeMsg::ProposeSectionState"),
Self::NodeEvent { .. } => write!(f, "NodeMsg::NodeEvent"),
Self::NodeDataCmd { .. } => write!(f, "NodeMsg::NodeCmd"),
}
}
}