Sync ConsoleLog class, base versions and TLS init.
This commit is contained in:
parent
9a0cd68ea5
commit
bc150fec04
@ -27,42 +27,34 @@
|
||||
#include "base/io/log/backends/ConsoleLog.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/kernel/private/Title.h"
|
||||
#include "base/tools/Cvt.h"
|
||||
#include "base/tools/Handle.h"
|
||||
|
||||
|
||||
#include <cstdio>
|
||||
|
||||
|
||||
xmrig::ConsoleLog::ConsoleLog(const Title &title)
|
||||
xmrig::ConsoleLog::ConsoleLog()
|
||||
{
|
||||
if (!isSupported()) {
|
||||
Log::setColors(false);
|
||||
if (!init()) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_tty = new uv_tty_t;
|
||||
|
||||
if (uv_tty_init(uv_default_loop(), m_tty, 1, 0) < 0) {
|
||||
Log::setColors(false);
|
||||
return;
|
||||
}
|
||||
|
||||
uv_tty_set_mode(m_tty, UV_TTY_MODE_NORMAL);
|
||||
|
||||
# ifdef XMRIG_OS_WIN
|
||||
m_stream = reinterpret_cast<uv_stream_t*>(m_tty);
|
||||
SetConsoleOutputCP(65001);
|
||||
# endif
|
||||
}
|
||||
|
||||
HANDLE handle = GetStdHandle(STD_INPUT_HANDLE);
|
||||
if (handle != INVALID_HANDLE_VALUE) { // NOLINT(cppcoreguidelines-pro-type-cstyle-cast, performance-no-int-to-ptr)
|
||||
DWORD mode = 0;
|
||||
if (GetConsoleMode(handle, &mode)) {
|
||||
mode &= ~ENABLE_QUICK_EDIT_MODE;
|
||||
SetConsoleMode(handle, mode | ENABLE_EXTENDED_FLAGS);
|
||||
}
|
||||
|
||||
xmrig::ConsoleLog::ConsoleLog(const Title &title)
|
||||
{
|
||||
if (!init()) {
|
||||
return;
|
||||
}
|
||||
|
||||
# ifdef XMRIG_OS_WIN
|
||||
if (title.isEnabled()) {
|
||||
SetConsoleTitleA(title.value());
|
||||
SetConsoleTitleW(Cvt::toUtf16(title.value().data()).c_str());
|
||||
}
|
||||
# endif
|
||||
}
|
||||
@ -104,6 +96,37 @@ bool xmrig::ConsoleLog::isSupported()
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::ConsoleLog::init()
|
||||
{
|
||||
if (!isSupported()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_tty = new uv_tty_t;
|
||||
|
||||
if (uv_tty_init(uv_default_loop(), m_tty, 1, 0) < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
uv_tty_set_mode(m_tty, UV_TTY_MODE_NORMAL);
|
||||
|
||||
# ifdef XMRIG_OS_WIN
|
||||
m_stream = reinterpret_cast<uv_stream_t*>(m_tty);
|
||||
|
||||
HANDLE handle = GetStdHandle(STD_INPUT_HANDLE);
|
||||
if (handle != INVALID_HANDLE_VALUE) { // NOLINT(cppcoreguidelines-pro-type-cstyle-cast, performance-no-int-to-ptr)
|
||||
DWORD mode = 0;
|
||||
if (GetConsoleMode(handle, &mode)) {
|
||||
mode &= ~ENABLE_QUICK_EDIT_MODE;
|
||||
SetConsoleMode(handle, mode | ENABLE_EXTENDED_FLAGS);
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
#ifdef XMRIG_OS_WIN
|
||||
bool xmrig::ConsoleLog::isWritable() const
|
||||
{
|
||||
|
@ -47,6 +47,7 @@ class ConsoleLog : public ILogBackend
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE(ConsoleLog)
|
||||
|
||||
ConsoleLog();
|
||||
ConsoleLog(const Title &title);
|
||||
~ConsoleLog() override;
|
||||
|
||||
@ -56,6 +57,8 @@ protected:
|
||||
private:
|
||||
static bool isSupported();
|
||||
|
||||
bool init();
|
||||
|
||||
uv_tty_t *m_tty = nullptr;
|
||||
|
||||
# ifdef XMRIG_OS_WIN
|
||||
|
@ -164,7 +164,6 @@ private:
|
||||
xmrig::Base::Base(Process *process)
|
||||
: d_ptr(new BasePrivate(process))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -187,7 +186,6 @@ int xmrig::Base::init()
|
||||
d_ptr->api->addListener(this);
|
||||
# endif
|
||||
|
||||
OS::init();
|
||||
Process::setUserAgent(config()->userAgent());
|
||||
|
||||
if (isBackground()) {
|
||||
|
@ -24,11 +24,14 @@
|
||||
*/
|
||||
|
||||
#include "base/kernel/config/BaseConfig.h"
|
||||
#include "3rdparty/fmt/core.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "base/io/json/Json.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/io/log/Tags.h"
|
||||
#include "base/kernel/interfaces/IJsonReader.h"
|
||||
#include "base/kernel/Process.h"
|
||||
#include "base/kernel/Versions.h"
|
||||
#include "base/net/dns/Dns.h"
|
||||
#include "version.h"
|
||||
|
||||
@ -38,7 +41,6 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_TLS
|
||||
@ -138,38 +140,21 @@ bool xmrig::BaseConfig::save()
|
||||
|
||||
void xmrig::BaseConfig::printVersions()
|
||||
{
|
||||
char buf[256] = { 0 };
|
||||
const auto &versions = Process::versions();
|
||||
|
||||
# if defined(__clang__)
|
||||
snprintf(buf, sizeof buf, "clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__);
|
||||
# elif defined(__GNUC__)
|
||||
snprintf(buf, sizeof buf, "gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
|
||||
# elif defined(_MSC_VER)
|
||||
snprintf(buf, sizeof buf, "MSVC/%d", MSVC_VERSION);
|
||||
# endif
|
||||
|
||||
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%s/%s") WHITE_BOLD(" %s"), "ABOUT", APP_NAME, APP_VERSION, buf);
|
||||
|
||||
std::string libs;
|
||||
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") CYAN_BOLD("%s/%s") WHITE_BOLD(" %s/%s"), "ABOUT", APP_NAME, APP_VERSION, Versions::kCompiler, versions.get(Versions::kCompiler).data());
|
||||
|
||||
# if defined(XMRIG_FEATURE_TLS)
|
||||
{
|
||||
# if defined(LIBRESSL_VERSION_TEXT)
|
||||
snprintf(buf, sizeof buf, "LibreSSL/%s ", LIBRESSL_VERSION_TEXT + 9);
|
||||
libs += buf;
|
||||
# elif defined(OPENSSL_VERSION_TEXT)
|
||||
constexpr const char *v = &OPENSSL_VERSION_TEXT[8];
|
||||
snprintf(buf, sizeof buf, "OpenSSL/%.*s ", static_cast<int>(strchr(v, ' ') - v), v);
|
||||
libs += buf;
|
||||
# endif
|
||||
}
|
||||
std::string libs = fmt::format("{}/{} ", Versions::kTls, versions.get(Versions::kTls));
|
||||
# else
|
||||
std::string libs;
|
||||
# endif
|
||||
|
||||
# if defined(XMRIG_FEATURE_HWLOC)
|
||||
libs += Cpu::info()->backend();
|
||||
# endif
|
||||
|
||||
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13slibuv/%s %s"), "LIBS", uv_version_string(), libs.c_str());
|
||||
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13slibuv/%s %s"), "LIBS", versions.get(Versions::kUv).data(), libs.c_str());
|
||||
}
|
||||
|
||||
|
||||
|
@ -14,17 +14,34 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional permission under GNU GPL version 3 section 7
|
||||
*
|
||||
* If you modify this Program, or any covered work, by linking or combining
|
||||
* it with OpenSSL (or a modified version of that library), containing parts
|
||||
* covered by the terms of OpenSSL License and SSLeay License, the licensors
|
||||
* of this Program grant you additional permission to convey the resulting work.
|
||||
*/
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
#include "base/net/https/HttpsServer.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/net/https/HttpsContext.h"
|
||||
#include "base/net/tls/TlsContext.h"
|
||||
#include "base/net/tools/NetBuffer.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
extern const char *tls_tag();
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::HttpsServer::HttpsServer(const std::shared_ptr<IHttpListener> &listener) :
|
||||
m_listener(listener)
|
||||
{
|
||||
@ -39,7 +56,14 @@ xmrig::HttpsServer::~HttpsServer()
|
||||
|
||||
bool xmrig::HttpsServer::setTls(const TlsConfig &config)
|
||||
{
|
||||
m_tls = TlsContext::create(config);
|
||||
m_tls = nullptr;
|
||||
|
||||
|
||||
try {
|
||||
m_tls = TlsContext::create(config);
|
||||
} catch (std::exception &ex) {
|
||||
LOG_ERR("%s " RED_BOLD("%s"), tls_tag(), ex.what());
|
||||
}
|
||||
|
||||
return m_tls != nullptr;
|
||||
}
|
||||
|
@ -14,6 +14,13 @@
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional permission under GNU GPL version 3 section 7
|
||||
*
|
||||
* If you modify this Program, or any covered work, by linking or combining
|
||||
* it with OpenSSL (or a modified version of that library), containing parts
|
||||
* covered by the terms of OpenSSL License and SSLeay License, the licensors
|
||||
* of this Program grant you additional permission to convey the resulting work.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_HTTPSSERVER_H
|
||||
|
Loading…
x
Reference in New Issue
Block a user