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
use crate::{
lib::{
fmt::{self, Display, Formatter},
Vec,
},
Address, Route,
};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)]
pub struct TransportMessage {
pub version: u8,
pub onward_route: Route,
pub return_route: Route,
pub payload: Vec<u8>,
}
impl TransportMessage {
pub fn v1(onward_route: Route, payload: Vec<u8>) -> Self {
Self {
version: 1,
onward_route,
return_route: Route::new().into(),
payload,
}
}
}
impl Display for TransportMessage {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
write!(
f,
"Message (onward route: {}, return route: {})",
self.onward_route, self.return_route
)
}
}
#[derive(Serialize, Deserialize, Debug, Clone, Hash, Ord, PartialOrd, Eq, PartialEq)]
pub enum RouterMessage {
Route(TransportMessage),
Register {
accepts: Address,
self_addr: Address,
},
}