1.4.10 updates

This commit is contained in:
WolverinDEV
2020-02-28 11:24:07 +01:00
parent 2b929fd3c0
commit 0d456eea5d
48 changed files with 2267 additions and 781 deletions
+25 -23
View File
@@ -44,7 +44,11 @@ InstanceHandler::InstanceHandler(SqlDataManager *sql) : sql(sql) {
this->statistics = make_shared<stats::ConnectionStatistics>(nullptr, true);
this->statistics->measure_bandwidths(true);
this->licenseHelper = make_shared<license::LicenseHelper>();
std::string error_message{};
this->license_service_ = std::make_shared<license::LicenseService>();
if(!this->license_service_->initialize(error_message)) {
logCritical(LOG_INSTANCE, strobf("Failed to the license service: {}").string(), error_message);
}
this->dbHelper = new DatabaseHelper(this->getSql());
this->_properties = new Properties();
@@ -214,7 +218,6 @@ InstanceHandler::~InstanceHandler() {
globalServerAdmin = nullptr;
_musicRoot = nullptr;
licenseHelper = nullptr;
statistics = nullptr;
tick_manager = nullptr;
}
@@ -453,6 +456,8 @@ void InstanceHandler::stopInstance() {
this->sslMgr = nullptr;
this->web_event_loop = nullptr;
this->license_service_->shutdown();
}
void InstanceHandler::tickInstance() {
@@ -470,7 +475,7 @@ void InstanceHandler::tickInstance() {
}
{
ALARM_TIMER(t, strobf("InstanceHandler::tickInstance -> license tick").string(), milliseconds(5));
this->licenseHelper->tick();
this->license_service_->execute_tick();
}
}
{
@@ -637,36 +642,35 @@ string get_mac_address() {
}
#define SN_BUFFER 1024
std::shared_ptr<license::LicenseRequestData> InstanceHandler::generateLicenseData() {
auto request = make_shared<license::LicenseRequestData>();
std::shared_ptr<ts::server::license::InstanceLicenseInfo> InstanceHandler::generateLicenseData() {
auto request = std::make_shared<license::InstanceLicenseInfo>();
request->license = config::license;
request->servers_online = this->voiceServerManager->runningServers();
request->metrics.servers_online = this->voiceServerManager->runningServers();
auto report = this->voiceServerManager->clientReport();
request->client_online = report.clients_ts;
request->web_clients_online = report.clients_web;
request->bots_online = report.bots;
request->queries_online = report.queries;
request->speach_total = this->properties()[property::SERVERINSTANCE_SPOKEN_TIME_TOTAL].as<uint64_t>();
request->speach_varianz = this->properties()[property::SERVERINSTANCE_SPOKEN_TIME_VARIANZ].as<uint64_t>();
request->speach_online = this->properties()[property::SERVERINSTANCE_SPOKEN_TIME_ALIVE].as<uint64_t>();
request->speach_dead = this->properties()[property::SERVERINSTANCE_SPOKEN_TIME_DELETED].as<uint64_t>();
request->metrics.client_online = report.clients_ts;
request->metrics.web_clients_online = report.clients_web;
request->metrics.bots_online = report.bots;
request->metrics.queries_online = report.queries;
request->metrics.speech_total = this->properties()[property::SERVERINSTANCE_SPOKEN_TIME_TOTAL].as<uint64_t>();
request->metrics.speech_varianz = this->properties()[property::SERVERINSTANCE_SPOKEN_TIME_VARIANZ].as<uint64_t>();
request->metrics.speech_online = this->properties()[property::SERVERINSTANCE_SPOKEN_TIME_ALIVE].as<uint64_t>();
request->metrics.speech_dead = this->properties()[property::SERVERINSTANCE_SPOKEN_TIME_DELETED].as<uint64_t>();
static std::string null_str{"\0\0\0\0\0\0\0\0", 8}; /* we need at least some characters */
request->web_certificate_revision = this->web_cert_revision.empty() ? null_str : this->web_cert_revision;
{
auto info = make_shared<license::ServerInfo>();
info->timestamp = duration_cast<milliseconds>(system_clock::now().time_since_epoch()).count();
info->version = build::version()->string(true);
request->info.timestamp = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch());
request->info.version = build::version()->string(true);
{ /* uname */
utsname retval{};
if(uname(&retval) < 0) {
info->uname = "unknown (" + string(strerror(errno)) + ")";
request->info.uname = "unknown (" + string(strerror(errno)) + ")";
} else {
char buffer[SN_BUFFER];
snprintf(buffer, SN_BUFFER, "sys:%s version:%s release:%s", retval.sysname, retval.version, retval.release);
info->uname = string(buffer);
request->info.uname = string(buffer);
}
}
@@ -676,12 +680,10 @@ std::shared_ptr<license::LicenseRequestData> InstanceHandler::generateLicenseDat
if(property_unique_id.as<string>().empty())
property_unique_id = rnd_string(64);
auto hash = digest::sha256(info->uname);
auto hash = digest::sha256(request->info.uname);
hash = digest::sha256(hash + property_unique_id.as<string>() + get_mac_address());
info->unique_identifier = base64::encode(hash);
request->info.unique_id = base64::encode(hash);
}
request->info = info;
}
return request;
}