blob: afe2a90c5c22c0c79c280118430db6c4c7f60312 [file] [log] [blame]
Austin Schuhe84c3ed2019-12-14 15:29:48 -08001#include "aos/events/shm_event_loop.h"
2#include "aos/init.h"
Sarah Newman45a64df2022-04-11 19:33:46 -07003#include "aos/logging/dynamic_logging.h"
Austin Schuh60e77942022-05-16 17:48:24 -07004#include "aos/network/message_bridge_client_lib.h"
Adam Snaider96a0f4b2023-05-18 20:41:19 -07005#include "aos/network/sctp_lib.h"
Austin Schuhb0e439d2023-05-15 10:55:40 -07006#include "aos/sha256.h"
Adam Snaider96a0f4b2023-05-18 20:41:19 -07007#include "aos/util/file.h"
Austin Schuhe84c3ed2019-12-14 15:29:48 -08008
Austin Schuhc5fa6d92022-02-25 14:36:28 -08009DEFINE_string(config, "aos_config.json", "Path to the config.");
Austin Schuha922ad02021-10-23 23:25:50 -070010DEFINE_int32(rt_priority, -1, "If > 0, run as this RT priority");
Austin Schuhe84c3ed2019-12-14 15:29:48 -080011
Adam Snaider96a0f4b2023-05-18 20:41:19 -070012#if HAS_SCTP_AUTH
13DEFINE_string(sctp_auth_key_file, "",
14 "When set, use the provided key for SCTP authentication as "
15 "defined in RFC 4895. The file should be binary-encoded");
16#endif
17
Austin Schuhe84c3ed2019-12-14 15:29:48 -080018namespace aos {
19namespace message_bridge {
20
Adam Snaider96a0f4b2023-05-18 20:41:19 -070021using ::aos::util::ReadFileToVecOrDie;
22
Austin Schuhe84c3ed2019-12-14 15:29:48 -080023int Main() {
24 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
25 aos::configuration::ReadConfig(FLAGS_config);
26
27 aos::ShmEventLoop event_loop(&config.message());
Austin Schuha922ad02021-10-23 23:25:50 -070028 if (FLAGS_rt_priority > 0) {
29 event_loop.SetRuntimeRealtimePriority(FLAGS_rt_priority);
30 }
Austin Schuhe84c3ed2019-12-14 15:29:48 -080031
Adam Snaider96a0f4b2023-05-18 20:41:19 -070032 std::vector<uint8_t> auth_key;
33#if HAS_SCTP_AUTH
34 if (!FLAGS_sctp_auth_key_file.empty()) {
35 auth_key = ReadFileToVecOrDie(FLAGS_sctp_auth_key_file);
36 }
37#endif
38 MessageBridgeClient app(&event_loop, Sha256(config.span()),
39 std::move(auth_key));
Austin Schuhe84c3ed2019-12-14 15:29:48 -080040
Sarah Newman45a64df2022-04-11 19:33:46 -070041 logging::DynamicLogging dynamic_logging(&event_loop);
Austin Schuhe84c3ed2019-12-14 15:29:48 -080042 // TODO(austin): Save messages into a vector to be logged. One file per
43 // channel? Need to sort out ordering.
44 //
45 // TODO(austin): Low priority, "reliable" logging channel.
46
47 event_loop.Run();
48
49 return EXIT_SUCCESS;
50}
51
52} // namespace message_bridge
53} // namespace aos
54
55int main(int argc, char **argv) {
56 aos::InitGoogle(&argc, &argv);
57
58 return aos::message_bridge::Main();
59}