1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
use super::{agreement::SectionSigned, section::NodeState};
use crate::SectionAuthorityProvider;
use ed25519_dalek::Signature;
use secured_linked_list::SecuredLinkedList;
use serde::{Deserialize, Serialize};
use std::{
collections::VecDeque,
fmt::{self, Debug, Formatter},
net::SocketAddr,
};
use threshold_crypto::PublicKey as BlsPublicKey;
#[derive(Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct JoinRequest {
pub section_key: BlsPublicKey,
pub resource_proof_response: Option<ResourceProofResponse>,
}
impl Debug for JoinRequest {
fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
formatter
.debug_struct("JoinRequest")
.field("section_key", &self.section_key)
.field(
"resource_proof_response",
&self
.resource_proof_response
.as_ref()
.map(|proof| proof.solution),
)
.finish()
}
}
#[derive(Clone, Eq, PartialEq, Serialize, Deserialize)]
pub struct ResourceProofResponse {
pub solution: u64,
pub data: VecDeque<u8>,
pub nonce: [u8; 32],
pub nonce_signature: Signature,
}
#[allow(clippy::large_enum_variant)]
#[derive(Clone, Eq, PartialEq, Serialize, Deserialize)]
pub enum JoinResponse {
ResourceChallenge {
data_size: usize,
difficulty: u8,
nonce: [u8; 32],
nonce_signature: Signature,
},
Retry(SectionAuthorityProvider),
Redirect(SectionAuthorityProvider),
Approval {
genesis_key: BlsPublicKey,
section_auth: SectionSigned<SectionAuthorityProvider>,
node_state: SectionSigned<NodeState>,
section_chain: SecuredLinkedList,
},
Rejected(JoinRejectionReason),
}
impl Debug for JoinResponse {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
match self {
Self::ResourceChallenge {
data_size,
difficulty,
..
} => f
.debug_struct("ResourceChallenge")
.field("data_size", data_size)
.field("difficulty", difficulty)
.finish(),
Self::Retry(section_auth) => write!(f, "Retry({:?})", section_auth),
Self::Redirect(section_auth) => write!(f, "Redirect({:?})", section_auth),
Self::Approval {
genesis_key,
section_auth,
node_state,
section_chain,
} => f
.debug_struct("Approval")
.field("genesis_key", genesis_key)
.field("section_auth", section_auth)
.field("node_state", node_state)
.field("section_chain", section_chain)
.finish(),
Self::Rejected(reason) => write!(f, "Rejected({:?})", reason),
}
}
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub enum JoinRejectionReason {
JoinsDisallowed,
NodeNotReachable(SocketAddr),
}