Skip to content

Commit

Permalink
Make sideband port configurable via json file. (#1126)
Browse files Browse the repository at this point in the history
* use sideband_port from config

* remove sideband address from json file

* fix default port

* revert sideband_address changes

* create helper for port extraction
  • Loading branch information
amehra-ni authored Nov 27, 2024
1 parent 4f6e50c commit dea3b5a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions source/config/localhost_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"address": "[::1]",
"port": 31763,
"sideband_address": "[::1]",
"sideband_port": 50055,
"security" : {
"server_cert": "",
"server_key": "",
Expand Down
4 changes: 3 additions & 1 deletion source/server/core_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
Expand Down
13 changes: 12 additions & 1 deletion source/server/server_configuration_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<int>();
Expand Down
2 changes: 2 additions & 0 deletions source/server/server_configuration_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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_;
Expand Down

0 comments on commit dea3b5a

Please sign in to comment.