mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
User connections enable/disable config flag (#209)
This commit is contained in:
@@ -471,6 +471,7 @@ namespace conf
|
||||
cfg.user.max_bytes_per_min = user["max_bytes_per_min"].as<uint64_t>();
|
||||
cfg.user.max_bad_msgs_per_min = user["max_bad_msgs_per_min"].as<uint64_t>();
|
||||
cfg.user.idle_timeout = user["idle_timeout"].as<uint16_t>();
|
||||
cfg.user.enabled = user["enabled"].as<bool>();
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
@@ -578,6 +579,7 @@ namespace conf
|
||||
user_config.insert_or_assign("max_bytes_per_min", cfg.user.max_bytes_per_min);
|
||||
user_config.insert_or_assign("max_bad_msgs_per_min", cfg.user.max_bad_msgs_per_min);
|
||||
user_config.insert_or_assign("max_connections", cfg.user.max_connections);
|
||||
user_config.insert_or_assign("enabled", cfg.user.enabled);
|
||||
d.insert_or_assign("user", user_config);
|
||||
|
||||
// Log configs.
|
||||
|
||||
@@ -104,6 +104,7 @@ namespace conf
|
||||
uint64_t max_bytes_per_min = 0; // User message rate (characters(bytes) per minute)
|
||||
uint64_t max_bad_msgs_per_min = 0; // User bad messages per minute
|
||||
uint16_t max_connections = 0; // Max inbound user connections
|
||||
bool enabled = true; // User connections enable/disable.
|
||||
};
|
||||
|
||||
struct peer_discovery_config
|
||||
|
||||
@@ -42,9 +42,16 @@ namespace usr
|
||||
if (input_store.init() == -1)
|
||||
return -1;
|
||||
|
||||
// Start listening for incoming user connections.
|
||||
if (start_listening() == -1)
|
||||
return -1;
|
||||
// Start listening for incoming user connections only if user connections config is enabled.
|
||||
if (conf::cfg.user.enabled)
|
||||
{
|
||||
if (start_listening() == -1)
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_INFO << "User connection listner isn't started since user connections are disabled.";
|
||||
}
|
||||
|
||||
init_success = true;
|
||||
return 0;
|
||||
@@ -57,7 +64,11 @@ namespace usr
|
||||
{
|
||||
if (init_success)
|
||||
{
|
||||
ctx.server->stop();
|
||||
// Stop com server only if user connections config is enabled (Otherwise server hasn't been started).
|
||||
if (conf::cfg.user.enabled)
|
||||
{
|
||||
ctx.server->stop();
|
||||
}
|
||||
input_store.deinit();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user