Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/comm/comm_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,17 @@ namespace comm

message_processor_thread.join();
}
/**
* Iterate over all active sessions and apply a function to each.
* Used to update live session thresholds (e.g. idle_timeout) without restart.
*/
template<typename F>
void for_each_session(F&& func)
{
std::scoped_lock<std::mutex> lock(sessions_mutex);
for (T &session : sessions)
func(session);
}
};

} // namespace comm
Expand Down
41 changes: 41 additions & 0 deletions src/conf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include "ledger/ledger_mount.hpp"
#include "sc/contract_mount.hpp"

// Forward declaration to avoid circular dependency with p2p/p2p.hpp
namespace p2p { void update_idle_timeout(const uint32_t timeout_ms); }

namespace conf
{

Expand Down Expand Up @@ -853,6 +856,44 @@ namespace conf
return -1;
}

// Apply log level change dynamically if present in patch config.
// Uses plog::get()->setMaxSeverity() to update the live logger without restart.
try {
if (jdoc.contains("log") && jdoc["log"].contains("log_level")) {
const std::string new_log_level = jdoc["log"]["log_level"].as<std::string>();
const std::unordered_set<std::string> valid_loglevels({"dbg", "inf", "wrn", "err"});
if (valid_loglevels.count(new_log_level) == 1) {
cfg.log.log_level = new_log_level;
cfg.log.log_level_type = get_loglevel_type(new_log_level);
temp_cfg.log.log_level = new_log_level;
temp_cfg.log.log_level_type = get_loglevel_type(new_log_level);
plog::Severity new_plog_level;
if (cfg.log.log_level_type == LOG_SEVERITY::DEBUG) new_plog_level = plog::Severity::debug;
else if (cfg.log.log_level_type == LOG_SEVERITY::INFO) new_plog_level = plog::Severity::info;
else if (cfg.log.log_level_type == LOG_SEVERITY::WARN) new_plog_level = plog::Severity::warning;
else new_plog_level = plog::Severity::error;
plog::get()->setMaxSeverity(new_plog_level);
LOG_INFO << "Log level updated dynamically to: " << new_log_level;
}
}
} catch (const std::exception &e) {
LOG_ERROR << "Error applying log level from patch config: " << e.what();
}
// Apply mesh idle timeout change dynamically if present in patch config.
// Updates all active peer sessions and future connections without restart.
try {
if (jdoc.contains("mesh") && jdoc["mesh"].contains("idle_timeout")) {
const uint32_t new_idle_timeout = jdoc["mesh"]["idle_timeout"].as<uint32_t>();
if (new_idle_timeout != cfg.mesh.idle_timeout) {
cfg.mesh.idle_timeout = new_idle_timeout;
temp_cfg.mesh.idle_timeout = new_idle_timeout;
p2p::update_idle_timeout(new_idle_timeout);
LOG_INFO << "Mesh idle timeout updated dynamically to: " << new_idle_timeout << "ms";
}
}
} catch (const std::exception &e) {
LOG_ERROR << "Error applying mesh idle timeout from patch config: " << e.what();
}
LOG_INFO << "Contract config updated from patch file.";
return 0;
}
Expand Down
18 changes: 18 additions & 0 deletions src/p2p/p2p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@ namespace p2p
}
}

/**
* Update mesh idle timeout on all active peer sessions and for future connections.
* Called from conf::apply_patch_config() when mesh.idle_timeout changes in patch.cfg.
* Updates both the cached metric_thresholds array (for new sessions) and all
* existing live sessions via set_threshold() so no restart is required.
*/
void update_idle_timeout(const uint32_t timeout_ms)
{
metric_thresholds[4] = timeout_ms;
if (ctx.server.has_value())
{
ctx.server->for_each_session([timeout_ms](peer_comm_session &session) {
session.set_threshold(comm::SESSION_THRESHOLDS::IDLE_CONNECTION_TIMEOUT, timeout_ms, 60000);
});
LOG_INFO << "Mesh idle timeout updated dynamically to: " << timeout_ms << "ms";
}
}

int start_peer_connections()
{
const uint16_t listen_port = conf::cfg.mesh.listen ? conf::cfg.mesh.port : 0;
Expand Down