blob: 078346620701449b295c7e3819a090d64b33f73b [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
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -080010namespace aos::message_bridge {
Austin Schuhe84c3ed2019-12-14 15:29:48 -080011
12// The protocol between the message_bridge_client and server is pretty simple.
13// The overarching design philosophy is that the server sends data to the
14// client, and the client (optionally) sends timestamps back.
15//
16// 1) A connection is established by the client sending the server a Connect
17// flatbuffer on stream 0.
18// 2) The server then replies with the data, as it is available, on streams 2 +
19// channel_id in the Connect message.
20// 3) The client (optionally) replies on stream 1 with MessageHeader flatbuffers
21// with the timestamps that the messages were received.
22//
23// Most of the complexity from there is handling multiple clients and servers
24// and persuading SCTP to do what we want.
25
26// Number of streams reserved for control messages.
27constexpr size_t kControlStreams() { return 2; }
28// The stream on which Connect messages are sent.
29constexpr size_t kConnectStream() { return 0; }
30// The stream on which timestamp replies are sent.
31constexpr size_t kTimestampStream() { return 1; }
32
Austin Schuh7712c582023-05-15 14:39:58 -070033// Overhead constant for headers. Both remote timestamps and the extra context
34// inside RemoteData need to fit inside this.
35constexpr size_t kHeaderSizeOverhead() { return 208u; }
36
Austin Schuh7bc59052020-02-16 23:48:33 -080037// Builds up a subscription request for my_node to remote_name.
38aos::FlatbufferDetachedBuffer<aos::message_bridge::Connect> MakeConnectMessage(
39 const Configuration *config, const Node *my_node,
Austin Schuhb0e439d2023-05-15 10:55:40 -070040 std::string_view remote_name, const UUID &boot_uuid,
41 std::string_view config_sha256);
Austin Schuh7bc59052020-02-16 23:48:33 -080042
Stephan Pleinesd99b1ee2024-02-02 20:56:44 -080043} // namespace aos::message_bridge
Austin Schuhe84c3ed2019-12-14 15:29:48 -080044
45#endif // AOS_NETWORK_MESSAGE_BRIDGE_PROTOCOL_H_