Added xmrigDaemon to control xmrigMiner
Fixed some issues in CCClient and CCServer
This commit is contained in:
parent
2b97e2f4ff
commit
3f39ca31fd
15 changed files with 86 additions and 83 deletions
|
@ -275,10 +275,11 @@ if (WITH_CC)
|
|||
|
||||
set(SOURCES_CC_SERVER
|
||||
src/cc/CCServer.cpp
|
||||
src/cc/xmrigCC.cpp
|
||||
src/cc/Service.cpp
|
||||
src/cc/Summary.cpp
|
||||
src/cc/Httpd.cpp)
|
||||
src/cc/Httpd.cpp
|
||||
src/xmrigCC.cpp
|
||||
)
|
||||
else()
|
||||
add_definitions(/DXMRIG_NO_CC)
|
||||
endif()
|
||||
|
@ -287,12 +288,13 @@ include_directories(src)
|
|||
include_directories(src/3rdparty)
|
||||
include_directories(${UV_INCLUDE_DIR})
|
||||
|
||||
add_executable(xmrig ${HEADERS} ${SOURCES} ${HEADERS_COMMON} ${SOURCES_COMMON} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG} ${HTTPD_SOURCES} ${SOURCES_CC_COMMON} ${HEADERS_CC_COMMON} ${SOURCES_CC_CLIENT} ${HEADERS_CC_CLIENT})
|
||||
target_link_libraries(xmrig ${UV_LIBRARIES} ${MHD_LIBRARY} ${CURL_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB})
|
||||
add_executable(xmrigMiner ${HEADERS} ${SOURCES} ${HEADERS_COMMON} ${SOURCES_COMMON} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CRYPTO} ${SOURCES_CRYPTO} ${SOURCES_SYSLOG} ${HTTPD_SOURCES} ${SOURCES_CC_COMMON} ${HEADERS_CC_COMMON} ${SOURCES_CC_CLIENT} ${HEADERS_CC_CLIENT})
|
||||
target_link_libraries(xmrigMiner ${UV_LIBRARIES} ${MHD_LIBRARY} ${CURL_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB})
|
||||
|
||||
add_executable(xmrigDaemon src/xmrigd.cpp)
|
||||
|
||||
if (WITH_CC AND MHD_FOUND AND CURL_FOUND)
|
||||
add_executable(xmrigCC ${HEADERS_COMMON} ${SOURCES_COMMON} ${SOURCES_OS} ${SOURCES_CPUID} ${SOURCES_SYSLOG} ${SOURCES_CC_COMMON} ${HEADERS_CC_COMMON} ${SOURCES_CC_SERVER} ${HEADERS_CC_SERVER})
|
||||
target_link_libraries(xmrigCC ${UV_LIBRARIES} ${MHD_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB})
|
||||
set_target_properties(xmrigCC PROPERTIES COMPILE_FLAGS "-DXMRIG_CC_SERVER ${SHARED_FLAGS}")
|
||||
add_executable(xmrigCCServer ${HEADERS_COMMON} ${SOURCES_COMMON} ${SOURCES_OS} ${SOURCES_CPUID} ${SOURCES_SYSLOG} ${SOURCES_CC_COMMON} ${HEADERS_CC_COMMON} ${SOURCES_CC_SERVER} ${HEADERS_CC_SERVER})
|
||||
target_link_libraries(xmrigCCServer ${UV_LIBRARIES} ${MHD_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB})
|
||||
set_target_properties(xmrigCCServer PROPERTIES COMPILE_FLAGS "-DXMRIG_CC_SERVER ${SHARED_FLAGS}")
|
||||
endif()
|
59
src/App.cpp
59
src/App.cpp
|
@ -25,6 +25,7 @@
|
|||
|
||||
#include <stdlib.h>
|
||||
#include <uv.h>
|
||||
#include <zconf.h>
|
||||
|
||||
#include "api/Api.h"
|
||||
#include "App.h"
|
||||
|
@ -53,7 +54,6 @@
|
|||
App *App::m_self = nullptr;
|
||||
|
||||
|
||||
|
||||
App::App(int argc, char **argv) :
|
||||
m_restart(false),
|
||||
m_console(nullptr),
|
||||
|
@ -98,31 +98,7 @@ App::App(int argc, char **argv) :
|
|||
|
||||
App::~App()
|
||||
{
|
||||
Log::release();
|
||||
Options::release();
|
||||
Mem::release();
|
||||
Platform::release();
|
||||
|
||||
delete m_network;
|
||||
|
||||
# ifndef XMRIG_NO_HTTPD
|
||||
delete m_httpd;
|
||||
# endif
|
||||
|
||||
# ifndef XMRIG_NO_CC
|
||||
delete m_ccclient;
|
||||
# endif
|
||||
|
||||
delete m_console;
|
||||
|
||||
# ifndef XMRIG_NO_API
|
||||
Api::release();
|
||||
# endif
|
||||
|
||||
uv_signal_stop(&m_signal);
|
||||
uv_tty_reset_mode();
|
||||
|
||||
m_self = nullptr;
|
||||
}
|
||||
|
||||
|
||||
|
@ -166,10 +142,25 @@ int App::start()
|
|||
const int r = uv_run(uv_default_loop(), UV_RUN_DEFAULT);
|
||||
uv_loop_close(uv_default_loop());
|
||||
|
||||
delete m_network;
|
||||
|
||||
Options::release();
|
||||
Mem::release();
|
||||
Platform::release();
|
||||
|
||||
uv_tty_reset_mode();
|
||||
|
||||
# ifndef XMRIG_NO_HTTPD
|
||||
delete m_httpd;
|
||||
# endif
|
||||
|
||||
# ifndef XMRIG_NO_CC
|
||||
delete m_ccclient;
|
||||
# endif
|
||||
|
||||
return m_restart ? ERESTART : r;
|
||||
}
|
||||
|
||||
|
||||
void App::onConsoleCommand(char command)
|
||||
{
|
||||
switch (command) {
|
||||
|
@ -178,11 +169,6 @@ void App::onConsoleCommand(char command)
|
|||
Workers::printHashrate(true);
|
||||
break;
|
||||
|
||||
case 'i':
|
||||
case 'I':
|
||||
restart();
|
||||
break;
|
||||
|
||||
case 'p':
|
||||
case 'P':
|
||||
LOG_INFO(m_options->colors() ? "\x1B[01;33mpaused\x1B[0m, press \x1B[01;35mr\x1B[0m to resume" : "paused, press 'r' to resume");
|
||||
|
@ -200,7 +186,8 @@ void App::onConsoleCommand(char command)
|
|||
case 'q':
|
||||
case 'Q':
|
||||
case 3:
|
||||
stop(false);
|
||||
LOG_INFO(m_options->colors() ? "\x1B[01;33mquitting" : "quitting");
|
||||
quit();
|
||||
break;
|
||||
|
||||
default:
|
||||
|
@ -224,6 +211,11 @@ void App::restart()
|
|||
m_self->stop(true);
|
||||
}
|
||||
|
||||
void App::quit()
|
||||
{
|
||||
m_self->stop(false);
|
||||
}
|
||||
|
||||
void App::onSignal(uv_signal_t *handle, int signum)
|
||||
{
|
||||
switch (signum)
|
||||
|
@ -244,5 +236,6 @@ void App::onSignal(uv_signal_t *handle, int signum)
|
|||
break;
|
||||
}
|
||||
|
||||
m_self->stop(false);
|
||||
uv_signal_stop(handle);
|
||||
App::quit();
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ public:
|
|||
int start();
|
||||
|
||||
static void restart();
|
||||
static void quit();
|
||||
|
||||
protected:
|
||||
void onConsoleCommand(char command) override;
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
*/
|
||||
|
||||
|
||||
#include <zconf.h>
|
||||
#include "Console.h"
|
||||
#include "interfaces/IConsoleListener.h"
|
||||
|
||||
|
@ -30,7 +31,10 @@ Console::Console(IConsoleListener *listener)
|
|||
: m_listener(listener)
|
||||
{
|
||||
m_tty.data = this;
|
||||
uv_tty_init(uv_default_loop(), &m_tty, 0, 1);
|
||||
|
||||
if (uv_tty_init(uv_default_loop(), &m_tty, 0, 1) < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!uv_is_readable(reinterpret_cast<uv_stream_t*>(&m_tty))) {
|
||||
return;
|
||||
|
@ -40,11 +44,6 @@ Console::Console(IConsoleListener *listener)
|
|||
uv_read_start(reinterpret_cast<uv_stream_t*>(&m_tty), Console::onAllocBuffer, Console::onRead);
|
||||
}
|
||||
|
||||
Console::~Console()
|
||||
{
|
||||
uv_read_stop(reinterpret_cast<uv_stream_t*>(&m_tty));
|
||||
uv_tty_reset_mode();
|
||||
}
|
||||
|
||||
void Console::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t *buf)
|
||||
{
|
||||
|
@ -53,13 +52,14 @@ void Console::onAllocBuffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t
|
|||
buf->base = console->m_buf;
|
||||
}
|
||||
|
||||
|
||||
void Console::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) {
|
||||
if (nread == 1 && static_cast<Console*>(stream->data)->m_listener && buf) {
|
||||
static_cast<Console*>(stream->data)->m_listener->onConsoleCommand(buf->base[0]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -153,6 +153,7 @@ static struct option const options[] = {
|
|||
{ "cc-pass", 1, nullptr, 4008 },
|
||||
{ "cc-client-config-folder", 1, nullptr, 4009 },
|
||||
{ "cc-custom-dashboard", 1, nullptr, 4010 },
|
||||
{ "daemonized", 0, nullptr, 4011 },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
|
||||
|
@ -250,6 +251,7 @@ Options::Options(int argc, char **argv) :
|
|||
m_ready(false),
|
||||
m_safe(false),
|
||||
m_syslog(false),
|
||||
m_daemonized(false),
|
||||
m_configFile(Platform::defaultConfigName()),
|
||||
m_apiToken(nullptr),
|
||||
m_apiWorkerId(nullptr),
|
||||
|
@ -295,7 +297,6 @@ Options::Options(int argc, char **argv) :
|
|||
return;
|
||||
}
|
||||
|
||||
|
||||
#ifdef XMRIG_CC_SERVER
|
||||
if (m_ccPort == 0) {
|
||||
parseConfig(Platform::defaultConfigName());
|
||||
|
@ -306,6 +307,14 @@ Options::Options(int argc, char **argv) :
|
|||
return;
|
||||
}
|
||||
#else
|
||||
|
||||
#ifndef XMRIG_NO_CC
|
||||
if (!m_daemonized) {
|
||||
fprintf(stderr, "\"" APP_ID "\" is compiled with CC support, please start the daemon instead.\n");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!m_pools[0]->isValid()) {
|
||||
parseConfig(Platform::defaultConfigName());
|
||||
}
|
||||
|
@ -465,6 +474,9 @@ bool Options::parseArg(int key, const char *arg)
|
|||
free(m_ccCustomDashboard);
|
||||
m_ccCustomDashboard = strdup(arg);
|
||||
break;
|
||||
case 4011: /* --daemonized */
|
||||
m_daemonized = true;
|
||||
break;
|
||||
|
||||
case 'r': /* --retries */
|
||||
case 'R': /* --retry-pause */
|
||||
|
|
|
@ -62,6 +62,7 @@ public:
|
|||
inline bool doubleHash() const { return m_doubleHash; }
|
||||
inline bool hugePages() const { return m_hugePages; }
|
||||
inline bool syslog() const { return m_syslog; }
|
||||
inline bool daemonized() const { return m_daemonized; }
|
||||
inline const char *configFile() const { return m_configFile; }
|
||||
inline const char *apiToken() const { return m_apiToken; }
|
||||
inline const char *apiWorkerId() const { return m_apiWorkerId; }
|
||||
|
@ -87,9 +88,7 @@ public:
|
|||
inline int ccPort() const { return m_ccPort; }
|
||||
inline int64_t affinity() const { return m_affinity; }
|
||||
|
||||
inline static void release() { delete m_self; }
|
||||
|
||||
void parseConfig(const char *fileName);
|
||||
inline static void release() { delete m_self; }
|
||||
|
||||
const char *algoName() const;
|
||||
|
||||
|
@ -106,6 +105,7 @@ private:
|
|||
bool parseArg(int key, uint64_t arg);
|
||||
bool parseBoolean(int key, bool enable);
|
||||
Url *parseUrl(const char *arg) const;
|
||||
void parseConfig(const char *fileName);
|
||||
void parseJSON(const struct option *option, const rapidjson::Value &object);
|
||||
void showUsage(int status) const;
|
||||
void showVersion(void);
|
||||
|
@ -126,6 +126,7 @@ private:
|
|||
bool m_ready;
|
||||
bool m_safe;
|
||||
bool m_syslog;
|
||||
bool m_daemonized;
|
||||
char *m_apiToken;
|
||||
char *m_apiWorkerId;
|
||||
char *m_logFile;
|
||||
|
|
|
@ -152,10 +152,10 @@ static void print_cc()
|
|||
static void print_commands()
|
||||
{
|
||||
if (Options::i()->colors()) {
|
||||
Log::i()->text("\x1B[01;32m * \x1B[01;37mCOMMANDS: \x1B[01;35mh\x1B[01;37mashrate, \x1B[01;35mi\x1B[01;37mnvalidate, \x1B[01;35mp\x1B[01;37mause, \x1B[01;35mr\x1B[01;37mesume, \x1B[01;35mq\x1B[01;37muit");
|
||||
Log::i()->text("\x1B[01;32m * \x1B[01;37mCOMMANDS: \x1B[01;35mh\x1B[01;37mashrate, \x1B[01;35mp\x1B[01;37mause, \x1B[01;35mr\x1B[01;37mesume, \x1B[01;35mq\x1B[01;37muit");
|
||||
}
|
||||
else {
|
||||
Log::i()->text(" * COMMANDS: 'h' hashrate, 'i' invalidate, 'p' pause, 'r' resume, 'q' quit");
|
||||
Log::i()->text(" * COMMANDS: 'h' hashrate, 'p' pause, 'r' resume, 'q' quit");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -116,23 +116,26 @@ void CCClient::publishClientStatusReport()
|
|||
if (controlCommand.parseFromJsonString(responseBuffer)) {
|
||||
if (controlCommand.getCommand() == ControlCommand::START) {
|
||||
if (!Workers::isEnabled()) {
|
||||
LOG_INFO("[CC-Client] Command: START received -> resume");
|
||||
LOG_WARN("[CC-Client] Command: START received -> resume");
|
||||
Workers::setEnabled(true);
|
||||
}
|
||||
} else if (controlCommand.getCommand() == ControlCommand::STOP) {
|
||||
if (Workers::isEnabled()) {
|
||||
LOG_INFO("[CC-Client] Command: STOP received -> pause");
|
||||
LOG_WARN("[CC-Client] Command: STOP received -> pause");
|
||||
Workers::setEnabled(false);
|
||||
}
|
||||
} else if (controlCommand.getCommand() == ControlCommand::UPDATE_CONFIG) {
|
||||
LOG_WARN("[CC-Client] Command: UPDATE_CONFIG received -> update config");
|
||||
updateConfig();
|
||||
} else if (controlCommand.getCommand() == ControlCommand::RESTART) {
|
||||
LOG_WARN("[CC-Client] Command: RESTART received -> restart");
|
||||
App::restart();
|
||||
} else if (controlCommand.getCommand() == ControlCommand::QUIT) {
|
||||
// TODO
|
||||
LOG_WARN("[CC-Client] Command: QUIT received -> quit");
|
||||
App::quit();
|
||||
}
|
||||
} else {
|
||||
LOG_ERR("[CC-Client] unknown command received from CC Server.");
|
||||
LOG_ERR("[CC-Client] Unknown command received from CC Server.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -162,13 +165,13 @@ void CCClient::updateConfig()
|
|||
clientConfigFile << buffer.GetString();
|
||||
clientConfigFile.close();
|
||||
|
||||
LOG_INFO("[CC-Client] config updated. restart.");
|
||||
LOG_WARN("[CC-Client] Config updated. -> restart");
|
||||
App::restart();
|
||||
} else {
|
||||
LOG_ERR("[CC-Client] not able to store client config to file %s.", m_self->m_options->configFile());
|
||||
LOG_ERR("[CC-Client] Not able to store client config to file %s.", m_self->m_options->configFile());
|
||||
}
|
||||
} else{
|
||||
LOG_ERR("[CC-Client] not able to store client config. received client config is broken!");
|
||||
LOG_ERR("[CC-Client] Not able to store client config. received client config is broken!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -78,7 +78,6 @@ CCServer::~CCServer()
|
|||
uv_tty_reset_mode();
|
||||
|
||||
delete m_httpd;
|
||||
delete m_console;
|
||||
}
|
||||
|
||||
int CCServer::start()
|
||||
|
|
|
@ -58,6 +58,7 @@ private:
|
|||
Httpd* m_httpd;
|
||||
Options* m_options;
|
||||
uv_signal_t m_signal;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -118,9 +118,9 @@ uint64_t ClientStatus::getSharesTotal() const
|
|||
return m_sharesTotal;
|
||||
}
|
||||
|
||||
void ClientStatus::setSharesTotal(uint64_t sharedTotal)
|
||||
void ClientStatus::setSharesTotal(uint64_t sharesTotal)
|
||||
{
|
||||
m_sharesTotal = sharedTotal;
|
||||
m_sharesTotal = sharesTotal;
|
||||
}
|
||||
|
||||
uint64_t ClientStatus::getHashesTotal() const
|
||||
|
@ -198,8 +198,8 @@ bool ClientStatus::parseFromJson(const rapidjson::Document& document)
|
|||
m_avgTime = clientStatus["avg_time"].GetUint();
|
||||
}
|
||||
|
||||
if (clientStatus.HasMember("shared_good")) {
|
||||
m_sharesGood = clientStatus["shared_good"].GetUint64();
|
||||
if (clientStatus.HasMember("shares_good")) {
|
||||
m_sharesGood = clientStatus["shares_good"].GetUint64();
|
||||
}
|
||||
|
||||
if (clientStatus.HasMember("shares_total")) {
|
||||
|
@ -235,7 +235,7 @@ rapidjson::Value ClientStatus::toJson(rapidjson::MemoryPoolAllocator<rapidjson::
|
|||
clientStatus.AddMember("hashrate_highest", m_hashrateHighest, allocator);
|
||||
clientStatus.AddMember("avg_time", m_avgTime, allocator);
|
||||
|
||||
clientStatus.AddMember("shared_good", m_sharesGood, allocator);
|
||||
clientStatus.AddMember("shares_good", m_sharesGood, allocator);
|
||||
clientStatus.AddMember("shares_total", m_sharesTotal, allocator);
|
||||
clientStatus.AddMember("hashes_total", m_hashesTotal, allocator);
|
||||
|
||||
|
|
|
@ -55,6 +55,7 @@ Network::Network(const Options *options) :
|
|||
Workers::setListener(this);
|
||||
|
||||
const std::vector<Url*> &pools = options->pools();
|
||||
|
||||
if (pools.size() > 1) {
|
||||
m_strategy = new FailoverStrategy(pools, Platform::userAgent(), this);
|
||||
}
|
||||
|
@ -75,13 +76,6 @@ Network::Network(const Options *options) :
|
|||
|
||||
Network::~Network()
|
||||
{
|
||||
uv_timer_stop(&m_timer);
|
||||
|
||||
if (m_donate) {
|
||||
delete m_donate;
|
||||
}
|
||||
|
||||
delete m_strategy;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
|
||||
#include <cmath>
|
||||
#include <cc/CCClient.h>
|
||||
#include <thread>
|
||||
|
||||
|
||||
#include "api/Api.h"
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2016-2017 XMRig <support@xmrig.com>
|
||||
* Copyright 2017- BenDr0id <ben@graef.in>
|
||||
*
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
|
@ -23,15 +24,10 @@
|
|||
|
||||
#include "App.h"
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
for (;;) {
|
||||
App* app = new App(argc, argv);
|
||||
int res = app->start();
|
||||
delete app;
|
||||
App* app = new App(argc, argv);
|
||||
int res = app->start();
|
||||
delete app;
|
||||
|
||||
if (res != ERESTART) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "CCServer.h"
|
||||
#include "cc/CCServer.h"
|
||||
|
||||
|
||||
int main(int argc, char** argv) {
|
Loading…
Add table
Add a link
Reference in a new issue