use super::{section::NodeState, signed::KeyedSig};
use crate::messaging::SectionAuthorityProvider;
use ed25519_dalek::{PublicKey, Signature};
use hex_fmt::HexFmt;
use serde::{Deserialize, Serialize};
use std::{borrow::Borrow, collections::BTreeSet, fmt, ops::Deref};
use xor_name::{Prefix, XorName};
type Digest256 = [u8; 32];
#[derive(Copy, Clone, Eq, PartialEq, Hash, Serialize, Deserialize, custom_debug::Debug)]
pub struct DkgSessionId {
#[debug(with = "Self::fmt_hash")]
pub hash: Digest256,
pub generation: u64,
}
impl DkgSessionId {
fn fmt_hash(hash: &Digest256, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:0.10}", HexFmt(hash))
}
}
#[derive(Copy, Clone, Eq, PartialEq, Serialize, Deserialize, custom_debug::Debug)]
pub struct DkgFailureSig {
#[allow(missing_docs)]
#[debug(with = "crate::types::PublicKey::fmt_ed25519")]
pub public_key: PublicKey,
#[allow(missing_docs)]
#[debug(with = "crate::types::Signature::fmt_ed25519")]
pub signature: Signature,
}
#[derive(Default, Clone, Eq, PartialEq, Debug, Serialize, Deserialize)]
pub struct DkgFailureSigSet {
#[allow(missing_docs)]
pub sigs: Vec<DkgFailureSig>,
#[allow(missing_docs)]
pub failed_participants: BTreeSet<XorName>,
}
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Serialize, Deserialize)]
pub struct SectionAuth<T: Serialize> {
pub value: T,
pub sig: KeyedSig,
}
impl<T> Borrow<Prefix> for SectionAuth<T>
where
T: Borrow<Prefix> + Serialize,
{
fn borrow(&self) -> &Prefix {
self.value.borrow()
}
}
impl<T: Serialize> Deref for SectionAuth<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.value
}
}
#[derive(Clone, Eq, PartialEq, Debug, Serialize, Deserialize)]
#[allow(clippy::large_enum_variant)]
pub enum Proposal {
Offline(NodeState),
SectionInfo(SectionAuthorityProvider),
OurElders(SectionAuth<SectionAuthorityProvider>),
JoinsAllowed(bool),
}