blob: d0a28a1a4344435d4a3cb0e287361f08a49d8f7d [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 Schuh5e2bfb82021-03-13 22:46:55 -080037 std::string_view remote_name, const UUID &boot_uuid);
Austin Schuh7bc59052020-02-16 23:48:33 -080038
Austin Schuhe84c3ed2019-12-14 15:29:48 -080039} // namespace message_bridge
40} // namespace aos
41
42#endif // AOS_NETWORK_MESSAGE_BRIDGE_PROTOCOL_H_