use super::agreement::SectionAuth;
use crate::messaging::system::{NodeState, SigShare};
use crate::messaging::{system::KeyedSig, SectionAuthorityProvider};
use bls::PublicKey as BlsPublicKey;
use ed25519_dalek::Signature;
use secured_linked_list::SecuredLinkedList;
use serde::{Deserialize, Serialize};
use std::{collections::VecDeque, net::SocketAddr};
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct JoinRequest {
pub section_key: BlsPublicKey,
pub resource_proof_response: Option<ResourceProofResponse>,
pub aggregated: Option<SectionAuth<NodeState>>,
}
#[derive(Clone, Eq, PartialEq, Serialize, Deserialize, custom_debug::Debug)]
pub struct ResourceProofResponse {
#[allow(missing_docs)]
pub solution: u64,
#[allow(missing_docs)]
#[debug(skip)]
pub data: VecDeque<u8>,
#[allow(missing_docs)]
#[debug(skip)]
pub nonce: [u8; 32],
#[allow(missing_docs)]
#[debug(with = "crate::types::Signature::fmt_ed25519")]
pub nonce_signature: Signature,
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
#[allow(clippy::large_enum_variant)]
pub enum JoinResponse {
ResourceChallenge {
#[allow(missing_docs)]
data_size: usize,
difficulty: u8,
#[allow(missing_docs)]
nonce: [u8; 32],
#[allow(missing_docs)]
nonce_signature: Signature,
},
Retry {
section_auth: SectionAuthorityProvider,
section_signed: KeyedSig,
proof_chain: SecuredLinkedList,
expected_age: u8,
},
Redirect(SectionAuthorityProvider),
ApprovalShare {
node_state: NodeState,
sig_share: SigShare,
},
Approval {
genesis_key: BlsPublicKey,
section_auth: SectionAuth<SectionAuthorityProvider>,
node_state: SectionAuth<NodeState>,
section_chain: SecuredLinkedList,
},
Rejected(JoinRejectionReason),
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub enum JoinRejectionReason {
JoinsDisallowed,
NodeNotReachable(SocketAddr),
}