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
use derive_more::{Display, IsVariant};
use elfo_core::{
addr::{GroupNo, NodeNo},
message, MoveOwnership,
};
use crate::{codec::format::NetworkAddr, socket::Socket};
slotmap::new_key_type! {
#[derive(Display)]
#[display("{:?}", self.0)] // <index>v<version>
pub(crate) struct ConnId;
}
#[message]
pub(crate) struct HandleConnection {
pub(crate) id: ConnId,
pub(crate) local: GroupMeta,
pub(crate) remote: GroupMeta,
pub(crate) socket: MoveOwnership<Socket>,
/// Initial window size of every flow.
pub(crate) initial_window: i32,
// TODO: different windows for rx/tx and routed flows.
}
#[message]
pub(crate) struct AbortConnection {
pub(crate) id: ConnId,
pub(crate) local: GroupMeta,
pub(crate) remote: GroupMeta,
}
#[message]
pub(crate) struct ConnectionFailed {
pub(crate) id: ConnId,
}
#[derive(Display, Copy, IsVariant, PartialEq, Eq)]
#[message(part)]
pub(crate) enum ConnectionRole {
// Only possible if this node is a server.
Unknown,
Control,
#[display("Data({local_group_no}, {remote_group_no})")]
Data {
local_group_no: GroupNo,
remote_group_no: GroupNo,
},
}
#[message(part)]
#[derive(PartialEq, Eq, Hash)]
pub(crate) struct GroupMeta {
pub(crate) node_no: NodeNo,
pub(crate) group_no: GroupNo,
pub(crate) group_name: String,
}
pub(crate) mod internode {
use super::*;
// control connection
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// (client) (server)
// ...
// SwitchToControl -->
// <-- SwitchToControl
// ...
//
// data connection
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// (client) (server)
// ...
// SwitchToData -->
// <-- SwitchToData
// ...
// UpdateFlow -->
// ...
// <-- UpdateFlow
//
// any connection
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// ...
// Ping -->
// <-- Pong
// ...
//
// TODO: close, status changes.
#[message]
pub(crate) struct SwitchToControl {
pub(crate) groups: Vec<GroupInfo>,
}
#[message(part)]
pub(crate) struct GroupInfo {
pub(crate) group_no: GroupNo, // TODO: just `no`?
pub(crate) name: String,
/// Remote group's names that this group is interested in.
pub(crate) interests: Vec<String>,
}
#[message]
pub(crate) struct SwitchToData {
/// Local group's number of a client.
pub(crate) my_group_no: GroupNo,
/// Local group's number of a server.
pub(crate) your_group_no: GroupNo,
/// Initial window size for every flow.
pub(crate) initial_window: i32,
// TODO: different windows for rx/tx and routed flows.
}
#[message]
pub(crate) struct UpdateFlow {
pub(crate) addr: NetworkAddr,
pub(crate) window_delta: i32,
}
#[message]
pub(crate) struct CloseFlow {
pub(crate) addr: NetworkAddr,
}
#[message]
pub(crate) struct Ping {
pub(crate) payload: u64,
}
#[message]
pub(crate) struct Pong {
pub(crate) payload: u64,
}
}