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
use elfo_core::{
    _priv::{GroupNo, NodeNo},
    message, MoveOwnership,
};

use crate::{codec::format::NetworkAddr, config::Transport, socket::Socket};

// Internal.

#[message]
pub(crate) struct HandleConnection {
    pub(crate) local: GroupInfo,
    pub(crate) remote: GroupInfo,
    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.
    pub(crate) transport: Option<Transport>,
}

#[message]
pub(crate) struct DataConnectionFailed {
    pub(crate) transport: Transport,
    pub(crate) local: GroupNo,
    pub(crate) remote: (NodeNo, GroupNo),
}

#[message(part)]
#[derive(PartialEq, Eq, Hash)]
pub(crate) struct GroupInfo {
    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,
    }
}