Files
thehub/libs/server/Application.cpp
T

126 lines
3.2 KiB
C++
Raw Permalink Normal View History

2016-08-16 16:51:22 +02:00
/*
2017-11-09 19:34:51 +01:00
* This file is part of the Flowee project
2019-12-12 17:34:14 +01:00
* Copyright (C) 2016-2019 Tom Zander <tomz@freedommail.ch>
2016-08-16 16:51:22 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Application.h"
2016-12-28 13:20:24 +01:00
#include "utilstrencodings.h"
#include "clientversion.h"
#include "net.h"
2017-02-18 15:31:38 +01:00
#include "util.h"
2018-01-15 15:26:12 +00:00
#include <validation/Engine.h>
2016-12-28 13:20:24 +01:00
2016-08-16 16:51:22 +02:00
// static
Application * Application::instance()
{
static Application s_app;
return &s_app;
}
// static
int Application::exec()
{
Application *app = Application::instance();
app->joinAll();
2016-08-16 16:51:22 +02:00
return app->m_returnCode;
}
// static
void Application::quit(int rc)
{
Application *app = Application::instance();
app->m_returnCode = rc;
2018-08-04 22:54:12 +02:00
app->m_closingDown = true;
app->m_validationEngine.reset();
app->stopThreads();
2016-08-16 16:51:22 +02:00
}
Application::Application()
2018-01-15 15:26:12 +00:00
: m_returnCode(0),
2019-06-02 13:57:47 +02:00
m_closingDown(false)
2016-08-16 16:51:22 +02:00
{
2017-07-23 12:37:49 +02:00
init();
}
void Application::init()
{
m_closingDown = false;
2018-01-15 15:26:12 +00:00
}
2017-02-18 15:31:38 +01:00
Application::~Application()
{
}
2018-01-15 15:26:12 +00:00
Validation::Engine *Application::validation()
{
if (m_validationEngine.get() == nullptr)
m_validationEngine.reset(new Validation::Engine());
return m_validationEngine.get();
}
CTxMemPool *Application::mempool()
{
return validation()->mempool();
}
2016-12-28 13:20:24 +01:00
std::string Application::userAgent()
{
std::vector<std::string> comments;
for (const std::string &comment : mapMultiArgs["-uacomment"]) {
if (comment == SanitizeString(comment, SAFE_CHARS_UA_COMMENT))
comments.push_back(comment);
else
2019-06-02 13:57:47 +02:00
logCritical(Log::Bitcoin).nospace() << "User Agent comment (" << comment << ") contains unsafe characters.";
2016-12-28 13:20:24 +01:00
}
std::ostringstream ss;
ss << "/";
2018-10-30 10:38:50 +01:00
ss << clientName() << ":" << HUB_SERIES;
2016-12-28 13:20:24 +01:00
if (!comments.empty()) {
auto it(comments.begin());
ss << "(" << *it;
for (++it; it != comments.end(); ++it)
ss << "; " << *it;
ss << ")";
2018-10-30 10:38:50 +01:00
} else {
2019-12-12 17:34:14 +01:00
ss << " (" << CLIENT_VERSION_MAJOR << "-";
2019-12-31 18:05:24 +01:00
ss.width(2);
ss.fill('0');
ss << CLIENT_VERSION_MINOR << ")";
2016-12-28 13:20:24 +01:00
}
ss << "/";
std::string answer = ss.str();
if (answer.size() > MAX_SUBVERSION_LENGTH) {
2019-06-02 13:57:47 +02:00
logCritical(Log::Bitcoin).nospace() << "Total length of network version string (" << answer.size()
<< ") exceeds maximum length (" << MAX_SUBVERSION_LENGTH
<< "). Reduce the number or size of uacomments.";
2016-12-28 13:20:24 +01:00
answer = answer.substr(0, MAX_SUBVERSION_LENGTH);
}
return answer;
}
const char *Application::clientName()
{
2017-11-13 23:09:33 +01:00
return "Flowee";
2016-12-28 13:20:24 +01:00
}
2017-02-24 14:34:35 +01:00
bool Application::closingDown()
{
return instance()->m_closingDown;
}