mirror of
https://github.com/xmrig/xmrig.git
synced 2025-01-18 16:55:55 +00:00
Sync ConsoleLog class, base versions and TLS init.
This commit is contained in:
parent
9a0cd68ea5
commit
bc150fec04
6 changed files with 88 additions and 48 deletions
|
@ -27,42 +27,34 @@
|
||||||
#include "base/io/log/backends/ConsoleLog.h"
|
#include "base/io/log/backends/ConsoleLog.h"
|
||||||
#include "base/io/log/Log.h"
|
#include "base/io/log/Log.h"
|
||||||
#include "base/kernel/private/Title.h"
|
#include "base/kernel/private/Title.h"
|
||||||
|
#include "base/tools/Cvt.h"
|
||||||
#include "base/tools/Handle.h"
|
#include "base/tools/Handle.h"
|
||||||
|
|
||||||
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
|
|
||||||
xmrig::ConsoleLog::ConsoleLog(const Title &title)
|
xmrig::ConsoleLog::ConsoleLog()
|
||||||
{
|
{
|
||||||
if (!isSupported()) {
|
if (!init()) {
|
||||||
Log::setColors(false);
|
|
||||||
return;
|
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
|
# 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)
|
xmrig::ConsoleLog::ConsoleLog(const Title &title)
|
||||||
DWORD mode = 0;
|
{
|
||||||
if (GetConsoleMode(handle, &mode)) {
|
if (!init()) {
|
||||||
mode &= ~ENABLE_QUICK_EDIT_MODE;
|
return;
|
||||||
SetConsoleMode(handle, mode | ENABLE_EXTENDED_FLAGS);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# ifdef XMRIG_OS_WIN
|
||||||
if (title.isEnabled()) {
|
if (title.isEnabled()) {
|
||||||
SetConsoleTitleA(title.value());
|
SetConsoleTitleW(Cvt::toUtf16(title.value().data()).c_str());
|
||||||
}
|
}
|
||||||
# endif
|
# 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
|
#ifdef XMRIG_OS_WIN
|
||||||
bool xmrig::ConsoleLog::isWritable() const
|
bool xmrig::ConsoleLog::isWritable() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -47,6 +47,7 @@ class ConsoleLog : public ILogBackend
|
||||||
public:
|
public:
|
||||||
XMRIG_DISABLE_COPY_MOVE(ConsoleLog)
|
XMRIG_DISABLE_COPY_MOVE(ConsoleLog)
|
||||||
|
|
||||||
|
ConsoleLog();
|
||||||
ConsoleLog(const Title &title);
|
ConsoleLog(const Title &title);
|
||||||
~ConsoleLog() override;
|
~ConsoleLog() override;
|
||||||
|
|
||||||
|
@ -56,6 +57,8 @@ protected:
|
||||||
private:
|
private:
|
||||||
static bool isSupported();
|
static bool isSupported();
|
||||||
|
|
||||||
|
bool init();
|
||||||
|
|
||||||
uv_tty_t *m_tty = nullptr;
|
uv_tty_t *m_tty = nullptr;
|
||||||
|
|
||||||
# ifdef XMRIG_OS_WIN
|
# ifdef XMRIG_OS_WIN
|
||||||
|
|
|
@ -164,7 +164,6 @@ private:
|
||||||
xmrig::Base::Base(Process *process)
|
xmrig::Base::Base(Process *process)
|
||||||
: d_ptr(new BasePrivate(process))
|
: d_ptr(new BasePrivate(process))
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -187,7 +186,6 @@ int xmrig::Base::init()
|
||||||
d_ptr->api->addListener(this);
|
d_ptr->api->addListener(this);
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
OS::init();
|
|
||||||
Process::setUserAgent(config()->userAgent());
|
Process::setUserAgent(config()->userAgent());
|
||||||
|
|
||||||
if (isBackground()) {
|
if (isBackground()) {
|
||||||
|
|
|
@ -24,11 +24,14 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "base/kernel/config/BaseConfig.h"
|
#include "base/kernel/config/BaseConfig.h"
|
||||||
|
#include "3rdparty/fmt/core.h"
|
||||||
#include "3rdparty/rapidjson/document.h"
|
#include "3rdparty/rapidjson/document.h"
|
||||||
#include "base/io/json/Json.h"
|
#include "base/io/json/Json.h"
|
||||||
#include "base/io/log/Log.h"
|
#include "base/io/log/Log.h"
|
||||||
#include "base/io/log/Tags.h"
|
#include "base/io/log/Tags.h"
|
||||||
#include "base/kernel/interfaces/IJsonReader.h"
|
#include "base/kernel/interfaces/IJsonReader.h"
|
||||||
|
#include "base/kernel/Process.h"
|
||||||
|
#include "base/kernel/Versions.h"
|
||||||
#include "base/net/dns/Dns.h"
|
#include "base/net/dns/Dns.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
|
@ -38,7 +41,6 @@
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <uv.h>
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef XMRIG_FEATURE_TLS
|
#ifdef XMRIG_FEATURE_TLS
|
||||||
|
@ -138,38 +140,21 @@ bool xmrig::BaseConfig::save()
|
||||||
|
|
||||||
void xmrig::BaseConfig::printVersions()
|
void xmrig::BaseConfig::printVersions()
|
||||||
{
|
{
|
||||||
char buf[256] = { 0 };
|
const auto &versions = Process::versions();
|
||||||
|
|
||||||
# if defined(__clang__)
|
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());
|
||||||
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;
|
|
||||||
|
|
||||||
# if defined(XMRIG_FEATURE_TLS)
|
# if defined(XMRIG_FEATURE_TLS)
|
||||||
{
|
std::string libs = fmt::format("{}/{} ", Versions::kTls, versions.get(Versions::kTls));
|
||||||
# if defined(LIBRESSL_VERSION_TEXT)
|
# else
|
||||||
snprintf(buf, sizeof buf, "LibreSSL/%s ", LIBRESSL_VERSION_TEXT + 9);
|
std::string libs;
|
||||||
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
|
|
||||||
}
|
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
# if defined(XMRIG_FEATURE_HWLOC)
|
# if defined(XMRIG_FEATURE_HWLOC)
|
||||||
libs += Cpu::info()->backend();
|
libs += Cpu::info()->backend();
|
||||||
# endif
|
# 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
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* 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 <uv.h>
|
||||||
|
|
||||||
|
|
||||||
#include "base/net/https/HttpsServer.h"
|
#include "base/net/https/HttpsServer.h"
|
||||||
|
#include "base/io/log/Log.h"
|
||||||
#include "base/net/https/HttpsContext.h"
|
#include "base/net/https/HttpsContext.h"
|
||||||
#include "base/net/tls/TlsContext.h"
|
#include "base/net/tls/TlsContext.h"
|
||||||
#include "base/net/tools/NetBuffer.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) :
|
xmrig::HttpsServer::HttpsServer(const std::shared_ptr<IHttpListener> &listener) :
|
||||||
m_listener(listener)
|
m_listener(listener)
|
||||||
{
|
{
|
||||||
|
@ -39,7 +56,14 @@ xmrig::HttpsServer::~HttpsServer()
|
||||||
|
|
||||||
bool xmrig::HttpsServer::setTls(const TlsConfig &config)
|
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;
|
return m_tls != nullptr;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,13 @@
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* 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
|
#ifndef XMRIG_HTTPSSERVER_H
|
||||||
|
|
Loading…
Reference in a new issue