Austin Schuh | e84c3ed | 2019-12-14 15:29:48 -0800 | [diff] [blame] | 1 | #include "aos/events/shm_event_loop.h" |
| 2 | #include "aos/init.h" |
Sarah Newman | 45a64df | 2022-04-11 19:33:46 -0700 | [diff] [blame] | 3 | #include "aos/logging/dynamic_logging.h" |
Austin Schuh | 60e7794 | 2022-05-16 17:48:24 -0700 | [diff] [blame] | 4 | #include "aos/network/message_bridge_client_lib.h" |
Adam Snaider | 96a0f4b | 2023-05-18 20:41:19 -0700 | [diff] [blame^] | 5 | #include "aos/network/sctp_lib.h" |
Austin Schuh | b0e439d | 2023-05-15 10:55:40 -0700 | [diff] [blame] | 6 | #include "aos/sha256.h" |
Adam Snaider | 96a0f4b | 2023-05-18 20:41:19 -0700 | [diff] [blame^] | 7 | #include "aos/util/file.h" |
Austin Schuh | e84c3ed | 2019-12-14 15:29:48 -0800 | [diff] [blame] | 8 | |
Austin Schuh | c5fa6d9 | 2022-02-25 14:36:28 -0800 | [diff] [blame] | 9 | DEFINE_string(config, "aos_config.json", "Path to the config."); |
Austin Schuh | a922ad0 | 2021-10-23 23:25:50 -0700 | [diff] [blame] | 10 | DEFINE_int32(rt_priority, -1, "If > 0, run as this RT priority"); |
Austin Schuh | e84c3ed | 2019-12-14 15:29:48 -0800 | [diff] [blame] | 11 | |
Adam Snaider | 96a0f4b | 2023-05-18 20:41:19 -0700 | [diff] [blame^] | 12 | #if HAS_SCTP_AUTH |
| 13 | DEFINE_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 Schuh | e84c3ed | 2019-12-14 15:29:48 -0800 | [diff] [blame] | 18 | namespace aos { |
| 19 | namespace message_bridge { |
| 20 | |
Adam Snaider | 96a0f4b | 2023-05-18 20:41:19 -0700 | [diff] [blame^] | 21 | using ::aos::util::ReadFileToVecOrDie; |
| 22 | |
Austin Schuh | e84c3ed | 2019-12-14 15:29:48 -0800 | [diff] [blame] | 23 | int Main() { |
| 24 | aos::FlatbufferDetachedBuffer<aos::Configuration> config = |
| 25 | aos::configuration::ReadConfig(FLAGS_config); |
| 26 | |
| 27 | aos::ShmEventLoop event_loop(&config.message()); |
Austin Schuh | a922ad0 | 2021-10-23 23:25:50 -0700 | [diff] [blame] | 28 | if (FLAGS_rt_priority > 0) { |
| 29 | event_loop.SetRuntimeRealtimePriority(FLAGS_rt_priority); |
| 30 | } |
Austin Schuh | e84c3ed | 2019-12-14 15:29:48 -0800 | [diff] [blame] | 31 | |
Adam Snaider | 96a0f4b | 2023-05-18 20:41:19 -0700 | [diff] [blame^] | 32 | 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 Schuh | e84c3ed | 2019-12-14 15:29:48 -0800 | [diff] [blame] | 40 | |
Sarah Newman | 45a64df | 2022-04-11 19:33:46 -0700 | [diff] [blame] | 41 | logging::DynamicLogging dynamic_logging(&event_loop); |
Austin Schuh | e84c3ed | 2019-12-14 15:29:48 -0800 | [diff] [blame] | 42 | // 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 | |
| 55 | int main(int argc, char **argv) { |
| 56 | aos::InitGoogle(&argc, &argv); |
| 57 | |
| 58 | return aos::message_bridge::Main(); |
| 59 | } |