From dea3b5af7d5671d918289d8e878bbed60a2d23ab Mon Sep 17 00:00:00 2001 From: Ayush Mehra <97939637+amehra-ni@users.noreply.github.com> Date: Wed, 27 Nov 2024 12:25:53 +0530 Subject: [PATCH] Make sideband port configurable via json file. (#1126) * use sideband_port from config * remove sideband address from json file * fix default port * revert sideband_address changes * create helper for port extraction --- source/config/localhost_config.json | 1 + source/server/core_server.cpp | 4 +++- source/server/server_configuration_parser.cpp | 13 ++++++++++++- source/server/server_configuration_parser.h | 2 ++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/source/config/localhost_config.json b/source/config/localhost_config.json index de72d5de6..c911b4fe6 100644 --- a/source/config/localhost_config.json +++ b/source/config/localhost_config.json @@ -2,6 +2,7 @@ "address": "[::1]", "port": 31763, "sideband_address": "[::1]", + "sideband_port": 50055, "security" : { "server_cert": "", "server_key": "", diff --git a/source/server/core_server.cpp b/source/server/core_server.cpp index 9521e6810..db97c28c2 100644 --- a/source/server/core_server.cpp +++ b/source/server/core_server.cpp @@ -35,6 +35,7 @@ struct ServerConfiguration { std::string server_key; std::string root_cert; int max_message_size; + int sideband_port; nidevice_grpc::FeatureToggles feature_toggles; }; @@ -49,6 +50,7 @@ static ServerConfiguration GetConfiguration(const std::string& config_file_path) config.config_file_path = server_config_parser.get_config_file_path(); config.server_address = server_config_parser.parse_address(); config.sideband_address = server_config_parser.parse_sideband_address(); + config.sideband_port = server_config_parser.parse_sideband_port(); config.server_cert = server_config_parser.parse_server_cert(); config.server_key = server_config_parser.parse_server_key(); config.root_cert = server_config_parser.parse_root_cert(); @@ -110,7 +112,7 @@ static void RunServer(const ServerConfiguration& config) } server = builder.BuildAndStart(); if (ni::data_monikers::is_sideband_streaming_enabled(config.feature_toggles)) { - auto sideband_socket_thread = new std::thread(RunSidebandSocketsAccept, config.sideband_address.c_str(), 50055); + auto sideband_socket_thread = new std::thread(RunSidebandSocketsAccept, config.sideband_address.c_str(), config.sideband_port); // auto sideband_rdma_send_thread = new std::thread(AcceptSidebandRdmaSendRequests); // auto sideband_rdma_recv_thread = new std::thread(AcceptSidebandRdmaReceiveRequests); } diff --git a/source/server/server_configuration_parser.cpp b/source/server/server_configuration_parser.cpp index 5ac64b6a5..96feb1ebb 100644 --- a/source/server/server_configuration_parser.cpp +++ b/source/server/server_configuration_parser.cpp @@ -18,6 +18,7 @@ static const char* kDefaultFilename = "server_config.json"; static const char* kAddressJsonKey = "address"; static const char* kPortJsonKey = "port"; static const char* kSidebandAddressJsonKey = "sideband_address"; +static const char* kSidebandPortJsonKey = "sideband_port"; static const char* kServerCertJsonKey = "server_cert"; static const char* kServerKeyJsonKey = "server_key"; static const char* kRootCertJsonKey = "root_cert"; @@ -141,6 +142,11 @@ int ServerConfigurationParser::parse_max_message_size() const return UNLIMITED_MAX_MESSAGE_SIZE; } +int ServerConfigurationParser::parse_sideband_port() const +{ + return parse_port_with_key(kSidebandPortJsonKey); +} + FeatureToggles ServerConfigurationParser::parse_feature_toggles() const { FeatureToggleConfigurationMap map; @@ -253,10 +259,15 @@ std::string ServerConfigurationParser::parse_bind_address() const } int ServerConfigurationParser::parse_port() const +{ + return parse_port_with_key(kPortJsonKey); +} + +int ServerConfigurationParser::parse_port_with_key(const std::string& key) const { int parsed_port = -1; - auto it = config_file_.find(kPortJsonKey); + auto it = config_file_.find(key); if (it != config_file_.end()) { try { parsed_port = it->get(); diff --git a/source/server/server_configuration_parser.h b/source/server/server_configuration_parser.h index 72396e857..6ef631b84 100644 --- a/source/server/server_configuration_parser.h +++ b/source/server/server_configuration_parser.h @@ -41,6 +41,7 @@ class ServerConfigurationParser { std::string parse_server_key() const; std::string parse_root_cert() const; int parse_max_message_size() const; + int parse_sideband_port() const; FeatureToggles parse_feature_toggles() const; FeatureToggles::CodeReadiness parse_code_readiness() const; @@ -103,6 +104,7 @@ class ServerConfigurationParser { std::string parse_key_from_security_section(const char* key) const; std::string parse_bind_address() const; int parse_port() const; + int parse_port_with_key(const std::string& key) const; std::string config_file_path_; nlohmann::json config_file_;