Austin Schuh | e84c3ed | 2019-12-14 15:29:48 -0800 | [diff] [blame] | 1 | #ifndef AOS_NETWORK_MESSAGE_BRIDGE_PROTOCOL_H_ |
| 2 | #define AOS_NETWORK_MESSAGE_BRIDGE_PROTOCOL_H_ |
| 3 | |
Austin Schuh | 7bc5905 | 2020-02-16 23:48:33 -0800 | [diff] [blame] | 4 | #include <string_view> |
| 5 | |
| 6 | #include "aos/configuration.h" |
| 7 | #include "aos/network/connect_generated.h" |
Austin Schuh | 4385b14 | 2021-03-14 21:31:13 -0700 | [diff] [blame] | 8 | #include "aos/uuid.h" |
Austin Schuh | 7bc5905 | 2020-02-16 23:48:33 -0800 | [diff] [blame] | 9 | |
Austin Schuh | e84c3ed | 2019-12-14 15:29:48 -0800 | [diff] [blame] | 10 | namespace aos { |
| 11 | namespace message_bridge { |
| 12 | |
| 13 | // The protocol between the message_bridge_client and server is pretty simple. |
| 14 | // The overarching design philosophy is that the server sends data to the |
| 15 | // client, and the client (optionally) sends timestamps back. |
| 16 | // |
| 17 | // 1) A connection is established by the client sending the server a Connect |
| 18 | // flatbuffer on stream 0. |
| 19 | // 2) The server then replies with the data, as it is available, on streams 2 + |
| 20 | // channel_id in the Connect message. |
| 21 | // 3) The client (optionally) replies on stream 1 with MessageHeader flatbuffers |
| 22 | // with the timestamps that the messages were received. |
| 23 | // |
| 24 | // Most of the complexity from there is handling multiple clients and servers |
| 25 | // and persuading SCTP to do what we want. |
| 26 | |
| 27 | // Number of streams reserved for control messages. |
| 28 | constexpr size_t kControlStreams() { return 2; } |
| 29 | // The stream on which Connect messages are sent. |
| 30 | constexpr size_t kConnectStream() { return 0; } |
| 31 | // The stream on which timestamp replies are sent. |
| 32 | constexpr size_t kTimestampStream() { return 1; } |
| 33 | |
Austin Schuh | 7bc5905 | 2020-02-16 23:48:33 -0800 | [diff] [blame] | 34 | // Builds up a subscription request for my_node to remote_name. |
| 35 | aos::FlatbufferDetachedBuffer<aos::message_bridge::Connect> MakeConnectMessage( |
| 36 | const Configuration *config, const Node *my_node, |
Austin Schuh | b0e439d | 2023-05-15 10:55:40 -0700 | [diff] [blame^] | 37 | std::string_view remote_name, const UUID &boot_uuid, |
| 38 | std::string_view config_sha256); |
Austin Schuh | 7bc5905 | 2020-02-16 23:48:33 -0800 | [diff] [blame] | 39 | |
Austin Schuh | e84c3ed | 2019-12-14 15:29:48 -0800 | [diff] [blame] | 40 | } // namespace message_bridge |
| 41 | } // namespace aos |
| 42 | |
| 43 | #endif // AOS_NETWORK_MESSAGE_BRIDGE_PROTOCOL_H_ |