From 34a19c97e27766c3c956ad29291037316bceabcc Mon Sep 17 00:00:00 2001 From: melpon Date: Mon, 28 Oct 2024 21:47:34 +0900 Subject: [PATCH] =?UTF-8?q?SoraSignalingConfig=20=E3=81=AB=20forwarding=5F?= =?UTF-8?q?filters=20=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGES.md | 4 +++ include/sora/sora_signaling.h | 5 ++- src/sora_signaling.cpp | 23 +++++++++++-- test/.testparam.example.json | 35 +++++++++++++++++++ test/hello.cpp | 63 ++++++++++++++++++++++++++++------- test/hello.h | 1 + 6 files changed, 115 insertions(+), 16 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index cc704210..e58cf15e 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -48,6 +48,10 @@ - @melpon - [ADD] SoraSignalingConfig::DataChennel に header を追加 - @melpon +- [ADD] SoraSignalingConfig::ForwardingFilter に name と priority を追加 + - @melpon +- [ADD] SoraSignalingConfig に forwarding_filters を追加 + - @melpon - [FIX] HTTP Proxy 利用時の Websocket 初期化で insecure_ メンバ変数が初期化されていなかったのを修正 - @melpon - [FIX] SoraSignalingConfig の client_cert と client_key に渡す必要がある値を、ファイルパスからファイルの内容に修正 diff --git a/include/sora/sora_signaling.h b/include/sora/sora_signaling.h index 783dc35b..3751e954 100644 --- a/include/sora/sora_signaling.h +++ b/include/sora/sora_signaling.h @@ -124,6 +124,8 @@ struct SoraSignalingConfig { std::vector data_channels; struct ForwardingFilter { + std::optional name; + std::optional priority; boost::optional action; struct Rule { std::string field; @@ -134,7 +136,8 @@ struct SoraSignalingConfig { boost::optional version; boost::optional metadata; }; - boost::optional forwarding_filter; + std::optional forwarding_filter; + std::optional> forwarding_filters; std::optional client_cert; std::optional client_key; diff --git a/src/sora_signaling.cpp b/src/sora_signaling.cpp index b1d2d963..1a7a2026 100644 --- a/src/sora_signaling.cpp +++ b/src/sora_signaling.cpp @@ -390,9 +390,14 @@ void SoraSignaling::DoSendConnect(bool redirect) { m["data_channels"] = ar; } - if (config_.forwarding_filter) { + auto forwarding_filter_to_json = [](const SoraSignalingConfig::ForwardingFilter& f) -> boost::json::value { boost::json::object obj; - auto& f = *config_.forwarding_filter; + if (f.name) { + obj["name"] = *f.name; + } + if (f.priority) { + obj["priority"] = *f.priority; + } if (f.action) { obj["action"] = *f.action; } @@ -417,7 +422,19 @@ void SoraSignaling::DoSendConnect(bool redirect) { if (f.metadata) { obj["metadata"] = *f.metadata; } - m["forwarding_filter"] = obj; + return obj; + }; + + if (config_.forwarding_filter) { + m["forwarding_filter"] = forwarding_filter_to_json(*config_.forwarding_filter); + } + + if (config_.forwarding_filters) { + boost::json::array ar; + for (const auto& f : *config_.forwarding_filters) { + ar.push_back(forwarding_filter_to_json(f)); + } + m["forwarding_filters"] = ar; } std::string text = boost::json::serialize(m); diff --git a/test/.testparam.example.json b/test/.testparam.example.json index f7f3fdd3..b10fbda4 100644 --- a/test/.testparam.example.json +++ b/test/.testparam.example.json @@ -48,6 +48,41 @@ // ], "data_channels": null, + // "forwarding_filters": [{ + // "name": "client-id-carol-block", + // "priority": 0, + // "action": "allow", + // "rules": [ + // [ + // { + // "field": "client_id", + // "operator": "is_in", + // "values": [ + // "carol", + // ] + // } + // ] + // ] + // }, { + // "name": "default", + // "priority": 32767, + // "action": "block", + // "rules": [ + // [ + // { + // "field": "kind", + // "operator": "is_in", + // "values": [ + // "audio", + // "video", + // ] + // } + // ] + // ] + // }, + // ], + "forwarding_filters": null, + // 0 - verbose // 1 - info // 2 - warning diff --git a/test/hello.cpp b/test/hello.cpp index 3959b154..3e69f13c 100644 --- a/test/hello.cpp +++ b/test/hello.cpp @@ -80,6 +80,9 @@ void HelloSora::Run() { if (!config_.data_channels.empty()) { config.data_channels = config_.data_channels; } + if (!config_.forwarding_filters.empty()) { + config.forwarding_filters = config_.forwarding_filters; + } conn_ = sora::SoraSignaling::Create(config); boost::asio::executor_work_guard @@ -196,27 +199,63 @@ int main(int argc, char* argv[]) { sora::SoraSignalingConfig::DataChannel data_channel; data_channel.label = dc.as_object().at("label").as_string(); data_channel.direction = dc.as_object().at("direction").as_string(); - if (get(dc, "ordered", x)) { - data_channel.ordered = x.as_bool(); + boost::json::value y; + if (get(dc, "ordered", y)) { + data_channel.ordered = y.as_bool(); } - if (get(dc, "max_packet_life_time", x)) { - data_channel.max_packet_life_time = x.to_number(); + if (get(dc, "max_packet_life_time", y)) { + data_channel.max_packet_life_time = y.to_number(); } - if (get(dc, "max_retransmits", x)) { - data_channel.max_retransmits = x.to_number(); + if (get(dc, "max_retransmits", y)) { + data_channel.max_retransmits = y.to_number(); } - if (get(dc, "protocol", x)) { - data_channel.protocol = x.as_string().c_str(); + if (get(dc, "protocol", y)) { + data_channel.protocol = y.as_string().c_str(); } - if (get(dc, "compress", x)) { - data_channel.compress = x.as_bool(); + if (get(dc, "compress", y)) { + data_channel.compress = y.as_bool(); } - if (get(dc, "header", x)) { - data_channel.header.emplace(x.as_array().begin(), x.as_array().end()); + if (get(dc, "header", y)) { + data_channel.header.emplace(y.as_array().begin(), y.as_array().end()); } config.data_channels.push_back(data_channel); } } + if (get(v, "forwarding_filters", x)) { + for (auto&& ff : x.as_array()) { + sora::SoraSignalingConfig::ForwardingFilter forwarding_filter; + boost::json::value y; + if (get(ff, "name", y)) { + forwarding_filter.name.emplace(y.as_string()); + } + if (get(ff, "priority", y)) { + forwarding_filter.priority.emplace(y.to_number()); + } + if (get(ff, "action", y)) { + forwarding_filter.action.emplace(y.as_string()); + } + for (auto&& rs : ff.as_object().at("rules").as_array()) { + std::vector rules; + for (auto&& r : rs.as_array()) { + sora::SoraSignalingConfig::ForwardingFilter::Rule rule; + rule.field = r.as_object().at("field").as_string(); + rule.op = r.as_object().at("operator").as_string(); + for (auto&& v : r.as_object().at("values").as_array()) { + rule.values.push_back(v.as_string().c_str()); + } + rules.push_back(rule); + } + forwarding_filter.rules.push_back(rules); + } + if (get(ff, "version", y)) { + forwarding_filter.version.emplace(y.as_string()); + } + if (get(ff, "metadata", y)) { + forwarding_filter.metadata = y; + } + config.forwarding_filters.push_back(forwarding_filter); + } + } if (get(v, "log_level", x)) { rtc::LogMessage::LogToDebug((rtc::LoggingSeverity)x.to_number()); } diff --git a/test/hello.h b/test/hello.h index 27341f44..3d4e8f5c 100644 --- a/test/hello.h +++ b/test/hello.h @@ -17,6 +17,7 @@ struct HelloSoraConfig { std::optional ignore_disconnect_websocket; std::string client_id; std::vector data_channels; + std::vector forwarding_filters; }; class HelloSora : public std::enable_shared_from_this,