Skip to content

Commit

Permalink
Just clean up naming, ordering of function parameters and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
garethsb committed Apr 26, 2023
1 parent a857ce1 commit c6d5161
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 47 deletions.
5 changes: 3 additions & 2 deletions Development/cpprest/host_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
#include <boost/asio/ip/host_name.hpp>
#include <boost/asio/ip/tcp.hpp>
#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm/find.hpp>
#include <boost/range/algorithm/find_if.hpp>
#include "cpprest/asyncrt_utils.h" // for utility::conversions

#if defined(_WIN32)
Expand Down Expand Up @@ -337,7 +338,7 @@ namespace web
{
return interface.addresses.end() != boost::range::find(interface.addresses, address);
});
return host_interfaces.end() != interface ? interface->name : utility::string_t {};
return host_interfaces.end() != interface ? interface->name : utility::string_t{};
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions Development/cpprest/uri_schemes.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef CPPREST_URI_SCHEMES_H
#define CPPREST_URI_SCHEMES_H

#include "cpprest/base_uri.h"
#include "cpprest/details/basic_types.h"

namespace web
Expand All @@ -24,10 +23,9 @@ namespace web
inline utility::string_t http_scheme(bool secure) { return secure ? uri_schemes::https : uri_schemes::http; }
inline utility::string_t ws_scheme(bool secure) { return secure ? uri_schemes::wss : uri_schemes::ws; }

// Check if the URI is secure
inline bool is_secure(const web::uri& uri)
inline bool is_secure_uri_scheme(const utility::string_t& scheme)
{
return uri_schemes::https == uri.scheme() || uri_schemes::wss == uri.scheme();
return uri_schemes::https == scheme || uri_schemes::wss == scheme;
}
}

Expand Down
10 changes: 6 additions & 4 deletions Development/nmos-cpp-node/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,12 @@
//"settings_port": 3209,
//"logging_port": 5106,

// addresses [registry, node]: addresses on which to listen for each API, or empty string for the wildcard address
// addresses [registry, node]: IP addresses on which to listen for each API, or empty string for the wildcard address

// server_address [registry, node]: if specified, this becomes the default address on which to listen for each API instead of the wildcard address
//"server_address": "",

// addresses [registry, node]: IP addresses on which to listen for specific APIs

//"settings_address": "127.0.0.1",
//"logging_address": "",
Expand All @@ -200,9 +205,6 @@
// for now, only supporting HTTP/HTTPS client connections on Linux
//"client_address": "",

// server_address [registry, node]: IP address of the network interface to bind server connections
//"server_address": "",

// logging_limit [registry, node]: maximum number of log events cached for the Logging API
//"logging_limit": 1234,

Expand Down
12 changes: 7 additions & 5 deletions Development/nmos-cpp-registry/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,17 @@
//"mdns_port": 3208,
//"schemas_port": 3208,

// addresses [registry, node]: addresses on which to listen for each API, or empty string for the wildcard address
// addresses [registry, node]: IP addresses on which to listen for each API, or empty string for the wildcard address

// server_address [registry, node]: if specified, this becomes the default address on which to listen for each API instead of the wildcard address
//"server_address": "",

// addresses [registry, node]: IP addresses on which to listen for specific APIs

//"settings_address": "127.0.0.1",
//"logging_address": "",

// addresses [registry]: addresses on which to listen for each API, or empty string for the wildcard address
// addresses [registry]: IP addresses on which to listen for specific APIs

//"admin_address": "",
//"mdns_address": "",
Expand All @@ -124,9 +129,6 @@
// for now, only supporting HTTP/HTTPS client connections on Linux
//"client_address": "",

// server_address [registry, node]: IP address of the network interface to bind server connections
//"server_address": "",

// query_ws_paging_default/query_ws_paging_limit [registry]: default/maximum number of events per message when using the Query WebSocket API (a client may request a lower limit)
//"query_ws_paging_default": 10,
//"query_ws_paging_limit": 100,
Expand Down
22 changes: 11 additions & 11 deletions Development/nmos/client_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ namespace nmos
}
#endif

inline std::function<void(web::http::client::native_handle)> make_client_nativehandle_options(const utility::string_t& client_address, bool secure, slog::base_gate& gate)
inline std::function<void(web::http::client::native_handle)> make_client_nativehandle_options(bool secure, const utility::string_t& client_address, slog::base_gate& gate)
{
// get the associated network interface name from IP address
const auto interface_name = web::hosts::experimental::get_interface_name(client_address);
Expand Down Expand Up @@ -121,7 +121,7 @@ namespace nmos

#ifdef CPPRESTSDK_ENABLE_BIND_WEBSOCKET_CLIENT
// The current version of the C++ REST SDK 2.10.18 does not provide the callback to enable the custom websocket setting
inline std::function<void(web::websockets::client::native_handle)> make_ws_client_nativehandle_options(const utility::string_t& client_address, bool secure, slog::base_gate& gate)
inline std::function<void(web::websockets::client::native_handle)> make_ws_client_nativehandle_options(bool secure, const utility::string_t& client_address, slog::base_gate& gate)
{
// get the associated network interface name from IP address
const auto interface_name = web::hosts::experimental::get_interface_name(client_address);
Expand Down Expand Up @@ -151,32 +151,32 @@ namespace nmos
#endif
}

// construct client config based on settings and specified secure flag, e.g. using the specified proxy, and the OCSP client
// construct client config based on specified secure flag and settings, e.g. using the specified proxy and OCSP config
// with the remaining options defaulted, e.g. request timeout
web::http::client::http_client_config make_http_client_config(const nmos::settings& settings, load_ca_certificates_handler load_ca_certificates, bool secure, slog::base_gate& gate)
web::http::client::http_client_config make_http_client_config(bool secure, const nmos::settings& settings, load_ca_certificates_handler load_ca_certificates, slog::base_gate& gate)
{
web::http::client::http_client_config config;
const auto proxy = proxy_uri(settings);
if (!proxy.is_empty()) config.set_proxy(proxy);
if (secure) config.set_validate_certificates(nmos::experimental::fields::validate_certificates(settings));
#if !defined(_WIN32) && !defined(__cplusplus_winrt) || defined(CPPREST_FORCE_HTTP_CLIENT_ASIO)
if (secure) config.set_ssl_context_callback(details::make_client_ssl_context_callback<web::http::http_exception>(settings, load_ca_certificates, gate));
config.set_nativehandle_options(details::make_client_nativehandle_options(nmos::experimental::fields::client_address(settings), secure, gate));
config.set_nativehandle_options(details::make_client_nativehandle_options(secure, nmos::experimental::fields::client_address(settings), gate));
#endif

return config;
}

// construct client config based on settings, e.g. using the specified proxy
// construct client config based on settings, e.g. using the specified proxy and OCSP config
// with the remaining options defaulted, e.g. request timeout
web::http::client::http_client_config make_http_client_config(const nmos::settings& settings, load_ca_certificates_handler load_ca_certificates, slog::base_gate& gate)
{
return make_http_client_config(settings, load_ca_certificates, nmos::experimental::fields::client_secure(settings), gate);
return make_http_client_config(nmos::experimental::fields::client_secure(settings), settings, load_ca_certificates, gate);
}

// construct client config based on settings and specified secure flag, e.g. using the specified proxy
// construct client config based on specified secure flag and settings, e.g. using the specified proxy
// with the remaining options defaulted
web::websockets::client::websocket_client_config make_websocket_client_config(const nmos::settings& settings, load_ca_certificates_handler load_ca_certificates, bool secure, slog::base_gate& gate)
web::websockets::client::websocket_client_config make_websocket_client_config(bool secure, const nmos::settings& settings, load_ca_certificates_handler load_ca_certificates, slog::base_gate& gate)
{
web::websockets::client::websocket_client_config config;
const auto proxy = proxy_uri(settings);
Expand All @@ -185,7 +185,7 @@ namespace nmos
#if !defined(_WIN32) || !defined(__cplusplus_winrt)
if (secure) config.set_ssl_context_callback(details::make_client_ssl_context_callback<web::websockets::client::websocket_exception>(settings, load_ca_certificates, gate));
#ifdef CPPRESTSDK_ENABLE_BIND_WEBSOCKET_CLIENT
config.set_nativehandle_options(details::make_ws_client_nativehandle_options(nmos::experimental::fields::client_address(settings), secure, gate));
config.set_nativehandle_options(details::make_ws_client_nativehandle_options(secure, nmos::experimental::fields::client_address(settings), gate));
#endif
#endif

Expand All @@ -196,7 +196,7 @@ namespace nmos
// with the remaining options defaulted
web::websockets::client::websocket_client_config make_websocket_client_config(const nmos::settings& settings, load_ca_certificates_handler load_ca_certificates, slog::base_gate& gate)
{
return make_websocket_client_config(settings, load_ca_certificates, nmos::experimental::fields::client_secure(settings), gate);
return make_websocket_client_config(nmos::experimental::fields::client_secure(settings), settings, load_ca_certificates, gate);
}

// make a request with logging
Expand Down
10 changes: 5 additions & 5 deletions Development/nmos/client_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ namespace slog { class base_gate; }
// Utility types, constants and functions for implementing NMOS REST API clients
namespace nmos
{
// construct client config based on settings and specified secure flag, e.g. using the specified proxy and the OCSP client
// construct client config based on specified secure flag and settings, e.g. using the specified proxy and OCSP config
// with the remaining options defaulted, e.g. request timeout
web::http::client::http_client_config make_http_client_config(const nmos::settings& settings, load_ca_certificates_handler load_ca_certificates, bool secure, slog::base_gate& gate);
// construct client config based on settings, e.g. using the specified proxy
web::http::client::http_client_config make_http_client_config(bool secure, const nmos::settings& settings, load_ca_certificates_handler load_ca_certificates, slog::base_gate& gate);
// construct client config based on settings, e.g. using the specified proxy and OCSP config
// with the remaining options defaulted, e.g. request timeout
web::http::client::http_client_config make_http_client_config(const nmos::settings& settings, load_ca_certificates_handler load_ca_certificates, slog::base_gate& gate);

// construct client config based on settings and specified secure flag, e.g. using the specified proxy
// construct client config based on specified secure flag and settings, e.g. using the specified proxy
// with the remaining options defaulted
web::websockets::client::websocket_client_config make_websocket_client_config(const nmos::settings& settings, load_ca_certificates_handler load_ca_certificates, bool secure, slog::base_gate& gate);
web::websockets::client::websocket_client_config make_websocket_client_config(bool secure, const nmos::settings& settings, load_ca_certificates_handler load_ca_certificates, slog::base_gate& gate);
// construct client config based on settings, e.g. using the specified proxy
// with the remaining options defaulted
web::websockets::client::websocket_client_config make_websocket_client_config(const nmos::settings& settings, load_ca_certificates_handler load_ca_certificates, slog::base_gate& gate);
Expand Down
4 changes: 2 additions & 2 deletions Development/nmos/node_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ namespace nmos

for (auto& api_router : node_server.api_routers)
{
// empty string and empty server IP address means the wildcard address
// if IP address isn't specified for this router, use default server address or wildcard address
const auto& host = !api_router.first.first.empty() ? api_router.first.first : !server_address.empty() ? server_address : web::http::experimental::listener::host_wildcard;
// map the configured client port to the server port on which to listen
// hmm, this should probably also take account of the address
Expand All @@ -86,7 +86,7 @@ namespace nmos

for (auto& ws_handler : node_server.ws_handlers)
{
// empty string and empty server IP address means the wildcard address
// if IP address isn't specified for this router, use default server address or wildcard address
const auto& host = !ws_handler.first.first.empty() ? ws_handler.first.first : !server_address.empty() ? server_address : web::websockets::experimental::listener::host_wildcard;
// map the configured client port to the server port on which to listen
// hmm, this should probably also take account of the address
Expand Down
7 changes: 4 additions & 3 deletions Development/nmos/ocsp_behaviour.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ namespace nmos

namespace details
{
web::http::client::http_client_config make_ocsp_client_config(const nmos::settings& settings, load_ca_certificates_handler load_ca_certificates, bool secure, slog::base_gate& gate)
web::http::client::http_client_config make_ocsp_client_config(bool secure, const nmos::settings& settings, load_ca_certificates_handler load_ca_certificates, slog::base_gate& gate)
{
auto config = nmos::make_http_client_config(settings, std::move(load_ca_certificates), secure, gate);
auto config = nmos::make_http_client_config(secure, settings, std::move(load_ca_certificates), gate);
config.set_timeout(std::chrono::seconds(nmos::experimental::fields::ocsp_request_max(settings)));
return config;
}
Expand Down Expand Up @@ -346,7 +346,8 @@ namespace nmos
if (!state.client)
{
const auto ocsp_uri = ocsp_uris.front();
state.client.reset(new web::http::client::http_client(ocsp_uri, make_ocsp_client_config(model.settings, state.load_ca_certificates, is_secure(ocsp_uri), gate)));
const auto secure = web::is_secure_uri_scheme(ocsp_uri.scheme());
state.client.reset(new web::http::client::http_client(ocsp_uri, make_ocsp_client_config(secure, model.settings, state.load_ca_certificates, gate)));
}

auto token = cancellation_source.get_token();
Expand Down
4 changes: 2 additions & 2 deletions Development/nmos/registry_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ namespace nmos

for (auto& api_router : registry_server.api_routers)
{
// empty string and empty server IP address means the wildcard address
// if IP address isn't specified for this router, use default server address or wildcard address
const auto& host = !api_router.first.first.empty() ? api_router.first.first : !server_address.empty() ? server_address : web::http::experimental::listener::host_wildcard;
// map the configured client port to the server port on which to listen
// hmm, this should probably also take account of the address
Expand All @@ -127,7 +127,7 @@ namespace nmos

for (auto& ws_handler : registry_server.ws_handlers)
{
//empty string and empty server IP address means the wildcard address
// if IP address isn't specified for this router, use default server address or wildcard address
const auto& host = !ws_handler.first.first.empty() ? ws_handler.first.first : !server_address.empty() ? server_address : web::websockets::experimental::listener::host_wildcard;
// map the configured client port to the server port on which to listen
// hmm, this should probably also take account of the address
Expand Down
1 change: 0 additions & 1 deletion Development/nmos/settings.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "nmos/settings.h"

#include <boost/range/adaptor/filtered.hpp>
#include <boost/range/algorithm.hpp>
#include <boost/range/algorithm/find_first_of.hpp>
#include <boost/version.hpp>
#include <openssl/opensslv.h>
Expand Down
15 changes: 7 additions & 8 deletions Development/nmos/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,6 @@ namespace nmos
{
// Get HTTP Strict-Transport-Security settings
bst::optional<web::http::experimental::hsts> get_hsts(const settings& settings);

// Get server IP address of the network interface for binding the server connections
utility::string_t get_server_address(const settings& settings);
}

// Get a summary of the build configuration, including versions of dependencies
Expand Down Expand Up @@ -243,12 +240,17 @@ namespace nmos
const web::json::field_as_integer_or mdns_port{ U("mdns_port"), 3208 };
const web::json::field_as_integer_or schemas_port{ U("schemas_port"), 3208 };

// addresses [registry, node]: addresses on which to listen for each API, or empty string for the wildcard address
// addresses [registry, node]: IP addresses on which to listen for each API, or empty string for the wildcard address

// server_address [registry, node]: if specified, this becomes the default address on which to listen for each API instead of the wildcard address
const web::json::field_as_string_or server_address{ U("server_address"), U("") };

// addresses [registry, node]: IP addresses on which to listen for specific APIs

const web::json::field_as_string_or settings_address{ U("settings_address"), U("") };
const web::json::field_as_string_or logging_address{ U("logging_address"), U("") };

// addresses [registry]: addresses on which to listen for each API, or empty string for the wildcard address
// addresses [registry]: IP addresses on which to listen for specific APIs

const web::json::field_as_string_or admin_address{ U("admin_address"), U("") };
const web::json::field_as_string_or mdns_address{ U("mdns_address"), U("") };
Expand All @@ -258,9 +260,6 @@ namespace nmos
// for now, only supporting HTTP/HTTPS client connections on Linux
const web::json::field_as_string_or client_address{ U("client_address"), U("") };

// server_address [registry, node]: IP address of the network interface to bind server connections
const web::json::field_as_string_or server_address{ U("server_address"), U("") };

// query_ws_paging_default/query_ws_paging_limit [registry]: default/maximum number of events per message when using the Query WebSocket API (a client may request a lower limit)
const web::json::field_as_integer_or query_ws_paging_default{ U("query_ws_paging_default"), 10 };
const web::json::field_as_integer_or query_ws_paging_limit{ U("query_ws_paging_limit"), 100 };
Expand Down

0 comments on commit c6d5161

Please sign in to comment.