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
mod agreement;
mod join;
mod join_as_relocated;
mod network;
mod node_msg;
mod plain_message;
mod prefix_map;
mod relocation;
mod section;
mod signature_aggregator;
mod signed;
mod src_authority;
mod variant;
pub use agreement::{DkgFailureSigned, DkgFailureSignedSet, DkgKey, Proposal, SectionSigned};
pub use join::{JoinRejectionReason, JoinRequest, JoinResponse, ResourceProofResponse};
pub use join_as_relocated::{JoinAsRelocatedRequest, JoinAsRelocatedResponse};
pub use network::{Network, OtherSection};
pub use node_msg::{
NodeCmd, NodeCmdError, NodeDataError, NodeDataQueryResponse, NodeEvent, NodeMsg, NodeQuery,
NodeQueryResponse, NodeRewardQuery, NodeSystemCmd, NodeSystemQuery, NodeSystemQueryResponse,
NodeTransferCmd, NodeTransferError, NodeTransferQuery, NodeTransferQueryResponse,
};
pub use plain_message::PlainMessage;
pub use prefix_map::PrefixMap;
pub use relocation::{RelocateDetails, RelocatePayload, RelocatePromise, SignedRelocateDetails};
pub use section::{ElderCandidates, MembershipState, NodeState, Peer, Section, SectionPeers};
pub use signature_aggregator::{Error, SignatureAggregator};
pub use signed::{Signed, SignedShare};
pub use src_authority::SrcAuthority;
pub use variant::Variant;
use crate::{Aggregation, DstLocation, MessageId, MessageType, WireMsg};
use bytes::Bytes;
use serde::{Deserialize, Serialize};
use std::fmt::{self, Debug, Formatter};
use threshold_crypto::PublicKey as BlsPublicKey;
use xor_name::XorName;
#[derive(Clone, Eq, Serialize, Deserialize)]
pub struct RoutingMsg {
pub id: MessageId,
pub src: SrcAuthority,
pub dst: DstLocation,
pub aggregation: Aggregation,
pub variant: Variant,
pub section_pk: BlsPublicKey,
}
impl RoutingMsg {
pub fn from(bytes: Bytes) -> crate::Result<Self> {
let deserialized = WireMsg::deserialize(bytes)?;
if let MessageType::Routing { msg, .. } = deserialized {
Ok(msg)
} else {
Err(crate::Error::FailedToParse(
"bytes as a node message".to_string(),
))
}
}
pub fn serialize(&self, dest: XorName, dest_section_pk: BlsPublicKey) -> crate::Result<Bytes> {
WireMsg::serialize_routing_msg(self, dest, dest_section_pk)
}
}
impl PartialEq for RoutingMsg {
fn eq(&self, other: &RoutingMsg) -> bool {
self.src == other.src
&& self.dst == other.dst
&& self.id == other.id
&& self.variant == other.variant
&& self.section_pk == other.section_pk
}
}
impl Debug for RoutingMsg {
fn fmt(&self, formatter: &mut Formatter) -> fmt::Result {
formatter
.debug_struct("RoutingMsg")
.field("id", &self.id)
.field("src", &self.src)
.field("dst", &self.dst)
.field("variant", &self.variant)
.finish()
}
}