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