mirror of
https://github.com/xmrig/xmrig.git
synced 2025-12-06 23:52:38 -05:00
Compare commits
15 Commits
v6.22.2
...
07d53fb77e
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
07d53fb77e | ||
|
|
3ded8e6734 | ||
|
|
774f630e14 | ||
|
|
d6a1c98314 | ||
|
|
75283445fd | ||
|
|
45084cb718 | ||
|
|
bc150fec04 | ||
|
|
9a0cd68ea5 | ||
|
|
603eb261c5 | ||
|
|
de97f3492e | ||
|
|
8a167cb2a7 | ||
|
|
d0953a507c | ||
|
|
fe8e198106 | ||
|
|
dfc3b4632a | ||
|
|
6106bf30de |
@@ -156,14 +156,12 @@ endif()
|
||||
if (XMRIG_OS_WIN)
|
||||
list(APPEND SOURCES_OS
|
||||
res/app.rc
|
||||
src/App_win.cpp
|
||||
src/crypto/common/VirtualMemory_win.cpp
|
||||
)
|
||||
|
||||
set(EXTRA_LIBS ws2_32 psapi iphlpapi userenv)
|
||||
elseif (XMRIG_OS_APPLE)
|
||||
list(APPEND SOURCES_OS
|
||||
src/App_unix.cpp
|
||||
src/crypto/common/VirtualMemory_unix.cpp
|
||||
)
|
||||
|
||||
@@ -172,7 +170,6 @@ elseif (XMRIG_OS_APPLE)
|
||||
set(EXTRA_LIBS ${IOKIT_LIBRARY} ${CORESERVICES_LIBRARY})
|
||||
else()
|
||||
list(APPEND SOURCES_OS
|
||||
src/App_unix.cpp
|
||||
src/crypto/common/VirtualMemory_unix.cpp
|
||||
)
|
||||
|
||||
@@ -190,7 +187,7 @@ else()
|
||||
endif()
|
||||
endif()
|
||||
|
||||
add_definitions(-DXMRIG_MINER_PROJECT -DXMRIG_JSON_SINGLE_LINE_ARRAY)
|
||||
add_definitions(-DXMRIG_MINER_PROJECT -DXMRIG_LEGACY -DXMRIG_JSON_SINGLE_LINE_ARRAY)
|
||||
add_definitions(-D__STDC_FORMAT_MACROS -DUNICODE -D_FILE_OFFSET_BITS=64)
|
||||
|
||||
find_package(UV REQUIRED)
|
||||
|
||||
@@ -20,7 +20,7 @@ VS_VERSION_INFO VERSIONINFO
|
||||
BEGIN
|
||||
BLOCK "000004b0"
|
||||
BEGIN
|
||||
VALUE "CompanyName", APP_SITE
|
||||
VALUE "CompanyName", APP_DOMAIN
|
||||
VALUE "FileDescription", APP_DESC
|
||||
VALUE "FileVersion", APP_VERSION
|
||||
VALUE "LegalCopyright", APP_COPYRIGHT
|
||||
|
||||
27
src/App.cpp
27
src/App.cpp
@@ -1,13 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -21,9 +14,15 @@
|
||||
*
|
||||
* 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 <cstdlib>
|
||||
#include <uv.h>
|
||||
|
||||
@@ -34,7 +33,6 @@
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/io/log/Tags.h"
|
||||
#include "base/io/Signals.h"
|
||||
#include "base/kernel/Platform.h"
|
||||
#include "core/config/Config.h"
|
||||
#include "core/Controller.h"
|
||||
#include "Summary.h"
|
||||
@@ -63,12 +61,7 @@ int xmrig::App::exec()
|
||||
|
||||
m_signals = std::make_shared<Signals>(this);
|
||||
|
||||
int rc = 0;
|
||||
if (background(rc)) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = m_controller->init();
|
||||
int rc = m_controller->init();
|
||||
if (rc != 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
19
src/App.h
19
src/App.h
@@ -1,13 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -21,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_APP_H
|
||||
@@ -60,7 +60,6 @@ protected:
|
||||
void onSignal(int signum) override;
|
||||
|
||||
private:
|
||||
bool background(int &rc);
|
||||
void close();
|
||||
|
||||
std::shared_ptr<Console> m_console;
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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 <cstdlib>
|
||||
#include <csignal>
|
||||
#include <cerrno>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#include "App.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "core/Controller.h"
|
||||
|
||||
|
||||
bool xmrig::App::background(int &rc)
|
||||
{
|
||||
if (!m_controller->isBackground()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int i = fork();
|
||||
if (i < 0) {
|
||||
rc = 1;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (i > 0) {
|
||||
rc = 0;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
i = setsid();
|
||||
|
||||
if (i < 0) {
|
||||
LOG_ERR("setsid() failed (errno = %d)", errno);
|
||||
}
|
||||
|
||||
i = chdir("/");
|
||||
if (i < 0) {
|
||||
LOG_ERR("chdir() failed (errno = %d)", errno);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -18,7 +18,7 @@
|
||||
|
||||
|
||||
#include "backend/common/Worker.h"
|
||||
#include "base/kernel/Platform.h"
|
||||
#include "base/kernel/OS.h"
|
||||
#include "crypto/common/VirtualMemory.h"
|
||||
|
||||
|
||||
@@ -28,6 +28,6 @@ xmrig::Worker::Worker(size_t id, int64_t affinity, int priority) :
|
||||
{
|
||||
m_node = VirtualMemory::bindToNUMANode(affinity);
|
||||
|
||||
Platform::trySetThreadAffinity(affinity);
|
||||
Platform::setThreadPriority(priority);
|
||||
OS::trySetThreadAffinity(affinity);
|
||||
OS::setThreadPriority(priority);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -26,6 +26,7 @@
|
||||
#include "base/io/Env.h"
|
||||
#include "base/io/json/Json.h"
|
||||
#include "base/kernel/Base.h"
|
||||
#include "base/kernel/OS.h"
|
||||
#include "base/tools/Chrono.h"
|
||||
#include "base/tools/Cvt.h"
|
||||
#include "core/config/Config.h"
|
||||
@@ -232,6 +233,6 @@ void xmrig::Api::genWorkerId(const String &id)
|
||||
{
|
||||
m_workerId = Env::expand(id);
|
||||
if (m_workerId.isEmpty()) {
|
||||
m_workerId = Env::hostname();
|
||||
m_workerId = OS::hostname();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -22,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/api/requests/ApiRequest.h"
|
||||
|
||||
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -22,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef XMRIG_APIREQUEST_H
|
||||
#define XMRIG_APIREQUEST_H
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/api/requests/HttpApiRequest.h"
|
||||
#include "3rdparty/llhttp/llhttp.h"
|
||||
#include "3rdparty/rapidjson/error/en.h"
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef XMRIG_HTTPAPIREQUEST_H
|
||||
#define XMRIG_HTTPAPIREQUEST_H
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ set(HEADERS_BASE
|
||||
src/base/kernel/Base.h
|
||||
src/base/kernel/config/BaseConfig.h
|
||||
src/base/kernel/config/BaseTransform.h
|
||||
src/base/kernel/config/Title.h
|
||||
src/base/kernel/private/Title.h
|
||||
src/base/kernel/constants.h
|
||||
src/base/kernel/Entry.h
|
||||
src/base/kernel/interfaces/IAsyncListener.h
|
||||
@@ -41,8 +41,10 @@ set(HEADERS_BASE
|
||||
src/base/kernel/interfaces/IStrategyListener.h
|
||||
src/base/kernel/interfaces/ITimerListener.h
|
||||
src/base/kernel/interfaces/IWatcherListener.h
|
||||
src/base/kernel/Platform.h
|
||||
src/base/kernel/Lib.h
|
||||
src/base/kernel/OS.h
|
||||
src/base/kernel/Process.h
|
||||
src/base/kernel/Versions.h
|
||||
src/base/net/dns/Dns.h
|
||||
src/base/net/dns/DnsConfig.h
|
||||
src/base/net/dns/DnsRecord.h
|
||||
@@ -109,10 +111,12 @@ set(SOURCES_BASE
|
||||
src/base/kernel/Base.cpp
|
||||
src/base/kernel/config/BaseConfig.cpp
|
||||
src/base/kernel/config/BaseTransform.cpp
|
||||
src/base/kernel/config/Title.cpp
|
||||
src/base/kernel/private/Title.cpp
|
||||
src/base/kernel/Entry.cpp
|
||||
src/base/kernel/Platform.cpp
|
||||
src/base/kernel/Lib.cpp
|
||||
src/base/kernel/OS.cpp
|
||||
src/base/kernel/Process.cpp
|
||||
src/base/kernel/Versions.cpp
|
||||
src/base/net/dns/Dns.cpp
|
||||
src/base/net/dns/DnsConfig.cpp
|
||||
src/base/net/dns/DnsRecord.cpp
|
||||
@@ -148,19 +152,22 @@ set(SOURCES_BASE
|
||||
if (WIN32)
|
||||
set(SOURCES_OS
|
||||
src/base/io/json/Json_win.cpp
|
||||
src/base/kernel/Platform_win.cpp
|
||||
src/base/kernel/Entry_win.cpp
|
||||
src/base/kernel/OS_win.cpp
|
||||
src/base/kernel/Process_win.cpp
|
||||
)
|
||||
elseif (APPLE)
|
||||
set(SOURCES_OS
|
||||
src/base/io/json/Json_unix.cpp
|
||||
src/base/kernel/Platform_mac.cpp
|
||||
src/base/kernel/Entry_unix.cpp
|
||||
src/base/kernel/OS_mac.cpp
|
||||
src/base/kernel/Process_unix.cpp
|
||||
)
|
||||
else()
|
||||
set(SOURCES_OS
|
||||
src/base/io/json/Json_unix.cpp
|
||||
src/base/kernel/Platform_unix.cpp
|
||||
src/base/kernel/Entry_unix.cpp
|
||||
src/base/kernel/OS_unix.cpp
|
||||
src/base/kernel/Process_unix.cpp
|
||||
)
|
||||
endif()
|
||||
@@ -168,7 +175,7 @@ endif()
|
||||
|
||||
if (WITH_HWLOC)
|
||||
list(APPEND SOURCES_OS
|
||||
src/base/kernel/Platform_hwloc.cpp
|
||||
src/base/kernel/OS_hwloc.cpp
|
||||
)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018 Lee Clagett <https://github.com/vtnerd>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -209,7 +209,7 @@ private:
|
||||
using Algorithms = std::vector<Algorithm>;
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif /* XMRIG_ALGORITHM_H */
|
||||
#endif // XMRIG_ALGORITHM_H
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -82,7 +82,7 @@ private:
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif /* XMRIG_COIN_H */
|
||||
#endif // XMRIG_COIN_H
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2011 Markku-Juhani O. Saarinen <mjos@iki.fi>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2011 Markku-Juhani O. Saarinen <mjos@iki.fi>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -23,7 +17,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <memory.h>
|
||||
|
||||
|
||||
|
||||
@@ -1,13 +1,7 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2011 Markku-Juhani O. Saarinen <mjos@iki.fi>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2011 Markku-Juhani O. Saarinen <mjos@iki.fi>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2015-2020 libuv project contributors.
|
||||
* Copyright (c) 2020 cohcho <https://github.com/cohcho>
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2015-2020 libuv project contributors.
|
||||
* Copyright (c) 2020 cohcho <https://github.com/cohcho>
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -14,16 +14,98 @@
|
||||
*
|
||||
* 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 "base/io/Console.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/io/Signals.h"
|
||||
#include "base/kernel/interfaces/IConsoleListener.h"
|
||||
#include "base/kernel/private/Title.h"
|
||||
#include "base/kernel/Process.h"
|
||||
#include "base/tools/Cvt.h"
|
||||
#include "base/tools/Handle.h"
|
||||
|
||||
|
||||
xmrig::Console::Console(IConsoleListener *listener)
|
||||
: m_listener(listener)
|
||||
#ifdef XMRIG_FEATURE_EVENTS
|
||||
# include "base/kernel/Events.h"
|
||||
# include "base/kernel/events/ConsoleEvent.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class Console::Private : public IConsoleListener
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE(Private)
|
||||
|
||||
Private();
|
||||
~Private() override;
|
||||
|
||||
# ifdef XMRIG_OS_WIN
|
||||
std::wstring title;
|
||||
# endif
|
||||
|
||||
IConsoleListener *listener = nullptr;
|
||||
|
||||
protected:
|
||||
void onConsoleCommand(char command) override;
|
||||
|
||||
private:
|
||||
static bool isSupported();
|
||||
|
||||
static void onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf);
|
||||
static void onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf);
|
||||
|
||||
char m_buf[1] = { 0 };
|
||||
uv_tty_t *m_tty = nullptr;
|
||||
};
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::Console::Console() :
|
||||
d(std::make_shared<Private>())
|
||||
{
|
||||
d->listener = d.get();
|
||||
}
|
||||
|
||||
|
||||
xmrig::Console::Console(IConsoleListener *listener) :
|
||||
d(std::make_shared<Private>())
|
||||
{
|
||||
d->listener = listener;
|
||||
}
|
||||
|
||||
|
||||
#ifdef XMRIG_OS_WIN
|
||||
void xmrig::Console::setTitle(const Title &title) const
|
||||
{
|
||||
SetConsoleTitleW(title.isEnabled() ? Cvt::toUtf16(title.value()).c_str() : d->title.c_str());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
xmrig::Console::Private::Private()
|
||||
{
|
||||
# ifdef XMRIG_OS_WIN
|
||||
{
|
||||
constexpr size_t kMaxTitleLength = 8192;
|
||||
|
||||
wchar_t title_w[kMaxTitleLength]{};
|
||||
title = { title_w, GetConsoleTitleW(title_w, kMaxTitleLength) };
|
||||
}
|
||||
# endif
|
||||
|
||||
if (!isSupported()) {
|
||||
return;
|
||||
}
|
||||
@@ -37,11 +119,11 @@ xmrig::Console::Console(IConsoleListener *listener)
|
||||
}
|
||||
|
||||
uv_tty_set_mode(m_tty, UV_TTY_MODE_RAW);
|
||||
uv_read_start(reinterpret_cast<uv_stream_t*>(m_tty), Console::onAllocBuffer, Console::onRead);
|
||||
uv_read_start(reinterpret_cast<uv_stream_t*>(m_tty), onAllocBuffer, onRead);
|
||||
}
|
||||
|
||||
|
||||
xmrig::Console::~Console()
|
||||
xmrig::Console::Private::~Private()
|
||||
{
|
||||
uv_tty_reset_mode();
|
||||
|
||||
@@ -49,28 +131,45 @@ xmrig::Console::~Console()
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::Console::isSupported()
|
||||
void xmrig::Console::Private::onConsoleCommand(char command)
|
||||
{
|
||||
# ifdef XMRIG_FEATURE_EVENTS
|
||||
if (command == 3) {
|
||||
LOG_WARN("%s " YELLOW_BOLD("Ctrl+C ") YELLOW("received, exiting"), Signals::tag());
|
||||
|
||||
Process::exit(0);
|
||||
}
|
||||
else {
|
||||
Process::events().send<ConsoleEvent>(command);
|
||||
}
|
||||
# else
|
||||
assert(!command);
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::Console::Private::isSupported()
|
||||
{
|
||||
const uv_handle_type type = uv_guess_handle(0);
|
||||
return type == UV_TTY || type == UV_NAMED_PIPE;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Console::onAllocBuffer(uv_handle_t *handle, size_t, uv_buf_t *buf)
|
||||
void xmrig::Console::Private::onAllocBuffer(uv_handle_t *handle, size_t, uv_buf_t *buf)
|
||||
{
|
||||
auto console = static_cast<Console*>(handle->data);
|
||||
auto console = static_cast<Private *>(handle->data);
|
||||
buf->len = 1;
|
||||
buf->base = console->m_buf;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Console::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
|
||||
void xmrig::Console::Private::onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf)
|
||||
{
|
||||
if (nread < 0) {
|
||||
return uv_close(reinterpret_cast<uv_handle_t*>(stream), nullptr);
|
||||
}
|
||||
|
||||
if (nread == 1) {
|
||||
static_cast<Console*>(stream->data)->m_listener->onConsoleCommand(buf->base[0]);
|
||||
static_cast<Private *>(stream->data)->listener->onConsoleCommand(*buf->base);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -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_CONSOLE_H
|
||||
@@ -23,45 +30,32 @@
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
using uv_buf_t = struct uv_buf_t;
|
||||
using uv_handle_t = struct uv_handle_s;
|
||||
using uv_stream_t = struct uv_stream_s;
|
||||
using uv_tty_t = struct uv_tty_s;
|
||||
|
||||
#ifdef XMRIG_OS_WIN
|
||||
using ssize_t = intptr_t;
|
||||
#else
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class Title;
|
||||
class IConsoleListener;
|
||||
|
||||
|
||||
class Console
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Console)
|
||||
XMRIG_DISABLE_COPY_MOVE(Console)
|
||||
|
||||
Console(IConsoleListener *listener);
|
||||
~Console();
|
||||
Console();
|
||||
explicit Console(IConsoleListener *listener);
|
||||
~Console() = default;
|
||||
|
||||
# ifdef XMRIG_OS_WIN
|
||||
void setTitle(const Title &title) const;
|
||||
# endif
|
||||
|
||||
private:
|
||||
static bool isSupported();
|
||||
|
||||
static void onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf);
|
||||
static void onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf);
|
||||
|
||||
char m_buf[1] = { 0 };
|
||||
IConsoleListener *m_listener;
|
||||
uv_tty_t *m_tty = nullptr;
|
||||
XMRIG_DECL_PRIVATE()
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif /* XMRIG_CONSOLE_H */
|
||||
#endif // XMRIG_CONSOLE_H
|
||||
|
||||
@@ -17,29 +17,15 @@
|
||||
*/
|
||||
|
||||
#include "base/io/Env.h"
|
||||
#include "base/kernel/OS.h"
|
||||
#include "base/kernel/Process.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
#include <regex>
|
||||
#include <uv.h>
|
||||
#include <map>
|
||||
|
||||
|
||||
#ifndef _WIN32
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef UV_MAXHOSTNAMESIZE
|
||||
# ifdef MAXHOSTNAMELEN
|
||||
# define UV_MAXHOSTNAMESIZE (MAXHOSTNAMELEN + 1)
|
||||
# else
|
||||
# define UV_MAXHOSTNAMESIZE 256
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
@@ -51,17 +37,17 @@ static void createVariables()
|
||||
{
|
||||
variables.insert({ "XMRIG_VERSION", APP_VERSION });
|
||||
variables.insert({ "XMRIG_KIND", APP_KIND });
|
||||
variables.insert({ "XMRIG_HOSTNAME", Env::hostname() });
|
||||
variables.insert({ "XMRIG_EXE", Process::exepath() });
|
||||
variables.insert({ "XMRIG_EXE_DIR", Process::location(Process::ExeLocation) });
|
||||
variables.insert({ "XMRIG_CWD", Process::location(Process::CwdLocation) });
|
||||
variables.insert({ "XMRIG_HOME_DIR", Process::location(Process::HomeLocation) });
|
||||
variables.insert({ "XMRIG_TEMP_DIR", Process::location(Process::TempLocation) });
|
||||
variables.insert({ "XMRIG_DATA_DIR", Process::location(Process::DataLocation) });
|
||||
variables.insert({ "XMRIG_HOSTNAME", OS::hostname() });
|
||||
variables.insert({ "XMRIG_EXE", Process::locate(Process::ExePathLocation) });
|
||||
variables.insert({ "XMRIG_EXE_DIR", Process::locate(Process::ExeLocation) });
|
||||
variables.insert({ "XMRIG_CWD", Process::locate(Process::CwdLocation) });
|
||||
variables.insert({ "XMRIG_HOME_DIR", Process::locate(Process::HomeLocation) });
|
||||
variables.insert({ "XMRIG_TEMP_DIR", Process::locate(Process::TempLocation) });
|
||||
variables.insert({ "XMRIG_DATA_DIR", Process::locate(Process::DataLocation) });
|
||||
|
||||
String hostname = "HOSTNAME";
|
||||
if (!getenv(hostname)) { // NOLINT(concurrency-mt-unsafe)
|
||||
variables.insert({ std::move(hostname), Env::hostname() });
|
||||
variables.insert({ std::move(hostname), OS::hostname() });
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -138,15 +124,3 @@ xmrig::String xmrig::Env::get(const String &name, const std::map<String, String>
|
||||
|
||||
return static_cast<const char *>(getenv(name)); // NOLINT(concurrency-mt-unsafe)
|
||||
}
|
||||
|
||||
|
||||
xmrig::String xmrig::Env::hostname()
|
||||
{
|
||||
char buf[UV_MAXHOSTNAMESIZE]{};
|
||||
|
||||
if (gethostname(buf, sizeof(buf)) == 0) {
|
||||
return static_cast<const char *>(buf);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -34,7 +34,6 @@ class Env
|
||||
public:
|
||||
static String expand(const char *in, const std::map<String, String> &extra = {});
|
||||
static String get(const String &name, const std::map<String, String> &extra = {});
|
||||
static String hostname();
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -14,25 +14,113 @@
|
||||
*
|
||||
* 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 "base/kernel/interfaces/ISignalListener.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/io/log/Tags.h"
|
||||
#include "base/io/Signals.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/kernel/interfaces/ISignalListener.h"
|
||||
#include "base/kernel/Process.h"
|
||||
#include "base/tools/Handle.h"
|
||||
|
||||
|
||||
#ifdef SIGUSR1
|
||||
static const int signums[xmrig::Signals::kSignalsCount] = { SIGHUP, SIGINT, SIGTERM, SIGUSR1 };
|
||||
#else
|
||||
static const int signums[xmrig::Signals::kSignalsCount] = { SIGHUP, SIGINT, SIGTERM };
|
||||
#ifdef XMRIG_FEATURE_EVENTS
|
||||
# include "base/kernel/Events.h"
|
||||
# include "base/kernel/events/SignalEvent.h"
|
||||
#endif
|
||||
|
||||
|
||||
xmrig::Signals::Signals(ISignalListener *listener)
|
||||
: m_listener(listener)
|
||||
#include <csignal>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
#ifdef SIGUSR1
|
||||
constexpr static const size_t kSignalsCount = 4;
|
||||
constexpr static const int signums[kSignalsCount] = { SIGHUP, SIGINT, SIGTERM, SIGUSR1 };
|
||||
#else
|
||||
constexpr static const size_t kSignalsCount = 3;
|
||||
constexpr static const int signums[kSignalsCount] = { SIGHUP, SIGINT, SIGTERM };
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_EVENTS
|
||||
static const char *signame(int signum)
|
||||
{
|
||||
switch (signum) {
|
||||
case SIGHUP:
|
||||
return "SIGHUP";
|
||||
|
||||
case SIGINT:
|
||||
return "SIGINT";
|
||||
|
||||
case SIGTERM:
|
||||
return "SIGTERM";
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
class Signals::Private : public ISignalListener
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE(Private)
|
||||
|
||||
Private();
|
||||
~Private() override;
|
||||
|
||||
ISignalListener *listener = nullptr;
|
||||
|
||||
protected:
|
||||
void onSignal(int signum) override;
|
||||
|
||||
private:
|
||||
static void onSignal(uv_signal_t *handle, int signum);
|
||||
|
||||
|
||||
|
||||
uv_signal_t *signals[kSignalsCount]{};
|
||||
};
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::Signals::Signals() :
|
||||
d(std::make_shared<Private>())
|
||||
{
|
||||
d->listener = d.get();
|
||||
}
|
||||
|
||||
|
||||
xmrig::Signals::Signals(ISignalListener *listener) :
|
||||
d(std::make_shared<Private>())
|
||||
{
|
||||
d->listener = listener;
|
||||
}
|
||||
|
||||
|
||||
const char *xmrig::Signals::tag()
|
||||
{
|
||||
static const char *tag = YELLOW_BG_BOLD(WHITE_BOLD_S " signal ");
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
||||
xmrig::Signals::Private::Private()
|
||||
{
|
||||
# ifndef XMRIG_OS_WIN
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
@@ -42,47 +130,44 @@ xmrig::Signals::Signals(ISignalListener *listener)
|
||||
auto signal = new uv_signal_t;
|
||||
signal->data = this;
|
||||
|
||||
m_signals[i] = signal;
|
||||
signals[i] = signal;
|
||||
|
||||
uv_signal_init(uv_default_loop(), signal);
|
||||
uv_signal_start(signal, Signals::onSignal, signums[i]);
|
||||
uv_signal_start(signal, onSignal, signums[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
xmrig::Signals::~Signals()
|
||||
xmrig::Signals::Private::~Private()
|
||||
{
|
||||
for (auto signal : m_signals) {
|
||||
for (auto signal : signals) {
|
||||
Handle::close(signal);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Signals::onSignal(uv_signal_t *handle, int signum)
|
||||
void xmrig::Signals::Private::onSignal(int signum)
|
||||
{
|
||||
# ifdef XMRIG_FEATURE_EVENTS
|
||||
Process::events().send<SignalEvent>(signum);
|
||||
|
||||
switch (signum)
|
||||
{
|
||||
case SIGHUP:
|
||||
LOG_WARN("%s " YELLOW("SIGHUP received, exiting"), Tags::signal());
|
||||
break;
|
||||
|
||||
case SIGTERM:
|
||||
LOG_WARN("%s " YELLOW("SIGTERM received, exiting"), Tags::signal());
|
||||
break;
|
||||
|
||||
case SIGINT:
|
||||
LOG_WARN("%s " YELLOW("SIGINT received, exiting"), Tags::signal());
|
||||
LOG_WARN("%s " YELLOW_BOLD("%s ") YELLOW("received, exiting"), tag(), signame(signum));
|
||||
Process::exit(128 + signum);
|
||||
break;
|
||||
|
||||
# ifdef SIGUSR1
|
||||
case SIGUSR1:
|
||||
LOG_V5("%s " WHITE_BOLD("SIGUSR1 received"), Tags::signal());
|
||||
break;
|
||||
# endif
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
static_cast<Signals *>(handle->data)->m_listener->onSignal(signum);
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Signals::Private::onSignal(uv_signal_t *handle, int signum)
|
||||
{
|
||||
static_cast<Private *>(handle->data)->listener->onSignal(signum);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -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_SIGNALS_H
|
||||
@@ -23,13 +30,6 @@
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
#include <csignal>
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
using uv_signal_t = struct uv_signal_s;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
@@ -39,28 +39,20 @@ class ISignalListener;
|
||||
class Signals
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Signals)
|
||||
XMRIG_DISABLE_COPY_MOVE(Signals)
|
||||
|
||||
# ifdef SIGUSR1
|
||||
constexpr static const size_t kSignalsCount = 4;
|
||||
# else
|
||||
constexpr static const size_t kSignalsCount = 3;
|
||||
# endif
|
||||
Signals();
|
||||
explicit Signals(ISignalListener *listener);
|
||||
~Signals() = default;
|
||||
|
||||
Signals(ISignalListener *listener);
|
||||
~Signals();
|
||||
static const char *tag();
|
||||
|
||||
private:
|
||||
void close(int signum);
|
||||
|
||||
static void onSignal(uv_signal_t *handle, int signum);
|
||||
|
||||
ISignalListener *m_listener;
|
||||
uv_signal_t *m_signals[kSignalsCount]{};
|
||||
XMRIG_DECL_PRIVATE()
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif /* XMRIG_SIGNALS_H */
|
||||
#endif // XMRIG_SIGNALS_H
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -20,37 +14,45 @@
|
||||
*
|
||||
* 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/kernel/interfaces/IWatcherListener.h"
|
||||
#include "base/io/Watcher.h"
|
||||
#include "base/kernel/interfaces/IWatcherListener.h"
|
||||
#include "base/tools/Handle.h"
|
||||
#include "base/tools/Timer.h"
|
||||
|
||||
|
||||
xmrig::Watcher::Watcher(const String &path, IWatcherListener *listener) :
|
||||
m_listener(listener),
|
||||
m_path(path)
|
||||
m_path(path),
|
||||
m_listener(listener)
|
||||
{
|
||||
m_timer = new Timer(this);
|
||||
m_timer = std::make_shared<Timer>(this);
|
||||
|
||||
m_fsEvent = new uv_fs_event_t;
|
||||
m_fsEvent->data = this;
|
||||
uv_fs_event_init(uv_default_loop(), m_fsEvent);
|
||||
|
||||
start();
|
||||
startTimer();
|
||||
}
|
||||
|
||||
|
||||
xmrig::Watcher::~Watcher()
|
||||
{
|
||||
delete m_timer;
|
||||
Handle::close(m_event);
|
||||
}
|
||||
|
||||
Handle::close(m_fsEvent);
|
||||
|
||||
void xmrig::Watcher::onTimer(const Timer * /*timer*/)
|
||||
{
|
||||
if (m_event) {
|
||||
reload();
|
||||
}
|
||||
else {
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -60,14 +62,7 @@ void xmrig::Watcher::onFsEvent(uv_fs_event_t *handle, const char *filename, int,
|
||||
return;
|
||||
}
|
||||
|
||||
static_cast<Watcher *>(handle->data)->queueUpdate();
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Watcher::queueUpdate()
|
||||
{
|
||||
m_timer->stop();
|
||||
m_timer->start(kDelay, 0);
|
||||
static_cast<Watcher *>(handle->data)->startTimer();
|
||||
}
|
||||
|
||||
|
||||
@@ -75,8 +70,8 @@ void xmrig::Watcher::reload()
|
||||
{
|
||||
m_listener->onFileChanged(m_path);
|
||||
|
||||
# ifndef _WIN32
|
||||
uv_fs_event_stop(m_fsEvent);
|
||||
# ifndef XMRIG_OS_WIN
|
||||
stop();
|
||||
start();
|
||||
# endif
|
||||
}
|
||||
@@ -84,5 +79,23 @@ void xmrig::Watcher::reload()
|
||||
|
||||
void xmrig::Watcher::start()
|
||||
{
|
||||
uv_fs_event_start(m_fsEvent, xmrig::Watcher::onFsEvent, m_path, 0);
|
||||
if (!m_event) {
|
||||
m_event = new uv_fs_event_t;
|
||||
m_event->data = this;
|
||||
uv_fs_event_init(uv_default_loop(), m_event);
|
||||
}
|
||||
|
||||
uv_fs_event_start(m_event, onFsEvent, m_path, 0);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Watcher::startTimer()
|
||||
{
|
||||
m_timer->singleShot(kDelay);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Watcher::stop()
|
||||
{
|
||||
uv_fs_event_stop(m_event);
|
||||
}
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -20,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_WATCHER_H
|
||||
@@ -30,7 +31,10 @@
|
||||
#include "base/tools/String.h"
|
||||
|
||||
|
||||
typedef struct uv_fs_event_s uv_fs_event_t;
|
||||
#include <memory>
|
||||
|
||||
|
||||
using uv_fs_event_t = struct uv_fs_event_s;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
@@ -43,29 +47,32 @@ class Timer;
|
||||
class Watcher : public ITimerListener
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Watcher)
|
||||
|
||||
Watcher(const String &path, IWatcherListener *listener);
|
||||
~Watcher() override;
|
||||
|
||||
protected:
|
||||
inline void onTimer(const Timer *) override { reload(); }
|
||||
void onTimer(const Timer *timer) override;
|
||||
|
||||
private:
|
||||
constexpr static int kDelay = 500;
|
||||
|
||||
static void onFsEvent(uv_fs_event_t *handle, const char *filename, int events, int status);
|
||||
|
||||
void queueUpdate();
|
||||
void reload();
|
||||
void start();
|
||||
void startTimer();
|
||||
void stop();
|
||||
|
||||
const String m_path;
|
||||
IWatcherListener *m_listener;
|
||||
String m_path;
|
||||
Timer *m_timer;
|
||||
uv_fs_event_t *m_fsEvent;
|
||||
std::shared_ptr<Timer> m_timer;
|
||||
uv_fs_event_t *m_event = nullptr;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif /* XMRIG_WATCHER_H */
|
||||
#endif // XMRIG_WATCHER_H
|
||||
|
||||
@@ -34,37 +34,21 @@
|
||||
#include "3rdparty/rapidjson/istreamwrapper.h"
|
||||
#include "3rdparty/rapidjson/ostreamwrapper.h"
|
||||
#include "3rdparty/rapidjson/prettywriter.h"
|
||||
#include "base/tools/Cvt.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
#if defined(_MSC_VER) || defined (__GNUC__)
|
||||
static std::wstring toUtf16(const char *str)
|
||||
{
|
||||
const int size = static_cast<int>(strlen(str));
|
||||
std::wstring ret;
|
||||
|
||||
int len = MultiByteToWideChar(CP_UTF8, 0, str, size, nullptr, 0);
|
||||
if (len > 0) {
|
||||
ret.resize(static_cast<size_t>(len));
|
||||
MultiByteToWideChar(CP_UTF8, 0, str, size, &ret[0], len);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
# define OPEN_IFS(name) \
|
||||
std::ifstream ifs(toUtf16(name), std::ios_base::in | std::ios_base::binary); \
|
||||
std::ifstream ifs(Cvt::toUtf16(name), std::ios_base::in | std::ios_base::binary); \
|
||||
if (!ifs.is_open()) { \
|
||||
return false; \
|
||||
}
|
||||
#elif defined(__GNUC__)
|
||||
# define OPEN_IFS(name) \
|
||||
const int fd = _wopen(toUtf16(name).c_str(), _O_RDONLY | _O_BINARY); \
|
||||
const int fd = _wopen(Cvt::toUtf16(name).c_str(), _O_RDONLY | _O_BINARY); \
|
||||
if (fd == -1) { \
|
||||
return false; \
|
||||
} \
|
||||
@@ -99,12 +83,12 @@ bool xmrig::Json::save(const char *fileName, const rapidjson::Document &doc)
|
||||
constexpr const std::ios_base::openmode mode = std::ios_base::out | std::ios_base::binary | std::ios_base::trunc;
|
||||
|
||||
# if defined(_MSC_VER)
|
||||
std::ofstream ofs(toUtf16(fileName), mode);
|
||||
std::ofstream ofs(Cvt::toUtf16(fileName), mode);
|
||||
if (!ofs.is_open()) {
|
||||
return false;
|
||||
}
|
||||
# elif defined(__GNUC__)
|
||||
const int fd = _wopen(toUtf16(fileName).c_str(), _O_WRONLY | _O_BINARY | _O_CREAT | _O_TRUNC, _S_IWRITE);
|
||||
const int fd = _wopen(Cvt::toUtf16(fileName).c_str(), _O_WRONLY | _O_BINARY | _O_CREAT | _O_TRUNC, _S_IWRITE);
|
||||
if (fd == -1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/io/log/FileLogWriter.h"
|
||||
#include "base/io/Env.h"
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2019 Spudz76 <https://github.com/Spudz76>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -15,9 +15,16 @@
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifdef WIN32
|
||||
#ifdef XMRIG_OS_WIN
|
||||
# include <winsock2.h>
|
||||
# include <windows.h>
|
||||
#endif
|
||||
@@ -25,40 +32,149 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <cstdarg>
|
||||
#include <cstring>
|
||||
#include <ctime>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
#include <uv.h>
|
||||
#include <vector>
|
||||
|
||||
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/kernel/interfaces/ILogBackend.h"
|
||||
#include "base/tools/Chrono.h"
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_EVENTS
|
||||
# include "base/kernel/Events.h"
|
||||
# include "base/kernel/events/LogEvent.h"
|
||||
# include "base/kernel/private/LogConfig.h"
|
||||
# include "base/kernel/Process.h"
|
||||
#else
|
||||
# include "base/kernel/interfaces/ILogBackend.h"
|
||||
#endif
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
bool Log::m_background = false;
|
||||
bool Log::m_colors = true;
|
||||
LogPrivate *Log::d = nullptr;
|
||||
uint32_t Log::m_verbose = 0;
|
||||
|
||||
|
||||
static char buf[Log::kMaxBufferSize]{};
|
||||
static std::mutex mutex;
|
||||
|
||||
|
||||
static const char *colors_map[] = {
|
||||
RED_BOLD_S, // EMERG
|
||||
RED_BOLD_S, // ALERT
|
||||
RED_BOLD_S, // CRIT
|
||||
RED_S, // ERR
|
||||
YELLOW_S, // WARNING
|
||||
WHITE_BOLD_S, // NOTICE
|
||||
nullptr, // INFO
|
||||
# ifdef WIN32
|
||||
BLACK_BOLD_S // DEBUG
|
||||
RED_BOLD_S "E ", // EMERG
|
||||
RED_BOLD_S "A ", // ALERT
|
||||
RED_BOLD_S "C ", // CRIT
|
||||
RED_S "E ", // ERR
|
||||
YELLOW_S "W ", // WARNING
|
||||
WHITE_BOLD_S "N ", // NOTICE
|
||||
"I ", // INFO
|
||||
"1 ", // V1
|
||||
"2 ", // V2
|
||||
"3 ", // V3
|
||||
"4 ", // V4
|
||||
# ifdef XMRIG_OS_WIN
|
||||
BLACK_BOLD_S "5 ", // V5
|
||||
BLACK_BOLD_S "D " // DEBUG
|
||||
# else
|
||||
BRIGHT_BLACK_S // DEBUG
|
||||
BRIGHT_BLACK_S "5 ", // V5
|
||||
BRIGHT_BLACK_S "D " // DEBUG
|
||||
# endif
|
||||
};
|
||||
|
||||
|
||||
static void log_endl(size_t &size)
|
||||
{
|
||||
# ifdef XMRIG_OS_WIN
|
||||
memcpy(buf + size, CLEAR "\r\n", 7);
|
||||
size += 6;
|
||||
# else
|
||||
memcpy(buf + size, CLEAR "\n", 6);
|
||||
size += 5;
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
static void log_color(Log::Level level, size_t &size)
|
||||
{
|
||||
if (level == Log::NONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
const char *color = colors_map[level];
|
||||
if (color == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const size_t s = strlen(color);
|
||||
memcpy(buf + size, color, s); // NOLINT(bugprone-not-null-terminated-result)
|
||||
|
||||
size += s;
|
||||
}
|
||||
|
||||
|
||||
static uint64_t log_timestamp(Log::Level level, size_t &size, size_t &offset)
|
||||
{
|
||||
const uint64_t ms = Chrono::currentMSecsSinceEpoch();
|
||||
|
||||
if (level == Log::NONE) {
|
||||
return ms;
|
||||
}
|
||||
|
||||
time_t now = ms / 1000;
|
||||
tm stime{};
|
||||
|
||||
# ifdef XMRIG_OS_WIN
|
||||
localtime_s(&stime, &now);
|
||||
# else
|
||||
localtime_r(&now, &stime);
|
||||
# endif
|
||||
|
||||
const int rc = snprintf(buf, sizeof(buf) - 1, "[%d-%02d-%02d %02d:%02d:%02d" BLACK_BOLD(".%03d") "] ",
|
||||
stime.tm_year + 1900,
|
||||
stime.tm_mon + 1,
|
||||
stime.tm_mday,
|
||||
stime.tm_hour,
|
||||
stime.tm_min,
|
||||
stime.tm_sec,
|
||||
static_cast<int>(ms % 1000)
|
||||
);
|
||||
|
||||
if (rc > 0) {
|
||||
size = offset = static_cast<size_t>(rc);
|
||||
}
|
||||
|
||||
return ms;
|
||||
}
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_EVENTS
|
||||
static void log_print(Log::Level level, const char *fmt, va_list args)
|
||||
{
|
||||
size_t size = 0;
|
||||
size_t offset = 0;
|
||||
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
|
||||
const uint64_t ts = log_timestamp(level, size, offset);
|
||||
log_color(level, size);
|
||||
|
||||
const int rc = vsnprintf(buf + size, sizeof(buf) - offset - 32, fmt, args);
|
||||
if (rc < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
size += std::min(static_cast<size_t>(rc), sizeof(buf) - offset - 32);
|
||||
log_endl(size);
|
||||
|
||||
Process::events().post<LogEvent>(ts, level, buf, offset, size);
|
||||
}
|
||||
#else
|
||||
class LogPrivate
|
||||
{
|
||||
public:
|
||||
@@ -70,46 +186,43 @@ public:
|
||||
|
||||
inline ~LogPrivate()
|
||||
{
|
||||
for (auto backend : m_backends) {
|
||||
for (auto backend : backends) {
|
||||
delete backend;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline void add(ILogBackend *backend) { m_backends.push_back(backend); }
|
||||
|
||||
|
||||
void print(Log::Level level, const char *fmt, va_list args)
|
||||
{
|
||||
size_t size = 0;
|
||||
size_t offset = 0;
|
||||
|
||||
std::lock_guard<std::mutex> lock(m_mutex);
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
|
||||
if (Log::isBackground() && m_backends.empty()) {
|
||||
if (Log::isBackground() && backends.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const uint64_t ts = timestamp(level, size, offset);
|
||||
color(level, size);
|
||||
const uint64_t ts = log_timestamp(level, size, offset);
|
||||
log_color(level, size);
|
||||
|
||||
const int rc = vsnprintf(m_buf + size, sizeof (m_buf) - offset - 32, fmt, args);
|
||||
const int rc = vsnprintf(buf + size, sizeof (buf) - offset - 32, fmt, args);
|
||||
if (rc < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
size += std::min(static_cast<size_t>(rc), sizeof (m_buf) - offset - 32);
|
||||
endl(size);
|
||||
size += std::min(static_cast<size_t>(rc), sizeof (buf) - offset - 32);
|
||||
log_endl(size);
|
||||
|
||||
std::string txt(m_buf);
|
||||
std::string txt(buf);
|
||||
size_t i = 0;
|
||||
while ((i = txt.find(CSI)) != std::string::npos) {
|
||||
txt.erase(i, txt.find('m', i) - i + 1);
|
||||
}
|
||||
|
||||
if (!m_backends.empty()) {
|
||||
for (auto backend : m_backends) {
|
||||
backend->print(ts, level, m_buf, offset, size, true);
|
||||
if (!backends.empty()) {
|
||||
for (auto backend : backends) {
|
||||
backend->print(ts, level, buf, offset, size, true);
|
||||
backend->print(ts, level, txt.c_str(), offset ? (offset - 11) : 0, txt.size(), false);
|
||||
}
|
||||
}
|
||||
@@ -120,94 +233,21 @@ public:
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
inline uint64_t timestamp(Log::Level level, size_t &size, size_t &offset)
|
||||
{
|
||||
const uint64_t ms = Chrono::currentMSecsSinceEpoch();
|
||||
|
||||
if (level == Log::NONE) {
|
||||
return ms;
|
||||
}
|
||||
|
||||
time_t now = ms / 1000;
|
||||
tm stime{};
|
||||
|
||||
# ifdef _WIN32
|
||||
localtime_s(&stime, &now);
|
||||
# else
|
||||
localtime_r(&now, &stime);
|
||||
# endif
|
||||
|
||||
const int rc = snprintf(m_buf, sizeof(m_buf) - 1, "[%d-%02d-%02d %02d:%02d:%02d" BLACK_BOLD(".%03d") "] ",
|
||||
stime.tm_year + 1900,
|
||||
stime.tm_mon + 1,
|
||||
stime.tm_mday,
|
||||
stime.tm_hour,
|
||||
stime.tm_min,
|
||||
stime.tm_sec,
|
||||
static_cast<int>(ms % 1000)
|
||||
);
|
||||
|
||||
if (rc > 0) {
|
||||
size = offset = static_cast<size_t>(rc);
|
||||
}
|
||||
|
||||
return ms;
|
||||
}
|
||||
|
||||
|
||||
inline void color(Log::Level level, size_t &size)
|
||||
{
|
||||
if (level == Log::NONE) {
|
||||
return;
|
||||
}
|
||||
|
||||
const char *color = colors_map[level];
|
||||
if (color == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
const size_t s = strlen(color);
|
||||
memcpy(m_buf + size, color, s);
|
||||
|
||||
size += s;
|
||||
}
|
||||
|
||||
|
||||
inline void endl(size_t &size)
|
||||
{
|
||||
# ifdef _WIN32
|
||||
memcpy(m_buf + size, CLEAR "\r\n", 7);
|
||||
size += 6;
|
||||
# else
|
||||
memcpy(m_buf + size, CLEAR "\n", 6);
|
||||
size += 5;
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
char m_buf[Log::kMaxBufferSize]{};
|
||||
std::mutex m_mutex;
|
||||
std::vector<ILogBackend*> m_backends;
|
||||
std::vector<ILogBackend*> backends;
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
bool Log::m_background = false;
|
||||
bool Log::m_colors = true;
|
||||
LogPrivate *Log::d = nullptr;
|
||||
uint32_t Log::m_verbose = 0;
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#ifndef XMRIG_FEATURE_EVENTS
|
||||
void xmrig::Log::add(ILogBackend *backend)
|
||||
{
|
||||
assert(d != nullptr);
|
||||
|
||||
if (d) {
|
||||
d->add(backend);
|
||||
d->backends.push_back(backend);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,18 +263,25 @@ void xmrig::Log::init()
|
||||
{
|
||||
d = new LogPrivate();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
void xmrig::Log::print(const char *fmt, ...)
|
||||
{
|
||||
# ifndef XMRIG_FEATURE_EVENTS
|
||||
if (!d) {
|
||||
return;
|
||||
}
|
||||
# endif
|
||||
|
||||
va_list args{};
|
||||
va_start(args, fmt);
|
||||
|
||||
# ifdef XMRIG_FEATURE_EVENTS
|
||||
log_print(NONE, fmt, args);
|
||||
# else
|
||||
d->print(NONE, fmt, args);
|
||||
# endif
|
||||
|
||||
va_end(args);
|
||||
}
|
||||
@@ -242,14 +289,33 @@ void xmrig::Log::print(const char *fmt, ...)
|
||||
|
||||
void xmrig::Log::print(Level level, const char *fmt, ...)
|
||||
{
|
||||
# ifndef XMRIG_FEATURE_EVENTS
|
||||
if (!d) {
|
||||
return;
|
||||
}
|
||||
# endif
|
||||
|
||||
va_list args{};
|
||||
va_start(args, fmt);
|
||||
|
||||
# ifdef XMRIG_FEATURE_EVENTS
|
||||
log_print(level, fmt, args);
|
||||
# else
|
||||
d->print(level, fmt, args);
|
||||
# endif
|
||||
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Log::setVerbose(uint32_t verbose)
|
||||
{
|
||||
static constexpr uint32_t kMaxVerbose =
|
||||
# ifdef XMRIG_FEATURE_EVENTS
|
||||
LogConfig::kMaxVerbose;
|
||||
# else
|
||||
5U;
|
||||
# endif
|
||||
|
||||
m_verbose = std::min(verbose, kMaxVerbose);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2019 Spudz76 <https://github.com/Spudz76>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -15,6 +15,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_LOG_H
|
||||
@@ -44,16 +51,25 @@ public:
|
||||
WARNING, // warning conditions
|
||||
NOTICE, // normal but significant condition
|
||||
INFO, // informational
|
||||
V1, // Verbose
|
||||
V2, // Verbose
|
||||
V3, // Verbose
|
||||
V4, // Verbose
|
||||
V5, // Verbose
|
||||
DEBUG, // debug-level messages
|
||||
};
|
||||
|
||||
constexpr static size_t kMaxBufferSize = 16384;
|
||||
|
||||
# ifndef XMRIG_FEATURE_EVENTS
|
||||
static void add(ILogBackend *backend);
|
||||
static void destroy();
|
||||
static void init();
|
||||
# endif
|
||||
|
||||
static void print(const char *fmt, ...);
|
||||
static void print(Level level, const char *fmt, ...);
|
||||
static void setVerbose(uint32_t verbose);
|
||||
|
||||
static inline bool isBackground() { return m_background; }
|
||||
static inline bool isColors() { return m_colors; }
|
||||
@@ -61,7 +77,6 @@ public:
|
||||
static inline uint32_t verbose() { return m_verbose; }
|
||||
static inline void setBackground(bool background) { m_background = background; }
|
||||
static inline void setColors(bool colors) { m_colors = colors; }
|
||||
static inline void setVerbose(uint32_t verbose) { m_verbose = verbose; }
|
||||
|
||||
private:
|
||||
static bool m_background;
|
||||
@@ -143,12 +158,12 @@ private:
|
||||
#define LOG_WARN(x, ...) xmrig::Log::print(xmrig::Log::WARNING, x, ##__VA_ARGS__)
|
||||
#define LOG_NOTICE(x, ...) xmrig::Log::print(xmrig::Log::NOTICE, x, ##__VA_ARGS__)
|
||||
#define LOG_INFO(x, ...) xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__)
|
||||
#define LOG_VERBOSE(x, ...) if (xmrig::Log::verbose() > 0) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); }
|
||||
#define LOG_V1(x, ...) if (xmrig::Log::verbose() > 0) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); }
|
||||
#define LOG_V2(x, ...) if (xmrig::Log::verbose() > 1) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); }
|
||||
#define LOG_V3(x, ...) if (xmrig::Log::verbose() > 2) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); }
|
||||
#define LOG_V4(x, ...) if (xmrig::Log::verbose() > 3) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); }
|
||||
#define LOG_V5(x, ...) if (xmrig::Log::verbose() > 4) { xmrig::Log::print(xmrig::Log::INFO, x, ##__VA_ARGS__); }
|
||||
#define LOG_VERBOSE(x, ...) if (xmrig::Log::verbose() > 0) { xmrig::Log::print(xmrig::Log::V1, x, ##__VA_ARGS__); }
|
||||
#define LOG_V1(x, ...) if (xmrig::Log::verbose() > 0) { xmrig::Log::print(xmrig::Log::V1, x, ##__VA_ARGS__); }
|
||||
#define LOG_V2(x, ...) if (xmrig::Log::verbose() > 1) { xmrig::Log::print(xmrig::Log::V2, x, ##__VA_ARGS__); }
|
||||
#define LOG_V3(x, ...) if (xmrig::Log::verbose() > 2) { xmrig::Log::print(xmrig::Log::V3, x, ##__VA_ARGS__); }
|
||||
#define LOG_V4(x, ...) if (xmrig::Log::verbose() > 3) { xmrig::Log::print(xmrig::Log::V4, x, ##__VA_ARGS__); }
|
||||
#define LOG_V5(x, ...) if (xmrig::Log::verbose() > 4) { xmrig::Log::print(xmrig::Log::V5, x, ##__VA_ARGS__); }
|
||||
|
||||
#ifdef APP_DEBUG
|
||||
# define LOG_DEBUG(x, ...) xmrig::Log::print(xmrig::Log::DEBUG, x, ##__VA_ARGS__)
|
||||
@@ -165,7 +180,7 @@ private:
|
||||
#endif
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif /* XMRIG_LOG_H */
|
||||
#endif // XMRIG_LOG_H
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -16,11 +16,27 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/io/log/Tags.h"
|
||||
#include "base/io/log/Log.h"
|
||||
|
||||
|
||||
#ifndef XMRIG_FEATURE_EVENTS
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
const char *tls_tag()
|
||||
{
|
||||
static const char *tag = GREEN_BG_BOLD(WHITE_BOLD_S " tls ");
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef XMRIG_LEGACY
|
||||
const char *xmrig::Tags::config()
|
||||
{
|
||||
static const char *tag = CYAN_BG_BOLD(WHITE_BOLD_S " config ");
|
||||
@@ -29,6 +45,15 @@ const char *xmrig::Tags::config()
|
||||
}
|
||||
|
||||
|
||||
const char *xmrig::Tags::signal()
|
||||
{
|
||||
static const char *tag = YELLOW_BG_BOLD(WHITE_BOLD_S " signal ");
|
||||
|
||||
return tag;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
const char *xmrig::Tags::network()
|
||||
{
|
||||
static const char *tag = BLUE_BG_BOLD(WHITE_BOLD_S " net ");
|
||||
@@ -45,14 +70,6 @@ const char* xmrig::Tags::origin()
|
||||
}
|
||||
|
||||
|
||||
const char *xmrig::Tags::signal()
|
||||
{
|
||||
static const char *tag = YELLOW_BG_BOLD(WHITE_BOLD_S " signal ");
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
||||
#ifdef XMRIG_MINER_PROJECT
|
||||
const char *xmrig::Tags::cpu()
|
||||
{
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -30,10 +30,13 @@ namespace xmrig {
|
||||
class Tags
|
||||
{
|
||||
public:
|
||||
# ifdef XMRIG_LEGACY
|
||||
static const char *config();
|
||||
static const char *signal();
|
||||
# endif
|
||||
|
||||
static const char *network();
|
||||
static const char *origin();
|
||||
static const char *signal();
|
||||
|
||||
# ifdef XMRIG_MINER_PROJECT
|
||||
static const char *cpu();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2019 Spudz76 <https://github.com/Spudz76>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -15,47 +15,46 @@
|
||||
*
|
||||
* 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 "base/io/log/backends/ConsoleLog.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/kernel/config/Title.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
|
||||
}
|
||||
@@ -97,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
|
||||
{
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2019 Spudz76 <https://github.com/Spudz76>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -15,6 +15,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_CONSOLELOG_H
|
||||
@@ -40,6 +47,7 @@ class ConsoleLog : public ILogBackend
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE(ConsoleLog)
|
||||
|
||||
ConsoleLog();
|
||||
ConsoleLog(const Title &title);
|
||||
~ConsoleLog() override;
|
||||
|
||||
@@ -49,6 +57,8 @@ protected:
|
||||
private:
|
||||
static bool isSupported();
|
||||
|
||||
bool init();
|
||||
|
||||
uv_tty_t *m_tty = nullptr;
|
||||
|
||||
# ifdef XMRIG_OS_WIN
|
||||
@@ -59,7 +69,7 @@ private:
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif /* XMRIG_CONSOLELOG_H */
|
||||
#endif // XMRIG_CONSOLELOG_H
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2019 Spudz76 <https://github.com/Spudz76>
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -17,7 +17,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/io/log/backends/FileLog.h"
|
||||
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2019 Spudz76 <https://github.com/Spudz76>
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2019 Spudz76 <https://github.com/Spudz76>
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -17,7 +17,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
#include <syslog.h>
|
||||
|
||||
|
||||
@@ -43,5 +43,5 @@ void xmrig::SysLog::print(uint64_t, int level, const char *line, size_t offset,
|
||||
return;
|
||||
}
|
||||
|
||||
syslog(level == -1 ? LOG_INFO : level, "%s", line + offset);
|
||||
syslog(level == -1 ? LOG_INFO : std::min(level, LOG_DEBUG), "%s", line + offset);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2019 Spudz76 <https://github.com/Spudz76>
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
#include "base/io/log/Tags.h"
|
||||
#include "base/io/Watcher.h"
|
||||
#include "base/kernel/interfaces/IBaseListener.h"
|
||||
#include "base/kernel/Platform.h"
|
||||
#include "base/kernel/OS.h"
|
||||
#include "base/kernel/Process.h"
|
||||
#include "base/net/tools/NetBuffer.h"
|
||||
#include "core/config/Config.h"
|
||||
@@ -130,17 +130,17 @@ private:
|
||||
return config.release();
|
||||
}
|
||||
|
||||
chain.addFile(Process::location(Process::DataLocation, "config.json"));
|
||||
chain.addFile(Process::locate(Process::DataLocation, "config.json"));
|
||||
if (read(chain, config)) {
|
||||
return config.release();
|
||||
}
|
||||
|
||||
chain.addFile(Process::location(Process::HomeLocation, "." APP_ID ".json"));
|
||||
chain.addFile(Process::locate(Process::HomeLocation, "." APP_ID ".json"));
|
||||
if (read(chain, config)) {
|
||||
return config.release();
|
||||
}
|
||||
|
||||
chain.addFile(Process::location(Process::HomeLocation, ".config" XMRIG_DIR_SEPARATOR APP_ID ".json"));
|
||||
chain.addFile(Process::locate(Process::HomeLocation, ".config" XMRIG_DIR_SEPARATOR APP_ID ".json"));
|
||||
if (read(chain, config)) {
|
||||
return config.release();
|
||||
}
|
||||
@@ -164,7 +164,6 @@ private:
|
||||
xmrig::Base::Base(Process *process)
|
||||
: d_ptr(new BasePrivate(process))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -187,7 +186,7 @@ int xmrig::Base::init()
|
||||
d_ptr->api->addListener(this);
|
||||
# endif
|
||||
|
||||
Platform::init(config()->userAgent());
|
||||
Process::setUserAgent(config()->userAgent());
|
||||
|
||||
if (isBackground()) {
|
||||
Log::setBackground(true);
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2016-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -22,92 +16,93 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <cstdio>
|
||||
#include <uv.h>
|
||||
#include "base/kernel/Entry.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/kernel/OS.h"
|
||||
#include "base/kernel/Process.h"
|
||||
#include "base/kernel/Versions.h"
|
||||
#include "base/tools/Arguments.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_TLS
|
||||
# include <openssl/opensslv.h>
|
||||
#endif
|
||||
#include <iostream>
|
||||
|
||||
#ifdef XMRIG_FEATURE_HWLOC
|
||||
# include <hwloc.h>
|
||||
#endif
|
||||
|
||||
#ifdef XMRIG_FEATURE_OPENCL
|
||||
# include "backend/opencl/wrappers/OclLib.h"
|
||||
# include "backend/opencl/wrappers/OclPlatform.h"
|
||||
#endif
|
||||
|
||||
#include "base/kernel/Entry.h"
|
||||
#include "base/kernel/Process.h"
|
||||
#include "core/config/usage.h"
|
||||
#include "version.h"
|
||||
#ifdef XMRIG_FEATURE_HWLOC
|
||||
# include <hwloc.h>
|
||||
#endif
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
static int showVersion()
|
||||
static bool showVersion(int &/*rc*/)
|
||||
{
|
||||
printf(APP_NAME " " APP_VERSION "\n built on " __DATE__
|
||||
|
||||
# if defined(__clang__)
|
||||
" with clang " __clang_version__);
|
||||
# elif defined(__GNUC__)
|
||||
" with GCC");
|
||||
printf(" %d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
|
||||
# elif defined(_MSC_VER)
|
||||
" with MSVC");
|
||||
printf(" %d", MSVC_VERSION);
|
||||
# else
|
||||
);
|
||||
# endif
|
||||
|
||||
printf("\n features:"
|
||||
# if defined(__i386__) || defined(_M_IX86)
|
||||
" 32-bit"
|
||||
# elif defined(__x86_64__) || defined(_M_AMD64)
|
||||
" 64-bit"
|
||||
# endif
|
||||
|
||||
# if defined(__AES__) || defined(_MSC_VER)
|
||||
" AES"
|
||||
# endif
|
||||
"\n");
|
||||
|
||||
printf("\nlibuv/%s\n", uv_version_string());
|
||||
|
||||
# if defined(XMRIG_FEATURE_TLS)
|
||||
{
|
||||
# if defined(LIBRESSL_VERSION_TEXT)
|
||||
printf("LibreSSL/%s\n", LIBRESSL_VERSION_TEXT + 9);
|
||||
# elif defined(OPENSSL_VERSION_TEXT)
|
||||
constexpr const char *v = &OPENSSL_VERSION_TEXT[8];
|
||||
printf("OpenSSL/%.*s\n", static_cast<int>(strchr(v, ' ') - v), v);
|
||||
# endif
|
||||
if (!Process::arguments().contains("-V", "--version")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
std::cout << APP_NAME " v" << Process::version() << std::endl
|
||||
<< " built on " __DATE__ " with " << Versions::kCompiler << "/" << Process::versions().get(Versions::kCompiler)
|
||||
<< " (" << OS::arch << ")" << std::endl;
|
||||
|
||||
# ifdef XMRIG_LEGACY
|
||||
std::cout << std::endl << "uv/" << Process::versions().get(Versions::kUv) << std::endl;
|
||||
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
std::cout << Versions::kTls << "/" << Process::versions().get(Versions::kTls) << std::endl;
|
||||
# endif
|
||||
|
||||
# if defined(XMRIG_FEATURE_HWLOC)
|
||||
# if defined(HWLOC_VERSION)
|
||||
printf("hwloc/%s\n", HWLOC_VERSION);
|
||||
# elif HWLOC_API_VERSION >= 0x20000
|
||||
printf("hwloc/2\n");
|
||||
# else
|
||||
printf("hwloc/1\n");
|
||||
# ifdef XMRIG_FEATURE_HWLOC
|
||||
std::cout << "hwloc/" << Process::versions().get(Versions::kHwloc) << std::endl;
|
||||
# endif
|
||||
# endif
|
||||
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
static bool showVersions(int &/*rc*/)
|
||||
{
|
||||
if (Process::arguments().contains("--versions")) {
|
||||
for (const auto &kv : Process::versions().get()) {
|
||||
std::cout << kv.first << "/" << kv.second << std::endl;;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
static bool userAgent(int &/*rc*/)
|
||||
{
|
||||
Process::setUserAgent(Process::arguments().value("--user-agent"));
|
||||
|
||||
if (Process::arguments().contains("--print-user-agent")) {
|
||||
std::cout << Process::userAgent() << std::endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_HWLOC
|
||||
static int exportTopology(const Process &)
|
||||
static bool exportTopology(int &rc)
|
||||
{
|
||||
const String path = Process::location(Process::ExeLocation, "topology.xml");
|
||||
if (!Process::arguments().contains("--export-topology")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto path = Process::locate(Process::DataLocation, "topology.xml");
|
||||
|
||||
hwloc_topology_t topology = nullptr;
|
||||
hwloc_topology_init(&topology);
|
||||
@@ -118,15 +113,16 @@ static int exportTopology(const Process &)
|
||||
# else
|
||||
if (hwloc_topology_export_xml(topology, path) == -1) {
|
||||
# endif
|
||||
printf("failed to export hwloc topology.\n");
|
||||
rc = 1;
|
||||
std::cout << "failed to export hwloc topology" << std::endl;
|
||||
}
|
||||
else {
|
||||
printf("hwloc topology successfully exported to \"%s\"\n", path.data());
|
||||
std::cout << "hwloc topology successfully exported to \"" << path << '"' << std::endl;
|
||||
}
|
||||
|
||||
hwloc_topology_destroy(topology);
|
||||
|
||||
return 0;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -134,59 +130,97 @@ static int exportTopology(const Process &)
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::Entry::Id xmrig::Entry::get(const Process &process)
|
||||
xmrig::Entry::Entry(const Usage &usage)
|
||||
{
|
||||
const Arguments &args = process.arguments();
|
||||
if (args.hasArg("-h") || args.hasArg("--help")) {
|
||||
return Usage;
|
||||
}
|
||||
|
||||
if (args.hasArg("-V") || args.hasArg("--version") || args.hasArg("--versions")) {
|
||||
return Version;
|
||||
}
|
||||
add(showVersion);
|
||||
add(showVersions);
|
||||
add(userAgent);
|
||||
|
||||
# ifdef XMRIG_FEATURE_HWLOC
|
||||
if (args.hasArg("--export-topology")) {
|
||||
return Topo;
|
||||
}
|
||||
add(exportTopology);
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_OPENCL
|
||||
if (args.hasArg("--print-platforms")) {
|
||||
return Platforms;
|
||||
}
|
||||
# endif
|
||||
|
||||
return Default;
|
||||
}
|
||||
|
||||
|
||||
int xmrig::Entry::exec(const Process &process, Id id)
|
||||
{
|
||||
switch (id) {
|
||||
case Usage:
|
||||
printf("%s\n", usage().c_str());
|
||||
return 0;
|
||||
|
||||
case Version:
|
||||
return showVersion();
|
||||
|
||||
# ifdef XMRIG_FEATURE_HWLOC
|
||||
case Topo:
|
||||
return exportTopology(process);
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_OPENCL
|
||||
case Platforms:
|
||||
if (OclLib::init()) {
|
||||
OclPlatform::print();
|
||||
add([usage](int &/*rc*/) {
|
||||
if (!Process::arguments().contains("-h", "--help")) {
|
||||
return false;
|
||||
}
|
||||
return 0;
|
||||
|
||||
std::cout << "Usage: " APP_ID " [OPTIONS]\n";
|
||||
std::cout << usage();
|
||||
|
||||
# ifndef XMRIG_LEGACY
|
||||
std::cout << "\nBase:\n";
|
||||
std::cout << " -h, --help print this help and exit\n";
|
||||
std::cout << " -V, --version print " APP_ID " version and exit\n";
|
||||
std::cout << " --versions print versions and exit\n";
|
||||
std::cout << " -d, --data-dir=<PATH> alternative working directory\n";
|
||||
std::cout << " -c, --config=<FILE> load a JSON-format configuration file\n";
|
||||
std::cout << " -B, --background run " APP_ID " in the background\n";
|
||||
std::cout << " --no-color disable colored output\n";
|
||||
std::cout << " --verbose=[LEVEL] verbose level (0-5)\n";
|
||||
std::cout << " --print-time=<N> print report every N seconds\n";
|
||||
std::cout << " -l, --log-file=<FILE> log all output to a file\n";
|
||||
|
||||
# ifdef HAVE_SYSLOG_H
|
||||
std::cout << " -S, --syslog use system log for output messages\n";
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_OS_WIN
|
||||
std::cout << " --title=[TITLE] set custom console window title\n";
|
||||
# endif
|
||||
|
||||
std::cout << " --user-agent=<UA> set custom user agent string\n";
|
||||
std::cout << " --print-user-agent print current user agent and exit\n";
|
||||
std::cout << " --dns-ipv6 prefer IPv6 records from DNS responses\n";
|
||||
std::cout << " --dns-ttl=<N> N seconds (default: 30) TTL for internal DNS cache\n";
|
||||
|
||||
# ifdef XMRIG_FEATURE_HWLOC
|
||||
std::cout << " --export-topology export hwloc topology to a XML file and exit\n";
|
||||
# endif
|
||||
# endif
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
# ifdef XMRIG_FEATURE_OPENCL
|
||||
add([](int &/*rc*/) {
|
||||
if (Process::arguments().contains("--print-platforms")) {
|
||||
if (OclLib::init()) {
|
||||
OclPlatform::print();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
# endif
|
||||
|
||||
default:
|
||||
break;
|
||||
add([](int &rc) {
|
||||
if (Process::arguments().contains("-B", "--background")) {
|
||||
Log::setBackground(true);
|
||||
|
||||
return background(rc);
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::Entry::exec(int &rc) const
|
||||
{
|
||||
for (const auto &fn : m_entries) {
|
||||
if (fn(rc)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Entry::add(Fn &&fn)
|
||||
{
|
||||
m_entries.emplace_back(std::move(fn));
|
||||
}
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2016-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -26,29 +20,38 @@
|
||||
#define XMRIG_ENTRY_H
|
||||
|
||||
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
#include <functional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class Process;
|
||||
|
||||
|
||||
class Entry
|
||||
{
|
||||
public:
|
||||
enum Id {
|
||||
Default,
|
||||
Usage,
|
||||
Version,
|
||||
Topo,
|
||||
Platforms
|
||||
};
|
||||
XMRIG_DISABLE_COPY_MOVE(Entry)
|
||||
|
||||
static Id get(const Process &process);
|
||||
static int exec(const Process &process, Id id);
|
||||
using Fn = std::function<bool(int &rc)>;
|
||||
using Usage = std::function<std::string()>;
|
||||
|
||||
Entry(const Usage &usage);
|
||||
|
||||
bool exec(int &rc) const;
|
||||
void add(Fn &&fn);
|
||||
|
||||
private:
|
||||
static bool background(int &rc);
|
||||
|
||||
std::vector<Fn> m_entries;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif /* XMRIG_ENTRY_H */
|
||||
#endif // XMRIG_ENTRY_H
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2016-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -16,35 +16,31 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_TITLE_H
|
||||
#define XMRIG_TITLE_H
|
||||
#include <cstdlib>
|
||||
#include <csignal>
|
||||
#include <cerrno>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
#include "3rdparty/rapidjson/fwd.h"
|
||||
#include "base/tools/String.h"
|
||||
#include "base/kernel/Entry.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class Title
|
||||
bool xmrig::Entry::background(int &rc)
|
||||
{
|
||||
public:
|
||||
Title() = default;
|
||||
Title(const rapidjson::Value &value);
|
||||
const int i = fork();
|
||||
if (i < 0) {
|
||||
rc = 1;
|
||||
|
||||
inline bool isEnabled() const { return m_enabled; }
|
||||
return true;
|
||||
}
|
||||
|
||||
rapidjson::Value toJSON() const;
|
||||
String value() const;
|
||||
if (i > 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
bool m_enabled = true;
|
||||
String m_value;
|
||||
};
|
||||
if (setsid() < 0) {
|
||||
fprintf(stderr, "setsid() failed (errno = %d)\n", errno);
|
||||
}
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif /* XMRIG_TITLE_H */
|
||||
return false;
|
||||
}
|
||||
@@ -1,12 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2016-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -22,21 +16,15 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
|
||||
|
||||
#include "App.h"
|
||||
#include "core/Controller.h"
|
||||
#include "base/kernel/Entry.h"
|
||||
|
||||
|
||||
bool xmrig::App::background(int &)
|
||||
bool xmrig::Entry::background(int &)
|
||||
{
|
||||
if (!m_controller->isBackground()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
HWND hcon = GetConsoleWindow();
|
||||
if (hcon) {
|
||||
ShowWindow(hcon, SW_HIDE);
|
||||
78
src/base/kernel/Lib.cpp
Normal file
78
src/base/kernel/Lib.cpp
Normal file
@@ -0,0 +1,78 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2016-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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 "base/kernel/Lib.h"
|
||||
|
||||
|
||||
#include <cassert>
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class Lib::Private
|
||||
{
|
||||
public:
|
||||
bool open = false;
|
||||
uv_lib_t lib{};
|
||||
};
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::Lib::Lib() :
|
||||
d(std::make_shared<Private>())
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::Lib::isOpen() const
|
||||
{
|
||||
return d->open;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::Lib::open(const char *filename)
|
||||
{
|
||||
assert(!isOpen());
|
||||
|
||||
return (d->open = uv_dlopen(filename, &d->lib) == 0);
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::Lib::sym(const char *name, void **ptr)
|
||||
{
|
||||
return isOpen() && uv_dlsym(&d->lib, name, ptr);
|
||||
}
|
||||
|
||||
|
||||
const char *xmrig::Lib::lastError() const
|
||||
{
|
||||
return uv_dlerror(&d->lib);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Lib::close()
|
||||
{
|
||||
if (isOpen()) {
|
||||
uv_dlclose(&d->lib);
|
||||
d->open = false;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
@@ -16,42 +16,39 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/kernel/Platform.h"
|
||||
#ifndef XMRIG_LIB_H
|
||||
#define XMRIG_LIB_H
|
||||
|
||||
|
||||
#include <cstring>
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_TLS
|
||||
# include <openssl/ssl.h>
|
||||
# include <openssl/err.h>
|
||||
#endif
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
String Platform::m_userAgent;
|
||||
|
||||
class Lib
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE(Lib)
|
||||
|
||||
Lib();
|
||||
inline ~Lib() { close(); }
|
||||
|
||||
bool isOpen() const;
|
||||
bool open(const char *filename);
|
||||
bool sym(const char *name, void **ptr);
|
||||
const char *lastError() const;
|
||||
void close();
|
||||
|
||||
template<typename T>
|
||||
inline bool sym(const char *name, T t) { return sym(name, reinterpret_cast<void **>(t)); }
|
||||
|
||||
private:
|
||||
XMRIG_DECL_PRIVATE()
|
||||
};
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
void xmrig::Platform::init(const char *userAgent)
|
||||
{
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
SSL_library_init();
|
||||
SSL_load_error_strings();
|
||||
ERR_load_BIO_strings();
|
||||
ERR_load_crypto_strings();
|
||||
SSL_load_error_strings();
|
||||
OpenSSL_add_all_digests();
|
||||
# endif
|
||||
|
||||
if (userAgent) {
|
||||
m_userAgent = userAgent;
|
||||
}
|
||||
else {
|
||||
m_userAgent = createUserAgent();
|
||||
}
|
||||
}
|
||||
#endif // XMRIG_LIB_H
|
||||
99
src/base/kernel/OS.cpp
Normal file
99
src/base/kernel/OS.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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 <uv.h>
|
||||
|
||||
|
||||
#include "base/kernel/OS.h"
|
||||
#include "3rdparty/fmt/core.h"
|
||||
#include "base/kernel/Process.h"
|
||||
#include "base/kernel/Versions.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
#ifndef XMRIG_OS_WIN
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef UV_MAXHOSTNAMESIZE
|
||||
# ifdef MAXHOSTNAMELEN
|
||||
# define UV_MAXHOSTNAMESIZE (MAXHOSTNAMELEN + 1)
|
||||
# else
|
||||
# define UV_MAXHOSTNAMESIZE 256
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
#if (XMRIG_ARM == 8 || defined(__arm64__) || defined(__aarch64__) || defined(_M_ARM64))
|
||||
const char *OS::arch = "arm64";
|
||||
#elif (XMRIG_ARM == 7 || defined(__arm__) || defined(_M_ARM))
|
||||
const char *OS::arch = "arm";
|
||||
#elif (defined(__x86_64__) || defined(_M_AMD64))
|
||||
const char *OS::arch = "x86_64";
|
||||
#elif (defined(_X86_) || defined(_M_IX86))
|
||||
const char *OS::arch = "x86";
|
||||
#else
|
||||
static_assert (false, "Unsupported CPU or compiler");
|
||||
#endif
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
std::string xmrig::OS::userAgent()
|
||||
{
|
||||
return fmt::format("{}/{} ({}; {}) uv/{} {}/{}",
|
||||
APP_NAME,
|
||||
APP_VERSION,
|
||||
name(),
|
||||
arch,
|
||||
Process::versions()[Versions::kUv],
|
||||
Versions::kCompiler,
|
||||
Process::versions()[Versions::kCompiler]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
#ifndef XMRIG_OS_WIN
|
||||
xmrig::String xmrig::OS::hostname()
|
||||
{
|
||||
char buf[UV_MAXHOSTNAMESIZE]{};
|
||||
|
||||
if (gethostname(buf, sizeof(buf)) == 0) {
|
||||
return static_cast<const char *>(buf);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
uint64_t xmrig::OS::freemem()
|
||||
{
|
||||
return uv_get_free_memory();
|
||||
}
|
||||
|
||||
|
||||
uint64_t xmrig::OS::totalmem()
|
||||
{
|
||||
return uv_get_total_memory();
|
||||
}
|
||||
@@ -16,50 +16,43 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_PLATFORM_H
|
||||
#define XMRIG_PLATFORM_H
|
||||
|
||||
|
||||
#include <cstdint>
|
||||
#ifndef XMRIG_OS_H
|
||||
#define XMRIG_OS_H
|
||||
|
||||
|
||||
#include "base/tools/String.h"
|
||||
|
||||
|
||||
#include <string>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class Platform
|
||||
class OS
|
||||
{
|
||||
public:
|
||||
static inline bool trySetThreadAffinity(int64_t cpu_id)
|
||||
{
|
||||
if (cpu_id < 0) {
|
||||
return false;
|
||||
}
|
||||
static const char *arch;
|
||||
|
||||
return setThreadAffinity(static_cast<uint64_t>(cpu_id));
|
||||
}
|
||||
|
||||
static bool setThreadAffinity(uint64_t cpu_id);
|
||||
static void init(const char *userAgent);
|
||||
static void setProcessPriority(int priority);
|
||||
static void setThreadPriority(int priority);
|
||||
|
||||
static inline bool isUserActive(uint64_t ms) { return idleTime() < ms; }
|
||||
static inline const String &userAgent() { return m_userAgent; }
|
||||
static inline bool isUserActive(uint64_t ms) { return idleTime() < ms; }
|
||||
static inline bool trySetThreadAffinity(int64_t cpu_id) { return cpu_id >= 0 && setThreadAffinity(static_cast<uint64_t>(cpu_id)); }
|
||||
|
||||
static bool isOnBatteryPower();
|
||||
static bool setThreadAffinity(uint64_t cpu_id);
|
||||
static std::string name();
|
||||
static std::string userAgent();
|
||||
static String hostname();
|
||||
static uint64_t freemem();
|
||||
static uint64_t idleTime();
|
||||
|
||||
private:
|
||||
static char *createUserAgent();
|
||||
|
||||
static String m_userAgent;
|
||||
static uint64_t totalmem();
|
||||
static void destroy();
|
||||
static void init();
|
||||
static void setProcessPriority(int priority);
|
||||
static void setThreadPriority(int priority);
|
||||
};
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif /* XMRIG_PLATFORM_H */
|
||||
#endif // XMRIG_OS_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -16,8 +16,7 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/kernel/Platform.h"
|
||||
#include "base/kernel/OS.h"
|
||||
#include "backend/cpu/platform/HwlocCpuInfo.h"
|
||||
#include "backend/cpu/Cpu.h"
|
||||
|
||||
@@ -27,7 +26,7 @@
|
||||
|
||||
|
||||
#ifndef XMRIG_OS_APPLE
|
||||
bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
|
||||
bool xmrig::OS::setThreadAffinity(uint64_t cpu_id)
|
||||
{
|
||||
auto cpu = static_cast<HwlocCpuInfo *>(Cpu::info());
|
||||
hwloc_obj_t pu = hwloc_get_pu_obj_by_os_index(cpu->topology(), static_cast<unsigned>(cpu_id));
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <IOKit/IOKitLib.h>
|
||||
#include <IOKit/ps/IOPowerSources.h>
|
||||
#include <stdio.h>
|
||||
@@ -27,46 +26,58 @@
|
||||
#include <fstream>
|
||||
|
||||
|
||||
#include "base/kernel/Platform.h"
|
||||
#include "version.h"
|
||||
#include "base/kernel/OS.h"
|
||||
|
||||
|
||||
char *xmrig::Platform::createUserAgent()
|
||||
bool xmrig::OS::isOnBatteryPower()
|
||||
{
|
||||
constexpr const size_t max = 256;
|
||||
|
||||
char *buf = new char[max]();
|
||||
int length = snprintf(buf, max,
|
||||
"%s/%s (Macintosh; macOS"
|
||||
# ifdef XMRIG_ARM
|
||||
"; arm64"
|
||||
# else
|
||||
"; x86_64"
|
||||
# endif
|
||||
") libuv/%s", APP_NAME, APP_VERSION, uv_version_string());
|
||||
|
||||
# ifdef __clang__
|
||||
length += snprintf(buf + length, max - length, " clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__);
|
||||
# elif defined(__GNUC__)
|
||||
length += snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
|
||||
# endif
|
||||
|
||||
return buf;
|
||||
return IOPSGetTimeRemainingEstimate() != kIOPSTimeRemainingUnlimited;
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
|
||||
bool xmrig::OS::setThreadAffinity(uint64_t /*cpu_id*/)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Platform::setProcessPriority(int)
|
||||
std::string xmrig::OS::name()
|
||||
{
|
||||
return "macOS";
|
||||
}
|
||||
|
||||
|
||||
uint64_t xmrig::OS::idleTime()
|
||||
{
|
||||
uint64_t idle_time = 0;
|
||||
const auto service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOHIDSystem"));
|
||||
const auto property = IORegistryEntryCreateCFProperty(service, CFSTR("HIDIdleTime"), kCFAllocatorDefault, 0);
|
||||
|
||||
CFNumberGetValue((CFNumberRef)property, kCFNumberSInt64Type, &idle_time);
|
||||
|
||||
CFRelease(property);
|
||||
IOObjectRelease(service);
|
||||
|
||||
return idle_time / 1000000U;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::OS::destroy()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Platform::setThreadPriority(int priority)
|
||||
void xmrig::OS::init()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void xmrig::OS::setProcessPriority(int)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void xmrig::OS::setThreadPriority(int priority)
|
||||
{
|
||||
if (priority == -1) {
|
||||
return;
|
||||
@@ -101,24 +112,3 @@ void xmrig::Platform::setThreadPriority(int priority)
|
||||
|
||||
setpriority(PRIO_PROCESS, 0, prio);
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::Platform::isOnBatteryPower()
|
||||
{
|
||||
return IOPSGetTimeRemainingEstimate() != kIOPSTimeRemainingUnlimited;
|
||||
}
|
||||
|
||||
|
||||
uint64_t xmrig::Platform::idleTime()
|
||||
{
|
||||
uint64_t idle_time = 0;
|
||||
const auto service = IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching("IOHIDSystem"));
|
||||
const auto property = IORegistryEntryCreateCFProperty(service, CFSTR("HIDIdleTime"), kCFAllocatorDefault, 0);
|
||||
|
||||
CFNumberGetValue((CFNumberRef)property, kCFNumberSInt64Type, &idle_time);
|
||||
|
||||
CFRelease(property);
|
||||
IOObjectRelease(service);
|
||||
|
||||
return idle_time / 1000000U;
|
||||
}
|
||||
@@ -37,8 +37,7 @@
|
||||
#include <limits>
|
||||
|
||||
|
||||
#include "base/kernel/Platform.h"
|
||||
#include "version.h"
|
||||
#include "base/kernel/OS.h"
|
||||
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
@@ -46,35 +45,24 @@ typedef cpuset_t cpu_set_t;
|
||||
#endif
|
||||
|
||||
|
||||
char *xmrig::Platform::createUserAgent()
|
||||
bool xmrig::OS::isOnBatteryPower()
|
||||
{
|
||||
constexpr const size_t max = 256;
|
||||
|
||||
char *buf = new char[max]();
|
||||
int length = snprintf(buf, max, "%s/%s (Linux ", APP_NAME, APP_VERSION);
|
||||
|
||||
# if defined(__x86_64__)
|
||||
length += snprintf(buf + length, max - length, "x86_64) libuv/%s", uv_version_string());
|
||||
# elif defined(__aarch64__)
|
||||
length += snprintf(buf + length, max - length, "aarch64) libuv/%s", uv_version_string());
|
||||
# elif defined(__arm__)
|
||||
length += snprintf(buf + length, max - length, "arm) libuv/%s", uv_version_string());
|
||||
# else
|
||||
length += snprintf(buf + length, max - length, "i686) libuv/%s", uv_version_string());
|
||||
# endif
|
||||
|
||||
# ifdef __clang__
|
||||
length += snprintf(buf + length, max - length, " clang/%d.%d.%d", __clang_major__, __clang_minor__, __clang_patchlevel__);
|
||||
# elif defined(__GNUC__)
|
||||
length += snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
|
||||
# endif
|
||||
|
||||
return buf;
|
||||
for (int i = 0; i <= 1; ++i) {
|
||||
char buf[64];
|
||||
snprintf(buf, 64, "/sys/class/power_supply/BAT%d/status", i);
|
||||
std::ifstream f(buf);
|
||||
if (f.is_open()) {
|
||||
std::string status;
|
||||
f >> status;
|
||||
return (status == "Discharging");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
#ifndef XMRIG_FEATURE_HWLOC
|
||||
bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
|
||||
bool xmrig::OS::setThreadAffinity(uint64_t cpu_id)
|
||||
{
|
||||
cpu_set_t mn;
|
||||
CPU_ZERO(&mn);
|
||||
@@ -92,12 +80,38 @@ bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
|
||||
#endif
|
||||
|
||||
|
||||
void xmrig::Platform::setProcessPriority(int)
|
||||
std::string xmrig::OS::name()
|
||||
{
|
||||
# ifdef __FreeBSD__
|
||||
return "FreeBSD";
|
||||
# else
|
||||
return "Linux";
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
uint64_t xmrig::OS::idleTime()
|
||||
{
|
||||
return std::numeric_limits<uint64_t>::max();
|
||||
}
|
||||
|
||||
|
||||
void xmrig::OS::destroy()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Platform::setThreadPriority(int priority)
|
||||
void xmrig::OS::init()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void xmrig::OS::setProcessPriority(int)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
void xmrig::OS::setThreadPriority(int priority)
|
||||
{
|
||||
if (priority == -1) {
|
||||
return;
|
||||
@@ -143,25 +157,3 @@ void xmrig::Platform::setThreadPriority(int priority)
|
||||
}
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::Platform::isOnBatteryPower()
|
||||
{
|
||||
for (int i = 0; i <= 1; ++i) {
|
||||
char buf[64];
|
||||
snprintf(buf, 64, "/sys/class/power_supply/BAT%d/status", i);
|
||||
std::ifstream f(buf);
|
||||
if (f.is_open()) {
|
||||
std::string status;
|
||||
f >> status;
|
||||
return (status == "Discharging");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
uint64_t xmrig::Platform::idleTime()
|
||||
{
|
||||
return std::numeric_limits<uint64_t>::max();
|
||||
}
|
||||
@@ -16,16 +16,28 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
#include <winsock2.h>
|
||||
#include <windows.h>
|
||||
#include <uv.h>
|
||||
#include <limits>
|
||||
|
||||
|
||||
#include "base/kernel/Platform.h"
|
||||
#include "version.h"
|
||||
#include "base/kernel/OS.h"
|
||||
#include "3rdparty/fmt/core.h"
|
||||
#include "base/kernel/Lib.h"
|
||||
#include "base/tools/Cvt.h"
|
||||
|
||||
|
||||
#ifndef UV_MAXHOSTNAMESIZE
|
||||
# define UV_MAXHOSTNAMESIZE 256
|
||||
#endif
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
typedef int (WSAAPI *GetHostNameW_t)(PWSTR, int); // NOLINT(modernize-use-using)
|
||||
|
||||
|
||||
static Lib ws2_32;
|
||||
static GetHostNameW_t pGetHostNameW = nullptr;
|
||||
|
||||
|
||||
static inline OSVERSIONINFOEX winOsVersion()
|
||||
@@ -46,32 +58,21 @@ static inline OSVERSIONINFOEX winOsVersion()
|
||||
}
|
||||
|
||||
|
||||
char *xmrig::Platform::createUserAgent()
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
bool xmrig::OS::isOnBatteryPower()
|
||||
{
|
||||
const auto osver = winOsVersion();
|
||||
constexpr const size_t max = 256;
|
||||
|
||||
char *buf = new char[max]();
|
||||
int length = snprintf(buf, max, "%s/%s (Windows NT %lu.%lu", APP_NAME, APP_VERSION, osver.dwMajorVersion, osver.dwMinorVersion);
|
||||
|
||||
# if defined(__x86_64__) || defined(_M_AMD64)
|
||||
length += snprintf(buf + length, max - length, "; Win64; x64) libuv/%s", uv_version_string());
|
||||
# else
|
||||
length += snprintf(buf + length, max - length, ") libuv/%s", uv_version_string());
|
||||
# endif
|
||||
|
||||
# ifdef __GNUC__
|
||||
snprintf(buf + length, max - length, " gcc/%d.%d.%d", __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__);
|
||||
# elif _MSC_VER
|
||||
snprintf(buf + length, max - length, " msvc/%d", MSVC_VERSION);
|
||||
# endif
|
||||
|
||||
return buf;
|
||||
SYSTEM_POWER_STATUS st;
|
||||
if (GetSystemPowerStatus(&st)) {
|
||||
return (st.ACLineStatus == 0);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
#ifndef XMRIG_FEATURE_HWLOC
|
||||
bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
|
||||
bool xmrig::OS::setThreadAffinity(uint64_t cpu_id)
|
||||
{
|
||||
const bool result = (SetThreadAffinityMask(GetCurrentThread(), 1ULL << cpu_id) != 0);
|
||||
Sleep(1);
|
||||
@@ -80,7 +81,70 @@ bool xmrig::Platform::setThreadAffinity(uint64_t cpu_id)
|
||||
#endif
|
||||
|
||||
|
||||
void xmrig::Platform::setProcessPriority(int priority)
|
||||
std::string xmrig::OS::name()
|
||||
{
|
||||
const auto osver = winOsVersion();
|
||||
|
||||
return fmt::format("Windows {}.{}", osver.dwMajorVersion, osver.dwMinorVersion);
|
||||
}
|
||||
|
||||
|
||||
xmrig::String xmrig::OS::hostname()
|
||||
{
|
||||
if (pGetHostNameW) {
|
||||
WCHAR buf[UV_MAXHOSTNAMESIZE]{};
|
||||
|
||||
if (pGetHostNameW(buf, UV_MAXHOSTNAMESIZE) == 0) {
|
||||
return Cvt::toUtf8(buf).c_str();
|
||||
}
|
||||
}
|
||||
|
||||
char buf[UV_MAXHOSTNAMESIZE]{};
|
||||
|
||||
if (gethostname(buf, sizeof(buf)) == 0) {
|
||||
return static_cast<const char *>(buf);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
|
||||
uint64_t xmrig::OS::idleTime()
|
||||
{
|
||||
LASTINPUTINFO info{};
|
||||
info.cbSize = sizeof(LASTINPUTINFO);
|
||||
|
||||
if (!GetLastInputInfo(&info)) {
|
||||
return std::numeric_limits<uint64_t>::max();
|
||||
}
|
||||
|
||||
return static_cast<uint64_t>(GetTickCount() - info.dwTime);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::OS::destroy()
|
||||
{
|
||||
# ifdef XMRIG_FEATURE_COM
|
||||
CoUninitialize();
|
||||
# endif
|
||||
|
||||
ws2_32.close();
|
||||
}
|
||||
|
||||
|
||||
void xmrig::OS::init()
|
||||
{
|
||||
# ifdef XMRIG_FEATURE_COM
|
||||
CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED);
|
||||
# endif
|
||||
|
||||
if (ws2_32.open("Ws2_32.dll")) {
|
||||
ws2_32.sym("GetHostNameW", &pGetHostNameW);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void xmrig::OS::setProcessPriority(int priority)
|
||||
{
|
||||
if (priority == -1) {
|
||||
return;
|
||||
@@ -117,7 +181,7 @@ void xmrig::Platform::setProcessPriority(int priority)
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Platform::setThreadPriority(int priority)
|
||||
void xmrig::OS::setThreadPriority(int priority)
|
||||
{
|
||||
if (priority == -1) {
|
||||
return;
|
||||
@@ -152,26 +216,3 @@ void xmrig::Platform::setThreadPriority(int priority)
|
||||
|
||||
SetThreadPriority(GetCurrentThread(), prio);
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::Platform::isOnBatteryPower()
|
||||
{
|
||||
SYSTEM_POWER_STATUS st;
|
||||
if (GetSystemPowerStatus(&st)) {
|
||||
return (st.ACLineStatus == 0);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
uint64_t xmrig::Platform::idleTime()
|
||||
{
|
||||
LASTINPUTINFO info{};
|
||||
info.cbSize = sizeof(LASTINPUTINFO);
|
||||
|
||||
if (!GetLastInputInfo(&info)) {
|
||||
return std::numeric_limits<uint64_t>::max();
|
||||
}
|
||||
|
||||
return static_cast<uint64_t>(GetTickCount() - info.dwTime);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -23,10 +23,25 @@
|
||||
|
||||
#include "base/kernel/Process.h"
|
||||
#include "3rdparty/fmt/core.h"
|
||||
#include "base/kernel/OS.h"
|
||||
#include "base/kernel/Versions.h"
|
||||
#include "base/tools/Arguments.h"
|
||||
#include "base/tools/Chrono.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_EVENTS
|
||||
# include "base/kernel/Events.h"
|
||||
# include "base/kernel/events/ExitEvent.h"
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_TLS
|
||||
# include <openssl/ssl.h>
|
||||
# include <openssl/err.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef XMRIG_OS_WIN
|
||||
# ifdef _MSC_VER
|
||||
# include <direct.h>
|
||||
@@ -42,99 +57,127 @@
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
static char pathBuf[520];
|
||||
static std::string dataDir;
|
||||
|
||||
|
||||
static std::string getPath(Process::Location location)
|
||||
class Process::Private
|
||||
{
|
||||
size_t size = sizeof(pathBuf);
|
||||
|
||||
if (location == Process::DataLocation) {
|
||||
if (!dataDir.empty()) {
|
||||
return dataDir;
|
||||
}
|
||||
|
||||
location = Process::ExeLocation;
|
||||
}
|
||||
|
||||
if (location == Process::HomeLocation) {
|
||||
# if UV_VERSION_HEX >= 0x010600
|
||||
return uv_os_homedir(pathBuf, &size) < 0 ? "" : std::string(pathBuf, size);
|
||||
# else
|
||||
location = Process::ExeLocation;
|
||||
public:
|
||||
Private(int argc, char **argv) : arguments(argc, argv)
|
||||
{
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
SSL_library_init();
|
||||
SSL_load_error_strings();
|
||||
ERR_load_BIO_strings();
|
||||
ERR_load_crypto_strings();
|
||||
SSL_load_error_strings();
|
||||
OpenSSL_add_all_digests();
|
||||
# endif
|
||||
}
|
||||
|
||||
if (location == Process::TempLocation) {
|
||||
# if UV_VERSION_HEX >= 0x010900
|
||||
return uv_os_tmpdir(pathBuf, &size) < 0 ? "" : std::string(pathBuf, size);
|
||||
# else
|
||||
location = Process::ExeLocation;
|
||||
# endif
|
||||
}
|
||||
|
||||
if (location == Process::ExeLocation) {
|
||||
if (uv_exepath(pathBuf, &size) < 0) {
|
||||
return {};
|
||||
void setDataDir(const char *path)
|
||||
{
|
||||
if (path == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto path = std::string(pathBuf, size);
|
||||
const auto pos = path.rfind(*XMRIG_DIR_SEPARATOR);
|
||||
|
||||
if (pos != std::string::npos) {
|
||||
return path.substr(0, pos);
|
||||
std::string dir = path;
|
||||
if (!dir.empty() && (dir.back() == '/' || dir.back() == '\\')) {
|
||||
dir.pop_back();
|
||||
}
|
||||
|
||||
return path;
|
||||
if (!dir.empty() && uv_chdir(dir.c_str()) == 0) {
|
||||
dataDir = { dir.data(), dir.size() };
|
||||
}
|
||||
}
|
||||
|
||||
if (location == Process::CwdLocation) {
|
||||
return uv_cwd(pathBuf, &size) < 0 ? "" : std::string(pathBuf, size);
|
||||
}
|
||||
Arguments arguments;
|
||||
const char *version = APP_VERSION;
|
||||
|
||||
return {};
|
||||
}
|
||||
int exitCode = 0;
|
||||
String dataDir;
|
||||
String userAgent;
|
||||
Versions versions;
|
||||
|
||||
# ifndef XMRIG_LEGACY
|
||||
Events events;
|
||||
# endif
|
||||
};
|
||||
|
||||
|
||||
static void setDataDir(const char *path)
|
||||
{
|
||||
if (path == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string dir = path;
|
||||
if (!dir.empty() && (dir.back() == '/' || dir.back() == '\\')) {
|
||||
dir.pop_back();
|
||||
}
|
||||
|
||||
if (!dir.empty() && uv_chdir(dir.c_str()) == 0) {
|
||||
dataDir = dir;
|
||||
}
|
||||
}
|
||||
Process::Private *Process::d = nullptr;
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::Process::Process(int argc, char **argv) :
|
||||
m_arguments(argc, argv)
|
||||
xmrig::Process::Process(int argc, char **argv)
|
||||
{
|
||||
d = new Private(argc, argv);
|
||||
|
||||
OS::init();
|
||||
srand(static_cast<unsigned int>(Chrono::currentMSecsSinceEpoch() ^ reinterpret_cast<uintptr_t>(this)));
|
||||
|
||||
setDataDir(m_arguments.value("--data-dir", "-d"));
|
||||
d_fn()->setDataDir(arguments().value("--data-dir", "-d"));
|
||||
|
||||
# ifdef XMRIG_SHARED_DATADIR
|
||||
if (dataDir.empty()) {
|
||||
dataDir = fmt::format("{}" XMRIG_DIR_SEPARATOR ".xmrig" XMRIG_DIR_SEPARATOR, location(HomeLocation));
|
||||
if (d_fn()->dataDir.isEmpty()) {
|
||||
auto dataDir = fmt::format("{}" XMRIG_DIR_SEPARATOR ".xmrig" XMRIG_DIR_SEPARATOR, locate(HomeLocation));
|
||||
MKDIR(dataDir);
|
||||
|
||||
dataDir += APP_KIND;
|
||||
MKDIR(dataDir);
|
||||
|
||||
uv_chdir(dataDir.c_str());
|
||||
if (uv_chdir(dataDir.c_str()) == 0) {
|
||||
d_fn()->dataDir = { dataDir.c_str(), dataDir.size() };
|
||||
}
|
||||
}
|
||||
# endif
|
||||
|
||||
if (d_fn()->dataDir.isEmpty()) {
|
||||
d_fn()->dataDir = locate(ExeLocation);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
xmrig::Process::~Process()
|
||||
{
|
||||
OS::destroy();
|
||||
|
||||
delete d;
|
||||
|
||||
d = nullptr;
|
||||
}
|
||||
|
||||
|
||||
const xmrig::Arguments &xmrig::Process::arguments()
|
||||
{
|
||||
return d_fn()->arguments;
|
||||
}
|
||||
|
||||
|
||||
const char *xmrig::Process::version()
|
||||
{
|
||||
return d_fn()->version;
|
||||
}
|
||||
|
||||
|
||||
const xmrig::String &xmrig::Process::userAgent()
|
||||
{
|
||||
if (d_fn()->userAgent.isEmpty()) {
|
||||
d_fn()->userAgent = OS::userAgent().c_str();
|
||||
}
|
||||
|
||||
return d_fn()->userAgent;
|
||||
}
|
||||
|
||||
|
||||
const xmrig::Versions &xmrig::Process::versions()
|
||||
{
|
||||
return d_fn()->versions;
|
||||
}
|
||||
|
||||
|
||||
int xmrig::Process::exitCode()
|
||||
{
|
||||
return d_fn()->exitCode;
|
||||
}
|
||||
|
||||
|
||||
@@ -148,20 +191,94 @@ int xmrig::Process::ppid()
|
||||
}
|
||||
|
||||
|
||||
xmrig::String xmrig::Process::exepath()
|
||||
xmrig::String xmrig::Process::locate(Location location, const char *fileName)
|
||||
{
|
||||
size_t size = sizeof(pathBuf);
|
||||
|
||||
return uv_exepath(pathBuf, &size) < 0 ? String("") : String(pathBuf, size);
|
||||
}
|
||||
|
||||
|
||||
xmrig::String xmrig::Process::location(Location location, const char *fileName)
|
||||
{
|
||||
auto path = getPath(location);
|
||||
if (path.empty() || fileName == nullptr) {
|
||||
return path.c_str();
|
||||
auto path = locate(location);
|
||||
if (path.isNull() || fileName == nullptr) {
|
||||
return path;
|
||||
}
|
||||
|
||||
return fmt::format("{}" XMRIG_DIR_SEPARATOR "{}", path, fileName).c_str();
|
||||
}
|
||||
|
||||
|
||||
xmrig::String xmrig::Process::locate(Location location)
|
||||
{
|
||||
char buf[520]{};
|
||||
size_t size = sizeof(buf);
|
||||
|
||||
if (location == ExePathLocation && uv_exepath(buf, &size) >= 0) {
|
||||
return { buf, size };
|
||||
}
|
||||
|
||||
if (location == Process::DataLocation && !d_fn()->dataDir.isEmpty()) {
|
||||
return d_fn()->dataDir;
|
||||
}
|
||||
|
||||
# if UV_VERSION_HEX >= 0x010600
|
||||
if (location == Process::HomeLocation && uv_os_homedir(buf, &size) >= 0) {
|
||||
return { buf, size };
|
||||
}
|
||||
# endif
|
||||
|
||||
# if UV_VERSION_HEX >= 0x010900
|
||||
if (location == Process::TempLocation && uv_os_tmpdir(buf, &size) >= 0) {
|
||||
return { buf, size };
|
||||
}
|
||||
# endif
|
||||
|
||||
if (location == Process::CwdLocation && uv_cwd(buf, &size) >= 0) {
|
||||
return { buf, size };
|
||||
}
|
||||
|
||||
if (location == Process::ExeLocation) {
|
||||
if (uv_exepath(buf, &size) < 0) {
|
||||
return {};
|
||||
}
|
||||
|
||||
auto path = std::string(buf, size);
|
||||
const auto pos = path.rfind(*XMRIG_DIR_SEPARATOR);
|
||||
|
||||
if (pos != std::string::npos) {
|
||||
return path.substr(0, pos).c_str();
|
||||
}
|
||||
|
||||
return { buf, size };
|
||||
}
|
||||
|
||||
return location != ExeLocation ? locate(ExeLocation) : String();
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Process::exit(int code)
|
||||
{
|
||||
if (code != -1) {
|
||||
d_fn()->exitCode = code;
|
||||
}
|
||||
|
||||
# ifdef XMRIG_FEATURE_EVENTS
|
||||
events().post<ExitEvent>(exitCode());
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Process::setUserAgent(const String &userAgent)
|
||||
{
|
||||
d_fn()->userAgent = userAgent;
|
||||
}
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_EVENTS
|
||||
xmrig::Events &xmrig::Process::events()
|
||||
{
|
||||
return d_fn()->events;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
xmrig::Process::Private *xmrig::Process::d_fn()
|
||||
{
|
||||
assert(d);
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -20,7 +20,8 @@
|
||||
#define XMRIG_PROCESS_H
|
||||
|
||||
|
||||
#include "base/tools/Arguments.h"
|
||||
#include "base/tools/Object.h"
|
||||
#include "base/tools/String.h"
|
||||
|
||||
|
||||
#ifdef WIN32
|
||||
@@ -33,10 +34,18 @@
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class Arguments;
|
||||
class Events;
|
||||
class Versions;
|
||||
|
||||
|
||||
class Process
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Process)
|
||||
|
||||
enum Location {
|
||||
ExePathLocation,
|
||||
ExeLocation,
|
||||
CwdLocation,
|
||||
DataLocation,
|
||||
@@ -45,20 +54,34 @@ public:
|
||||
};
|
||||
|
||||
Process(int argc, char **argv);
|
||||
~Process();
|
||||
|
||||
static const Arguments &arguments();
|
||||
static const char *version();
|
||||
static const String &userAgent();
|
||||
static const Versions &versions();
|
||||
static int exitCode();
|
||||
static int pid();
|
||||
static int ppid();
|
||||
static String exepath();
|
||||
static String location(Location location, const char *fileName = nullptr);
|
||||
static String locate(Location location, const char *fileName);
|
||||
static String locate(Location location);
|
||||
static void exit(int code = -1);
|
||||
static void setUserAgent(const String &userAgent);
|
||||
|
||||
inline const Arguments &arguments() const { return m_arguments; }
|
||||
# ifdef XMRIG_FEATURE_EVENTS
|
||||
static Events &events();
|
||||
# endif
|
||||
|
||||
private:
|
||||
Arguments m_arguments;
|
||||
class Private;
|
||||
|
||||
static Private *d_fn();
|
||||
|
||||
static Private *d;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif /* XMRIG_PROCESS_H */
|
||||
#endif // XMRIG_PROCESS_H
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <uv.h>
|
||||
#include <unistd.h>
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
|
||||
203
src/base/kernel/Versions.cpp
Normal file
203
src/base/kernel/Versions.cpp
Normal file
@@ -0,0 +1,203 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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 "base/kernel/Versions.h"
|
||||
#include "3rdparty/fmt/core.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_HTTP
|
||||
# include "3rdparty/llhttp/llhttp.h"
|
||||
#endif
|
||||
|
||||
#ifdef XMRIG_FEATURE_TLS
|
||||
# include <openssl/opensslv.h>
|
||||
#endif
|
||||
|
||||
#ifdef XMRIG_FEATURE_SODIUM
|
||||
# include <sodium.h>
|
||||
#endif
|
||||
|
||||
#ifdef XMRIG_FEATURE_SQLITE
|
||||
# include "3rdparty/sqlite/sqlite3.h"
|
||||
#endif
|
||||
|
||||
#ifdef XMRIG_FEATURE_HWLOC
|
||||
# include "backend/cpu/Cpu.h"
|
||||
#endif
|
||||
|
||||
#ifdef XMRIG_FEATURE_POSTGRESQL
|
||||
# include <libpq-fe.h>
|
||||
#endif
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
const char *Versions::kApp = "app";
|
||||
const char *Versions::kBase = "base";
|
||||
const char *Versions::kFmt = "fmt";
|
||||
const char *Versions::kRapidjson = "rapidjson";
|
||||
const char *Versions::kUv = "uv";
|
||||
|
||||
#if defined (__INTEL_LLVM_COMPILER)
|
||||
const char *Versions::kCompiler = "icx";
|
||||
#elif defined(__INTEL_COMPILER)
|
||||
const char *Versions::kCompiler = "icc";
|
||||
#elif defined(__clang__)
|
||||
const char *Versions::kCompiler = "clang";
|
||||
#elif defined(__GNUC__)
|
||||
const char *Versions::kCompiler = "gcc";
|
||||
#elif defined(_MSC_VER)
|
||||
# if (_MSC_VER >= 1930)
|
||||
# define MSVC_VERSION 2022
|
||||
# elif (_MSC_VER >= 1920 && _MSC_VER < 1930)
|
||||
# define MSVC_VERSION 2019
|
||||
# elif (_MSC_VER >= 1910 && _MSC_VER < 1920)
|
||||
# define MSVC_VERSION 2017
|
||||
# elif _MSC_VER == 1900
|
||||
# define MSVC_VERSION 2015
|
||||
# else
|
||||
# define MSVC_VERSION 0
|
||||
# endif
|
||||
const char *Versions::kCompiler = "MSVC";
|
||||
#else
|
||||
const char *Versions::kCompiler = "unknown";
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_HTTP
|
||||
const char *Versions::kLlhttp = "llhttp";
|
||||
#endif
|
||||
|
||||
#ifdef XMRIG_FEATURE_TLS
|
||||
# if defined(LIBRESSL_VERSION_TEXT)
|
||||
const char *Versions::kTls = "libressl";
|
||||
# else
|
||||
const char *Versions::kTls = "openssl";
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef XMRIG_FEATURE_SODIUM
|
||||
const char *Versions::kSodium = "sodium";
|
||||
#endif
|
||||
|
||||
#ifdef XMRIG_FEATURE_SQLITE
|
||||
const char *Versions::kSqlite = "sqlite";
|
||||
#endif
|
||||
|
||||
#ifdef XMRIG_FEATURE_HWLOC
|
||||
const char *Versions::kHwloc = "hwloc";
|
||||
#endif
|
||||
|
||||
#ifdef XMRIG_FEATURE_POSTGRESQL
|
||||
const char *kPq = "pq";
|
||||
#endif
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
xmrig::Versions::Versions()
|
||||
{
|
||||
m_data.insert({ kApp, APP_VERSION });
|
||||
m_data.insert({ kBase, fmt::format("{}.{}.{}", XMRIG_BASE_VERSION / 10000, XMRIG_BASE_VERSION / 100 % 100, XMRIG_BASE_VERSION % 100).c_str() });
|
||||
m_data.insert({ kUv, uv_version_string() });
|
||||
m_data.insert({ kRapidjson, RAPIDJSON_VERSION_STRING });
|
||||
m_data.insert({ kFmt, fmt::format("{}.{}.{}", FMT_VERSION / 10000, FMT_VERSION / 100 % 100, FMT_VERSION % 100).c_str() });
|
||||
|
||||
# if defined (__INTEL_LLVM_COMPILER)
|
||||
m_data.insert({ kCompiler, fmt::format("{}.{}.{}", __INTEL_LLVM_COMPILER / 10000, __INTEL_LLVM_COMPILER / 100 % 100, __INTEL_LLVM_COMPILER % 100).c_str() });
|
||||
# elif defined (__INTEL_COMPILER)
|
||||
# if (__INTEL_COMPILER >= 2020)
|
||||
m_data.insert({ kCompiler, XMRIG_TOSTRING(__INTEL_COMPILER) });
|
||||
# else
|
||||
m_data.insert({ kCompiler, fmt::format("{}.{}.{}", __INTEL_COMPILER / 100, __INTEL_COMPILER / 10 % 10, __INTEL_COMPILER % 10).c_str() });
|
||||
# endif
|
||||
# elif defined(__clang__)
|
||||
m_data.insert({ kCompiler, XMRIG_TOSTRING(__clang_major__.__clang_minor__.__clang_patchlevel__) });
|
||||
# elif defined(__GNUC__)
|
||||
m_data.insert({ kCompiler, XMRIG_TOSTRING(__GNUC__.__GNUC_MINOR__.__GNUC_PATCHLEVEL__) });
|
||||
# elif defined(_MSC_VER)
|
||||
m_data.insert({ kCompiler, XMRIG_TOSTRING(MSVC_VERSION) });
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_HTTP
|
||||
m_data.insert({ kLlhttp, XMRIG_TOSTRING(LLHTTP_VERSION_MAJOR.LLHTTP_VERSION_MINOR.LLHTTP_VERSION_PATCH) });
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
# if defined(LIBRESSL_VERSION_TEXT)
|
||||
m_data.insert({ kTls, String(LIBRESSL_VERSION_TEXT).split(' ')[1] });
|
||||
# elif defined(OPENSSL_VERSION_TEXT)
|
||||
m_data.insert({ kTls, String(OPENSSL_VERSION_TEXT).split(' ')[1] });
|
||||
# endif
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_SODIUM
|
||||
m_data.insert({ kSodium, sodium_version_string() });
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_SQLITE
|
||||
m_data.insert({ kSqlite, sqlite3_libversion() });
|
||||
# endif
|
||||
|
||||
# if defined(XMRIG_FEATURE_HWLOC) && defined(XMRIG_LEGACY)
|
||||
m_data.insert({ kHwloc, String(Cpu::info()->backend()).split('/')[1] });
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_POSTGRESQL
|
||||
m_data.insert({ kPq, fmt::format("{}.{}", PQlibVersion() / 10000, PQlibVersion() % 100).c_str() });
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
const xmrig::String &xmrig::Versions::get(const char *key) const
|
||||
{
|
||||
static const String empty;
|
||||
|
||||
const auto it = m_data.find(key);
|
||||
|
||||
return it != m_data.end() ? it->second : empty;
|
||||
}
|
||||
|
||||
|
||||
rapidjson::Value xmrig::Versions::toJSON(rapidjson::Document &doc) const
|
||||
{
|
||||
using namespace rapidjson;
|
||||
|
||||
Value out(kObjectType);
|
||||
toJSON(out, doc);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Versions::toJSON(rapidjson::Value &out, rapidjson::Document &doc) const
|
||||
{
|
||||
auto &allocator = doc.GetAllocator();
|
||||
const auto &data = get();
|
||||
|
||||
for (const auto &kv : data) {
|
||||
out.AddMember(kv.first.toJSON(), kv.second.toJSON(), allocator);
|
||||
}
|
||||
}
|
||||
83
src/base/kernel/Versions.h
Normal file
83
src/base/kernel/Versions.h
Normal file
@@ -0,0 +1,83 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_VERSIONS_H
|
||||
#define XMRIG_VERSIONS_H
|
||||
|
||||
|
||||
#include "base/tools/String.h"
|
||||
|
||||
|
||||
#include <map>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class Versions
|
||||
{
|
||||
public:
|
||||
static const char *kApp;
|
||||
static const char *kBase;
|
||||
static const char *kCompiler;
|
||||
static const char *kFmt;
|
||||
static const char *kRapidjson;
|
||||
static const char *kUv;
|
||||
|
||||
# ifdef XMRIG_FEATURE_HTTP
|
||||
static const char *kLlhttp;
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_TLS
|
||||
static const char *kTls;
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_SODIUM
|
||||
static const char *kSodium;
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_SQLITE
|
||||
static const char *kSqlite;
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_HWLOC
|
||||
static const char *kHwloc;
|
||||
# endif
|
||||
|
||||
# ifdef XMRIG_FEATURE_POSTGRESQL
|
||||
static const char *kPq;
|
||||
# endif
|
||||
|
||||
Versions();
|
||||
|
||||
inline const std::map<String, String> &get() const { return m_data; }
|
||||
inline const String &operator[](const char *key) const { return get(key); }
|
||||
|
||||
const String &get(const char *key) const;
|
||||
rapidjson::Value toJSON(rapidjson::Document &doc) const;
|
||||
void toJSON(rapidjson::Value &out, rapidjson::Document &doc) const;
|
||||
|
||||
private:
|
||||
std::map<String, String> m_data;
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
|
||||
|
||||
#endif /* XMRIG_VERSIONS_H */
|
||||
49
src/base/kernel/base-version.h
Normal file
49
src/base/kernel/base-version.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
#ifndef XMRIG_BASE_VERSION_H
|
||||
#define XMRIG_BASE_VERSION_H
|
||||
|
||||
// The base version in the form major * 10000 + minor * 100 + patch.
|
||||
#define XMRIG_BASE_VERSION 70000
|
||||
|
||||
#ifndef APP_DOMAIN
|
||||
# define APP_DOMAIN "xmrig.com"
|
||||
#endif
|
||||
|
||||
#ifndef APP_COPYRIGHT
|
||||
# define APP_COPYRIGHT "Copyright (C) 2016-2022 xmrig.com"
|
||||
#endif
|
||||
|
||||
#define XMRIG_STRINGIFY(x) #x
|
||||
#define XMRIG_TOSTRING(x) XMRIG_STRINGIFY(x)
|
||||
|
||||
#ifdef GIT_COMMIT_HASH
|
||||
# define XMRIG_GIT_COMMIT_HASH XMRIG_TOSTRING(GIT_COMMIT_HASH)
|
||||
#else
|
||||
# define XMRIG_GIT_COMMIT_HASH "0000000"
|
||||
#endif
|
||||
|
||||
#ifdef GIT_BRANCH
|
||||
# define XMRIG_GIT_BRANCH XMRIG_TOSTRING(GIT_BRANCH)
|
||||
# define APP_VERSION XMRIG_TOSTRING(APP_VER_MAJOR.APP_VER_MINOR.APP_VER_PATCH) "-" XMRIG_GIT_BRANCH
|
||||
#else
|
||||
# define APP_VERSION XMRIG_TOSTRING(APP_VER_MAJOR.APP_VER_MINOR.APP_VER_PATCH)
|
||||
#endif
|
||||
|
||||
#endif // XMRIG_BASE_VERSION_H
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -14,15 +14,24 @@
|
||||
*
|
||||
* 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 "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"
|
||||
|
||||
@@ -32,7 +41,6 @@
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
#ifdef XMRIG_FEATURE_TLS
|
||||
@@ -132,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());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -14,13 +14,20 @@
|
||||
*
|
||||
* 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_BASECONFIG_H
|
||||
#define XMRIG_BASECONFIG_H
|
||||
|
||||
|
||||
#include "base/kernel/config/Title.h"
|
||||
#include "base/kernel/private/Title.h"
|
||||
#include "base/kernel/interfaces/IConfig.h"
|
||||
#include "base/net/http/Http.h"
|
||||
#include "base/net/stratum/Pools.h"
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
#include "base/net/dns/DnsConfig.h"
|
||||
#include "base/net/stratum/Pool.h"
|
||||
#include "base/net/stratum/Pools.h"
|
||||
#include "base/tools/Arguments.h"
|
||||
#include "core/config/Config_platform.h"
|
||||
|
||||
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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 "base/kernel/config/Title.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "base/io/Env.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
xmrig::Title::Title(const rapidjson::Value &value)
|
||||
{
|
||||
if (value.IsBool()) {
|
||||
m_enabled = value.GetBool();
|
||||
}
|
||||
else if (value.IsString()) {
|
||||
m_value = value.GetString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
rapidjson::Value xmrig::Title::toJSON() const
|
||||
{
|
||||
if (isEnabled() && !m_value.isNull()) {
|
||||
return m_value.toJSON();
|
||||
}
|
||||
|
||||
return rapidjson::Value(m_enabled);
|
||||
}
|
||||
|
||||
|
||||
xmrig::String xmrig::Title::value() const
|
||||
{
|
||||
if (!isEnabled()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (m_value.isNull()) {
|
||||
return APP_NAME " " APP_VERSION;
|
||||
}
|
||||
|
||||
return Env::expand(m_value);
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -30,6 +24,7 @@
|
||||
|
||||
|
||||
#include "3rdparty/rapidjson/fwd.h"
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
@@ -44,7 +39,10 @@ class SubmitResult;
|
||||
class IClientListener
|
||||
{
|
||||
public:
|
||||
virtual ~IClientListener() = default;
|
||||
XMRIG_DISABLE_COPY_MOVE(IClientListener)
|
||||
|
||||
IClientListener() = default;
|
||||
virtual ~IClientListener() = default;
|
||||
|
||||
virtual void onClose(IClient *client, int failures) = 0;
|
||||
virtual void onJobReceived(IClient *client, const Job &job, const rapidjson::Value ¶ms) = 0;
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -27,6 +21,7 @@
|
||||
|
||||
|
||||
#include "3rdparty/rapidjson/fwd.h"
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
@@ -39,6 +34,9 @@ class String;
|
||||
class IConfigTransform
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE(IConfigTransform)
|
||||
|
||||
IConfigTransform() = default;
|
||||
virtual ~IConfigTransform() = default;
|
||||
|
||||
virtual void finalize(rapidjson::Document &doc) = 0;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -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_ICONSOLELISTENER_H
|
||||
@@ -38,7 +45,7 @@ public:
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif // XMRIG_ICONSOLELISTENER_H
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -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_ISIGNALLISTENER_H
|
||||
@@ -41,7 +48,7 @@ public:
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif // XMRIG_ISIGNALLISTENER_H
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -29,6 +23,9 @@
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
@@ -41,7 +38,10 @@ class ProxyUrl;
|
||||
class IStrategy
|
||||
{
|
||||
public:
|
||||
virtual ~IStrategy() = default;
|
||||
XMRIG_DISABLE_COPY_MOVE(IStrategy)
|
||||
|
||||
IStrategy() = default;
|
||||
virtual ~IStrategy() = default;
|
||||
|
||||
virtual bool isActive() const = 0;
|
||||
virtual IClient *client() const = 0;
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -26,10 +20,13 @@
|
||||
#define XMRIG_ITCPSERVERLISTENER_H
|
||||
|
||||
|
||||
#include <stdint.h>
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
typedef struct uv_stream_s uv_stream_t;
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
using uv_stream_t = struct uv_stream_s;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
@@ -41,7 +38,10 @@ class String;
|
||||
class ITcpServerListener
|
||||
{
|
||||
public:
|
||||
virtual ~ITcpServerListener() = default;
|
||||
XMRIG_DISABLE_COPY_MOVE(ITcpServerListener)
|
||||
|
||||
ITcpServerListener() = default;
|
||||
virtual ~ITcpServerListener() = default;
|
||||
|
||||
virtual void onConnection(uv_stream_t *stream, uint16_t port) = 0;
|
||||
};
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
||||
@@ -1,12 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
||||
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
||||
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -26,6 +20,9 @@
|
||||
#define XMRIG_IWATCHERLISTENER_H
|
||||
|
||||
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
@@ -35,6 +32,9 @@ class String;
|
||||
class IWatcherListener
|
||||
{
|
||||
public:
|
||||
XMRIG_DISABLE_COPY_MOVE(IWatcherListener)
|
||||
|
||||
IWatcherListener() = default;
|
||||
virtual ~IWatcherListener() = default;
|
||||
|
||||
virtual void onFileChanged(const String &fileName) = 0;
|
||||
|
||||
124
src/base/kernel/private/Title.cpp
Normal file
124
src/base/kernel/private/Title.cpp
Normal file
@@ -0,0 +1,124 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
* 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 "base/kernel/private/Title.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
#include "base/io/Env.h"
|
||||
#include "base/kernel/interfaces/IJsonReader.h"
|
||||
#include "base/tools/Arguments.h"
|
||||
#include "version.h"
|
||||
|
||||
|
||||
#ifdef APP_DEBUG
|
||||
# include "base/io/log/Log.h"
|
||||
# include "base/kernel/Config.h"
|
||||
#endif
|
||||
|
||||
|
||||
const char *xmrig::Title::kField = "title";
|
||||
|
||||
|
||||
xmrig::Title::Title(const Arguments &arguments)
|
||||
{
|
||||
# ifdef XMRIG_DEPRECATED
|
||||
if (arguments.contains("--no-title")) {
|
||||
m_enabled = false;
|
||||
|
||||
return;
|
||||
}
|
||||
# endif
|
||||
|
||||
const size_t pos = arguments.pos("--title");
|
||||
if (pos) {
|
||||
m_value = arguments.value(pos + 1U);
|
||||
m_enabled = !m_value.isEmpty();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
xmrig::Title::Title(const IJsonReader &reader, const Title ¤t)
|
||||
{
|
||||
if (!parse(reader.getValue(kField))) {
|
||||
m_value = current.m_value;
|
||||
m_enabled = current.m_enabled;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
rapidjson::Value xmrig::Title::toJSON() const
|
||||
{
|
||||
return isEnabled() ? m_value.toJSON() : rapidjson::Value(m_enabled);
|
||||
}
|
||||
|
||||
|
||||
xmrig::String xmrig::Title::value() const
|
||||
{
|
||||
if (!isEnabled()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
if (m_value.isNull()) {
|
||||
return APP_NAME " " APP_VERSION;
|
||||
}
|
||||
|
||||
return Env::expand(m_value);
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Title::print() const
|
||||
{
|
||||
# ifdef APP_DEBUG
|
||||
LOG_DEBUG("%s " MAGENTA_BOLD("TITLE")
|
||||
MAGENTA("<enabled=") CYAN("%d")
|
||||
MAGENTA(", value=") "\"%s\""
|
||||
MAGENTA(">"),
|
||||
Config::tag(), m_enabled, m_value.data());
|
||||
# endif
|
||||
}
|
||||
|
||||
|
||||
void xmrig::Title::save(rapidjson::Document &doc) const
|
||||
{
|
||||
doc.AddMember(rapidjson::StringRef(kField), toJSON(), doc.GetAllocator());
|
||||
}
|
||||
|
||||
|
||||
bool xmrig::Title::parse(const rapidjson::Value &value)
|
||||
{
|
||||
if (value.IsBool()) {
|
||||
m_enabled = value.GetBool();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (value.IsString()) {
|
||||
m_value = value.GetString();
|
||||
m_enabled = !m_value.isEmpty();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
74
src/base/kernel/private/Title.h
Normal file
74
src/base/kernel/private/Title.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
* 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_TITLE_H
|
||||
#define XMRIG_TITLE_H
|
||||
|
||||
|
||||
#include "3rdparty/rapidjson/fwd.h"
|
||||
#include "base/tools/String.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class Arguments;
|
||||
class IJsonReader;
|
||||
|
||||
|
||||
class Title
|
||||
{
|
||||
public:
|
||||
static const char *kField;
|
||||
|
||||
Title() = default;
|
||||
Title(bool enabled) : m_enabled(enabled) {}
|
||||
Title(const Arguments &arguments);
|
||||
Title(const IJsonReader &reader, const Title ¤t);
|
||||
inline Title(const rapidjson::Value &value) { parse(value); }
|
||||
|
||||
inline bool isEnabled() const { return m_enabled; }
|
||||
inline bool isEqual(const Title &other) const { return (m_enabled == other.m_enabled && m_value == other.m_value); }
|
||||
|
||||
inline bool operator!=(const Title &other) const { return !isEqual(other); }
|
||||
inline bool operator==(const Title &other) const { return isEqual(other); }
|
||||
|
||||
rapidjson::Value toJSON() const;
|
||||
String value() const;
|
||||
void print() const;
|
||||
void save(rapidjson::Document &doc) const;
|
||||
|
||||
private:
|
||||
bool parse(const rapidjson::Value &value);
|
||||
|
||||
bool m_enabled = true;
|
||||
String m_value;
|
||||
};
|
||||
|
||||
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif // XMRIG_TITLE_H
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ private:
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif /* XMRIG_DNSRECORD_H */
|
||||
#endif // XMRIG_DNSRECORD_H
|
||||
|
||||
@@ -42,7 +42,7 @@ private:
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif /* XMRIG_DNSRECORDS_H */
|
||||
#endif // XMRIG_DNSRECORDS_H
|
||||
|
||||
@@ -23,9 +23,6 @@
|
||||
#include "base/tools/Object.h"
|
||||
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
@@ -44,7 +41,7 @@ public:
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif /* XMRIG_DNSREQUEST_H */
|
||||
#endif // XMRIG_DNSREQUEST_H
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
@@ -28,17 +27,17 @@
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
static Storage<DnsUvBackend>* storage = nullptr;
|
||||
|
||||
static Storage<DnsUvBackend> *storage = nullptr;
|
||||
|
||||
|
||||
Storage<DnsUvBackend>& DnsUvBackend::getStorage()
|
||||
{
|
||||
if (storage == nullptr) storage = new Storage<DnsUvBackend>();
|
||||
return *storage;
|
||||
}
|
||||
if (!storage) {
|
||||
storage = new Storage<DnsUvBackend>();
|
||||
}
|
||||
|
||||
void DnsUvBackend::releaseStorage()
|
||||
{
|
||||
delete storage;
|
||||
return *storage;
|
||||
}
|
||||
|
||||
static addrinfo hints{};
|
||||
@@ -62,7 +61,9 @@ xmrig::DnsUvBackend::DnsUvBackend()
|
||||
xmrig::DnsUvBackend::~DnsUvBackend()
|
||||
{
|
||||
getStorage().release(m_key);
|
||||
releaseStorage();
|
||||
|
||||
delete storage;
|
||||
storage = nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -62,11 +62,10 @@ private:
|
||||
uintptr_t m_key;
|
||||
|
||||
static Storage<DnsUvBackend>& getStorage();
|
||||
void releaseStorage();
|
||||
};
|
||||
|
||||
|
||||
} /* namespace xmrig */
|
||||
} // namespace xmrig
|
||||
|
||||
|
||||
#endif /* XMRIG_DNSUVBACKEND_H */
|
||||
#endif // XMRIG_DNSUVBACKEND_H
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef XMRIG_FETCH_H
|
||||
#define XMRIG_FETCH_H
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/net/http/HttpApiResponse.h"
|
||||
#include "3rdparty/rapidjson/prettywriter.h"
|
||||
#include "3rdparty/rapidjson/stringbuffer.h"
|
||||
|
||||
@@ -17,11 +17,10 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/net/http/HttpClient.h"
|
||||
#include "3rdparty/llhttp/llhttp.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/kernel/Platform.h"
|
||||
#include "base/kernel/Process.h"
|
||||
#include "base/net/dns/Dns.h"
|
||||
#include "base/net/dns/DnsRecords.h"
|
||||
#include "base/net/tools/NetBuffer.h"
|
||||
@@ -95,7 +94,7 @@ void xmrig::HttpClient::handshake()
|
||||
{
|
||||
headers.insert({ "Host", host() });
|
||||
headers.insert({ "Connection", "close" });
|
||||
headers.insert({ "User-Agent", Platform::userAgent().data() });
|
||||
headers.insert({ "User-Agent", Process::userAgent().data() });
|
||||
|
||||
if (!body.empty()) {
|
||||
headers.insert({ "Content-Length", std::to_string(body.size()) });
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef XMRIG_HTTPCLIENT_H
|
||||
#define XMRIG_HTTPCLIENT_H
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/net/http/HttpContext.h"
|
||||
#include "3rdparty/llhttp/llhttp.h"
|
||||
#include "base/kernel/interfaces/IHttpListener.h"
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef XMRIG_HTTPCONTEXT_H
|
||||
#define XMRIG_HTTPCONTEXT_H
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/net/http/HttpData.h"
|
||||
#include "3rdparty/llhttp/llhttp.h"
|
||||
#include "3rdparty/rapidjson/document.h"
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef XMRIG_HTTPDATA_H
|
||||
#define XMRIG_HTTPDATA_H
|
||||
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/net/http/HttpListener.h"
|
||||
#include "3rdparty/llhttp/llhttp.h"
|
||||
#include "base/io/log/Log.h"
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include "base/net/http/HttpResponse.h"
|
||||
#include "3rdparty/llhttp/llhttp.h"
|
||||
#include "base/io/log/Log.h"
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <functional>
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -17,7 +17,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#include <cassert>
|
||||
#include <openssl/ssl.h>
|
||||
#include <uv.h>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2014-2019 heapwolf <https://github.com/heapwolf>
|
||||
* Copyright (c) 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -17,7 +17,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef XMRIG_HTTPSCLIENT_H
|
||||
#define XMRIG_HTTPSCLIENT_H
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
xmrig::HttpsContext::HttpsContext(TlsContext *tls, const std::weak_ptr<IHttpListener> &listener) :
|
||||
HttpContext(HTTP_REQUEST, listener),
|
||||
ServerTls(tls ? tls->ctx() : nullptr)
|
||||
ServerTls(tls ? tls->handle() : nullptr)
|
||||
{
|
||||
if (!tls) {
|
||||
m_mode = TLS_OFF;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -16,7 +16,6 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef XMRIG_HTTPSCONTEXT_H
|
||||
#define XMRIG_HTTPSCONTEXT_H
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -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)
|
||||
{
|
||||
@@ -34,14 +51,19 @@ xmrig::HttpsServer::HttpsServer(const std::shared_ptr<IHttpListener> &listener)
|
||||
xmrig::HttpsServer::~HttpsServer()
|
||||
{
|
||||
HttpContext::closeAll();
|
||||
|
||||
delete m_tls;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -49,7 +71,7 @@ bool xmrig::HttpsServer::setTls(const TlsConfig &config)
|
||||
|
||||
void xmrig::HttpsServer::onConnection(uv_stream_t *stream, uint16_t)
|
||||
{
|
||||
auto ctx = new HttpsContext(m_tls, m_listener);
|
||||
auto ctx = new HttpsContext(m_tls.get(), m_listener);
|
||||
uv_accept(stream, ctx->stream());
|
||||
|
||||
uv_read_start(ctx->stream(), NetBuffer::onAlloc, onRead); // NOLINT(clang-analyzer-cplusplus.NewDeleteLeaks)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/* XMRig
|
||||
* Copyright (c) 2018-2021 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2021 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright (c) 2018-2022 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright (c) 2016-2022 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
@@ -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
|
||||
@@ -58,8 +65,8 @@ protected:
|
||||
private:
|
||||
static void onRead(uv_stream_t *stream, ssize_t nread, const uv_buf_t *buf);
|
||||
|
||||
std::shared_ptr<TlsContext> m_tls;
|
||||
std::weak_ptr<IHttpListener> m_listener;
|
||||
TlsContext *m_tls = nullptr;
|
||||
};
|
||||
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user