mirror of
https://github.com/EvernodeXRPL/sashimono.git
synced 2026-04-29 15:38:00 +00:00
* VM script improvements. * Modified docker-pull to create new container * Replaced vpnkit with slirp4netns for better containerized network performance. * Added swap allocation config. Co-authored-by: chalith <desaman.chalith@gmail.com>
146 lines
4.2 KiB
C++
146 lines
4.2 KiB
C++
#ifndef _SA_CONF_
|
|
#define _SA_CONF_
|
|
|
|
#include "pchheader.hpp"
|
|
#include "util/util.hpp"
|
|
|
|
namespace conf
|
|
{
|
|
// Log severity levels used in Sashimono agent.
|
|
enum LOG_SEVERITY
|
|
{
|
|
DEBUG,
|
|
INFO,
|
|
WARN,
|
|
ERROR
|
|
};
|
|
|
|
struct host_ip_port
|
|
{
|
|
std::string host_address;
|
|
uint16_t port = 0;
|
|
|
|
bool operator==(const host_ip_port &other) const
|
|
{
|
|
return host_address == other.host_address && port == other.port;
|
|
}
|
|
|
|
bool operator!=(const host_ip_port &other) const
|
|
{
|
|
return !(host_address == other.host_address && port == other.port);
|
|
}
|
|
|
|
bool operator<(const host_ip_port &other) const
|
|
{
|
|
return (host_address == other.host_address) ? port < other.port : host_address < other.host_address;
|
|
}
|
|
|
|
const std::string to_string() const
|
|
{
|
|
return host_address + ":" + std::to_string(port);
|
|
}
|
|
};
|
|
|
|
struct ugid
|
|
{
|
|
uid_t uid = 0;
|
|
gid_t gid = 0;
|
|
|
|
bool empty() const
|
|
{
|
|
return uid <= 0 && gid <= 0;
|
|
}
|
|
|
|
const std::string to_string() const
|
|
{
|
|
return (uid == 0 && gid == 0) ? "" : (std::to_string(uid) + ":" + std::to_string(gid));
|
|
}
|
|
};
|
|
|
|
struct log_config
|
|
{
|
|
std::string log_level; // Log severity level (dbg, inf, wrn, wrr)
|
|
LOG_SEVERITY log_level_type = LOG_SEVERITY::INFO; // Log severity level enum (debug, info, warn, error)
|
|
std::unordered_set<std::string> loggers; // List of enabled loggers (console, file)
|
|
size_t max_mbytes_per_file = 0; // Max MB size of a single log file.
|
|
size_t max_file_count = 0; // Max no. of log files to keep.
|
|
};
|
|
|
|
struct hp_config
|
|
{
|
|
std::string host_address;
|
|
uint16_t init_peer_port = 0;
|
|
uint16_t init_user_port = 0;
|
|
};
|
|
|
|
struct system_config
|
|
{
|
|
size_t max_cpu_us = 0; // Max CPU time the agent process can consume.
|
|
size_t max_mem_kbytes = 0; // Max memory the agent process can allocate in KB.
|
|
size_t max_swap_kbytes = 0; // Max swap memory the agent process can allocate in KB.
|
|
size_t max_storage_kbytes = 0; // Max physical storage the agent process can allocate in KB.
|
|
size_t max_instance_count = 0; // Max number of instances that can be created.
|
|
};
|
|
|
|
struct docker_config
|
|
{
|
|
std::unordered_map<std::string, std::string> images;
|
|
};
|
|
|
|
struct sa_config
|
|
{
|
|
std::string version;
|
|
hp_config hp;
|
|
system_config system;
|
|
docker_config docker;
|
|
log_config log;
|
|
};
|
|
|
|
struct sa_context
|
|
{
|
|
std::string command; // The CLI command issued to launch Sashimono agent
|
|
std::string exe_dir; // Sashimono Agent executable dir.
|
|
std::string hpfs_exe_path; // hpfs executable file path.
|
|
std::string contract_template_path; // Path to default contract.
|
|
|
|
std::string socket_path; // Path to the unix socket file.
|
|
|
|
std::string user_install_sh;
|
|
std::string user_uninstall_sh;
|
|
|
|
std::string config_file; // Full path to the config file.
|
|
std::string log_dir; // Log directory full path.
|
|
std::string data_dir; // Data directory full path.
|
|
};
|
|
|
|
// Global context struct exposed to the application.
|
|
// Other modules will access context values via this.
|
|
extern sa_context ctx;
|
|
|
|
// Global configuration struct exposed to the application.
|
|
// Other modules will access config values via this.
|
|
extern sa_config cfg;
|
|
|
|
int init();
|
|
|
|
int create(std::string_view host_addr, std::string_view registry_addr);
|
|
|
|
void set_dir_paths(std::string exepath, std::string datadir);
|
|
|
|
int validate_dir_paths();
|
|
|
|
int read_config(sa_config &cfg);
|
|
|
|
int write_config(const sa_config &cfg);
|
|
|
|
int write_json_file(const std::string &file_path, const jsoncons::ojson &d);
|
|
|
|
LOG_SEVERITY get_loglevel_type(std::string_view severity);
|
|
|
|
void print_missing_field_error(std::string_view jpath, const std::exception &e);
|
|
|
|
int validate_config(const sa_config &cfg);
|
|
|
|
}
|
|
|
|
#endif |