blob: 4daf9c7e72150d9e0bcea0d2fec25cc13b287be7 [file] [log] [blame]
Philipp Schrader790cb542023-07-05 21:06:52 -07001#include "gflags/gflags.h"
2#include "glog/logging.h"
3
Austin Schuhe84c3ed2019-12-14 15:29:48 -08004#include "aos/events/shm_event_loop.h"
5#include "aos/init.h"
Sarah Newman45a64df2022-04-11 19:33:46 -07006#include "aos/logging/dynamic_logging.h"
Austin Schuhe84c3ed2019-12-14 15:29:48 -08007#include "aos/network/message_bridge_server_lib.h"
Adam Snaider96a0f4b2023-05-18 20:41:19 -07008#include "aos/network/sctp_lib.h"
Austin Schuhb0e439d2023-05-15 10:55:40 -07009#include "aos/sha256.h"
Austin Schuhe84c3ed2019-12-14 15:29:48 -080010
Austin Schuhc5fa6d92022-02-25 14:36:28 -080011DEFINE_string(config, "aos_config.json", "Path to the config.");
Austin Schuha922ad02021-10-23 23:25:50 -070012DEFINE_int32(rt_priority, -1, "If > 0, run as this RT priority");
Austin Schuhe84c3ed2019-12-14 15:29:48 -080013
Adam Snaider96a0f4b2023-05-18 20:41:19 -070014#if HAS_SCTP_AUTH
15DEFINE_string(sctp_auth_key_file, "",
16 "When set, use the provided key for SCTP authentication as "
17 "defined in RFC 4895");
18#endif
19
Austin Schuhe84c3ed2019-12-14 15:29:48 -080020namespace aos {
21namespace message_bridge {
22
Adam Snaider96a0f4b2023-05-18 20:41:19 -070023using ::aos::util::ReadFileToVecOrDie;
24
Austin Schuhe84c3ed2019-12-14 15:29:48 -080025int Main() {
26 aos::FlatbufferDetachedBuffer<aos::Configuration> config =
27 aos::configuration::ReadConfig(FLAGS_config);
28
29 aos::ShmEventLoop event_loop(&config.message());
Austin Schuha922ad02021-10-23 23:25:50 -070030 if (FLAGS_rt_priority > 0) {
31 event_loop.SetRuntimeRealtimePriority(FLAGS_rt_priority);
32 }
Austin Schuhe84c3ed2019-12-14 15:29:48 -080033
Adam Snaider96a0f4b2023-05-18 20:41:19 -070034 std::vector<uint8_t> auth_key;
35#if HAS_SCTP_AUTH
36 if (!FLAGS_sctp_auth_key_file.empty()) {
37 auth_key = ReadFileToVecOrDie(FLAGS_sctp_auth_key_file);
38 }
39#endif
40 MessageBridgeServer app(&event_loop, Sha256(config.span()),
41 std::move(auth_key));
Austin Schuhe84c3ed2019-12-14 15:29:48 -080042
Sarah Newman45a64df2022-04-11 19:33:46 -070043 logging::DynamicLogging dynamic_logging(&event_loop);
44
Austin Schuhe84c3ed2019-12-14 15:29:48 -080045 // TODO(austin): Track which messages didn't make it in time and need to be
46 // logged locally and forwarded.
47
48 event_loop.Run();
49
50 return EXIT_SUCCESS;
51}
52
53} // namespace message_bridge
54} // namespace aos
55
56int main(int argc, char **argv) {
57 aos::InitGoogle(&argc, &argv);
58
59 return aos::message_bridge::Main();
60}