Initial project snapshot

This commit is contained in:
2026-04-28 22:29:50 +03:00
commit 8ba0561f4f
365 changed files with 91832 additions and 0 deletions
+89
View File
@@ -0,0 +1,89 @@
#include "rdp_worker/config/config.hpp"
#include <cstdlib>
#include <fstream>
#include <sstream>
#include <stdexcept>
namespace rdp_worker::config {
namespace {
std::string GetEnvOrDefault(const char* key, const char* fallback) {
const char* value = std::getenv(key);
if (value == nullptr || std::string(value).empty()) {
return fallback;
}
return value;
}
int GetInt(const char* key, int fallback) {
const char* value = std::getenv(key);
if (value == nullptr || std::string(value).empty()) {
return fallback;
}
return std::stoi(value);
}
bool GetBool(const char* key, bool fallback) {
const char* value = std::getenv(key);
if (value == nullptr || std::string(value).empty()) {
return fallback;
}
const std::string raw(value);
return raw == "1" || raw == "true" || raw == "TRUE" || raw == "yes" || raw == "on";
}
std::string ReadFileIfConfigured(const std::string& path) {
if (path.empty()) {
return "";
}
std::ifstream input(path);
if (!input.good()) {
throw std::runtime_error("failed to read file " + path);
}
std::stringstream buffer;
buffer << input.rdbuf();
return buffer.str();
}
std::vector<std::string> Split(const std::string& value) {
std::vector<std::string> parts;
std::stringstream stream(value);
std::string part;
while (std::getline(stream, part, ',')) {
if (!part.empty()) {
parts.push_back(part);
}
}
return parts;
}
} // namespace
Config LoadFromEnv() {
Config config{};
config.worker_id = GetEnvOrDefault("RDP_WORKER_ID", "rdp-worker-1");
config.redis_host = GetEnvOrDefault("RDP_WORKER_REDIS_HOST", "127.0.0.1");
config.redis_port = GetInt("RDP_WORKER_REDIS_PORT", 6379);
config.redis_password = GetEnvOrDefault("RDP_WORKER_REDIS_PASSWORD", "");
config.redis_db = GetInt("RDP_WORKER_REDIS_DB", 0);
config.worker_heartbeat_interval = std::chrono::seconds(GetInt("RDP_WORKER_HEARTBEAT_INTERVAL_SECONDS", 5));
config.lease_renew_interval = std::chrono::seconds(GetInt("RDP_WORKER_LEASE_RENEW_INTERVAL_SECONDS", 10));
config.assignment_poll_interval = std::chrono::seconds(GetInt("RDP_WORKER_ASSIGNMENT_POLL_INTERVAL_SECONDS", 2));
config.insecure_skip_verify = GetBool("RDP_WORKER_INSECURE_SKIP_VERIFY", false);
config.capabilities = Split(GetEnvOrDefault("RDP_WORKER_CAPABILITIES", "adaptive-quality,dirty-rects,clipboard,file-transfer"));
config.data_plane_enabled = GetBool("RDP_WORKER_DATA_PLANE_ENABLED", false);
config.data_plane_listen_host = GetEnvOrDefault("RDP_WORKER_DATA_PLANE_LISTEN_HOST", "0.0.0.0");
config.data_plane_listen_port = GetInt("RDP_WORKER_DATA_PLANE_LISTEN_PORT", 8443);
config.data_plane_public_key_pem = GetEnvOrDefault("RDP_WORKER_DATA_PLANE_PUBLIC_KEY_PEM", "");
config.data_plane_public_key_file = GetEnvOrDefault("RDP_WORKER_DATA_PLANE_PUBLIC_KEY_FILE", "");
if (config.data_plane_public_key_pem.empty()) {
config.data_plane_public_key_pem = ReadFileIfConfigured(config.data_plane_public_key_file);
}
config.data_plane_tls_cert_file = GetEnvOrDefault("RDP_WORKER_DATA_PLANE_TLS_CERT_FILE", "");
config.data_plane_tls_key_file = GetEnvOrDefault("RDP_WORKER_DATA_PLANE_TLS_KEY_FILE", "");
return config;
}
} // namespace rdp_worker::config