blob: 485defeb1164b09640255c681324cba45bb4c6ba [file] [log] [blame]
Austin Schuhe84c3ed2019-12-14 15:29:48 -08001#ifndef AOS_NETWORK_MESSAGE_BRIDGE_PROTOCOL_H_
2#define AOS_NETWORK_MESSAGE_BRIDGE_PROTOCOL_H_
3
Austin Schuh7bc59052020-02-16 23:48:33 -08004#include <string_view>
5
6#include "aos/configuration.h"
7#include "aos/network/connect_generated.h"
Austin Schuh4385b142021-03-14 21:31:13 -07008#include "aos/uuid.h"
Austin Schuh7bc59052020-02-16 23:48:33 -08009
Austin Schuhe84c3ed2019-12-14 15:29:48 -080010namespace aos {
11namespace 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.
28constexpr size_t kControlStreams() { return 2; }
29// The stream on which Connect messages are sent.
30constexpr size_t kConnectStream() { return 0; }
31// The stream on which timestamp replies are sent.
32constexpr size_t kTimestampStream() { return 1; }
33
Austin Schuh7bc59052020-02-16 23:48:33 -080034// Builds up a subscription request for my_node to remote_name.
35aos::FlatbufferDetachedBuffer<aos::message_bridge::Connect> MakeConnectMessage(
36 const Configuration *config, const Node *my_node,
Austin Schuhb0e439d2023-05-15 10:55:40 -070037 std::string_view remote_name, const UUID &boot_uuid,
38 std::string_view config_sha256);
Austin Schuh7bc59052020-02-16 23:48:33 -080039
Austin Schuhe84c3ed2019-12-14 15:29:48 -080040} // namespace message_bridge
41} // namespace aos
42
43#endif // AOS_NETWORK_MESSAGE_BRIDGE_PROTOCOL_H_