Rework SCTP auth pipeline to allow dynamic key change
The SCTP key sharing mechanism won't be using a file to communicate
the active authentication key anymore as we will be receiving
it directly into message bridge through an AOS channel instead.
Change-Id: I46e079b98cbb6a0ed52fca36c67f7fa724ba249c
Signed-off-by: James Kuszmaul <james.kuszmaul@bluerivertech.com>
diff --git a/aos/network/sctp_perf.cc b/aos/network/sctp_perf.cc
index 3bafed1..5201f47 100644
--- a/aos/network/sctp_perf.cc
+++ b/aos/network/sctp_perf.cc
@@ -22,11 +22,9 @@
DEFINE_uint32(skip_first_n, 10,
"Skip the first 'n' messages when computing statistics.");
-#if HAS_SCTP_AUTH
DEFINE_string(sctp_auth_key_file, "",
"When set, use the provided key for SCTP authentication as "
"defined in RFC 4895");
-#endif
DECLARE_bool(die_on_malloc);
@@ -36,13 +34,16 @@
using util::ReadFileToVecOrDie;
+SctpAuthMethod SctpAuthMethod() {
+ return FLAGS_sctp_auth_key_file.empty() ? SctpAuthMethod::kNoAuth
+ : SctpAuthMethod::kAuth;
+}
+
std::vector<uint8_t> GetSctpAuthKey() {
-#if HAS_SCTP_AUTH
- if (!FLAGS_sctp_auth_key_file.empty()) {
- return ReadFileToVecOrDie(FLAGS_sctp_auth_key_file);
+ if (SctpAuthMethod() == SctpAuthMethod::kNoAuth) {
+ return {};
}
-#endif
- return {};
+ return ReadFileToVecOrDie(FLAGS_sctp_auth_key_file);
}
} // namespace
@@ -53,7 +54,8 @@
public:
Server(aos::ShmEventLoop *event_loop)
: event_loop_(event_loop),
- server_(2, "0.0.0.0", FLAGS_port, GetSctpAuthKey()) {
+ server_(2, "0.0.0.0", FLAGS_port, SctpAuthMethod()) {
+ server_.SetAuthKey(GetSctpAuthKey());
event_loop_->epoll()->OnReadable(server_.fd(),
[this]() { MessageReceived(); });
server_.SetMaxReadSize(FLAGS_rx_size + 100);
@@ -134,7 +136,8 @@
Client(aos::ShmEventLoop *event_loop)
: event_loop_(event_loop),
client_(FLAGS_host, FLAGS_port, 2, "0.0.0.0", FLAGS_port,
- GetSctpAuthKey()) {
+ SctpAuthMethod()) {
+ client_.SetAuthKey(GetSctpAuthKey());
client_.SetMaxReadSize(FLAGS_rx_size + 100);
client_.SetMaxWriteSize(FLAGS_rx_size + 100);