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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
mod wire_msg;
mod wire_msg_header;
use xor_name::XorName;
pub(crate) const DKG_MSG_PRIORITY: i32 = 3;
pub(crate) const AE_MSG_PRIORITY: i32 = 2;
pub(crate) const INFRASTRUCTURE_MSG_PRIORITY: i32 = 1;
pub(crate) const NODE_DATA_MSG_PRIORITY: i32 = 0;
pub(crate) const SERVICE_MSG_PRIORITY: i32 = -2;
pub(crate) const JOIN_RESPONSE_PRIORITY: i32 = -5;
use crate::types::PublicKey;
pub use self::wire_msg::WireMsg;
use super::{
data::ServiceMsg, system::SystemMsg, AuthorityProof, BlsShareAuth, DstLocation, MessageId,
NodeAuth, SectionAuth, ServiceAuth,
};
#[derive(PartialEq, Debug, Clone)]
#[allow(clippy::large_enum_variant)]
pub enum MessageType {
Service {
msg_id: MessageId,
auth: AuthorityProof<ServiceAuth>,
dst_location: DstLocation,
msg: ServiceMsg,
},
System {
msg_id: MessageId,
msg_authority: NodeMsgAuthority,
dst_location: DstLocation,
msg: SystemMsg,
},
}
impl MessageType {
pub fn priority(&self) -> i32 {
match self {
MessageType::System {
msg: SystemMsg::JoinResponse(_) | SystemMsg::JoinAsRelocatedResponse(_),
..
} => JOIN_RESPONSE_PRIORITY,
MessageType::System {
msg:
SystemMsg::DkgStart { .. }
| SystemMsg::DkgSessionUnknown { .. }
| SystemMsg::DkgSessionInfo { .. }
| SystemMsg::DkgNotReady { .. }
| SystemMsg::DkgRetry { .. }
| SystemMsg::DkgMessage { .. }
| SystemMsg::DkgFailureObservation { .. }
| SystemMsg::DkgFailureAgreement(_),
..
} => DKG_MSG_PRIORITY,
MessageType::System {
msg:
SystemMsg::AntiEntropyRetry { .. }
| SystemMsg::AntiEntropyRedirect { .. }
| SystemMsg::AntiEntropyUpdate { .. }
| SystemMsg::AntiEntropyProbe(_)
| SystemMsg::BackPressure(_)
| SystemMsg::Relocate(_)
| SystemMsg::RelocatePromise(_)
| SystemMsg::JoinRequest(_)
| SystemMsg::JoinAsRelocatedRequest(_)
| SystemMsg::Propose { .. }
| SystemMsg::StartConnectivityTest(_),
..
} => INFRASTRUCTURE_MSG_PRIORITY,
MessageType::System {
msg:
SystemMsg::NodeCmd(_)
| SystemMsg::NodeQuery(_)
| SystemMsg::NodeQueryResponse { .. }
| SystemMsg::NodeMsgError { .. },
..
} => NODE_DATA_MSG_PRIORITY,
MessageType::Service { .. } => SERVICE_MSG_PRIORITY,
}
}
}
#[derive(PartialEq, Debug, Clone)]
pub enum NodeMsgAuthority {
Node(AuthorityProof<NodeAuth>),
BlsShare(AuthorityProof<BlsShareAuth>),
Section(AuthorityProof<SectionAuth>),
}
impl NodeMsgAuthority {
pub(crate) fn get_auth_xorname(&self) -> XorName {
match self.clone() {
NodeMsgAuthority::BlsShare(auth_proof) => {
let auth = auth_proof.into_inner();
auth.src_name
}
NodeMsgAuthority::Node(auth_proof) => {
let auth = auth_proof.into_inner();
let pk = auth.public_key;
XorName::from(PublicKey::from(pk))
}
NodeMsgAuthority::Section(auth_proof) => {
let auth = auth_proof.into_inner();
auth.src_name
}
}
}
}