Cleanup CMakeLists, Added ControlCommand
This commit is contained in:
parent
4f606644fe
commit
003e17d18f
8 changed files with 254 additions and 140 deletions
|
@ -237,10 +237,25 @@ else()
|
|||
add_definitions(/DXMRIG_NO_API)
|
||||
endif()
|
||||
|
||||
if (WITH_CC_SERVER AND MHD_FOUND)
|
||||
if (WITH_CC_SERVER)
|
||||
find_package(MHD)
|
||||
|
||||
if (MHD_FOUND)
|
||||
include_directories(${MHD_INCLUDE_DIRS})
|
||||
else()
|
||||
message(FATAL_ERROR "microhttpd NOT found: use `-DWITH_CC_SERVER=OFF` to build without CC Server support")
|
||||
endif()
|
||||
|
||||
find_package(CURL)
|
||||
|
||||
if (CURL_FOUND)
|
||||
include_directories(${CURL_INCLUDE_DIRS})
|
||||
else()
|
||||
message(FATAL_ERROR "microhttpd NOT found: use `-DWITH_CC_SERVER=OFF` to build without CC Server support")
|
||||
endif()
|
||||
|
||||
set(CC_SERVER_SOURCES
|
||||
src/server/ControlCommand.cpp
|
||||
src/server/ClientStatus.cpp
|
||||
src/server/xmrigCC.cpp
|
||||
src/server/CCServer.cpp
|
||||
|
@ -249,12 +264,14 @@ if (WITH_CC_SERVER AND MHD_FOUND)
|
|||
src/server/Httpd.cpp)
|
||||
|
||||
set(CC_SERVER_HEADERS
|
||||
src/server/ControlCommand.h
|
||||
src/server/ClientStatus.h
|
||||
src/server/CCServer.h
|
||||
src/server/Service.h
|
||||
src/server/version.h
|
||||
src/server/Httpd.h)
|
||||
|
||||
else()
|
||||
add_definitions(/DXMRIG_NO_CC_SERVER)
|
||||
endif()
|
||||
|
||||
include_directories(src)
|
||||
|
@ -262,9 +279,9 @@ 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})
|
||||
target_link_libraries(xmrig ${UV_LIBRARIES} ${MHD_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB})
|
||||
target_link_libraries(xmrig ${UV_LIBRARIES} ${MHD_LIBRARY} ${CURL_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB})
|
||||
|
||||
if (WITH_CC_SERVER AND MHD_FOUND)
|
||||
if (WITH_CC_SERVER AND MHD_FOUND AND CURL_FOUND)
|
||||
add_executable(xmrigCC ${HEADERS_COMMON} ${SOURCES_COMMON} ${SOURCES_OS} ${SOURCES_CPUID} ${HEADERS_CC_SERVER} ${CC_SERVER_SOURCES} ${SOURCES_SYSLOG})
|
||||
target_link_libraries(xmrigCC ${UV_LIBRARIES} ${MHD_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB})
|
||||
endif()
|
|
@ -28,113 +28,113 @@
|
|||
#include "server/ClientStatus.h"
|
||||
|
||||
ClientStatus::ClientStatus()
|
||||
: hashrateShort(0), hashrateMedium(0), hashrateLong(0), sharesGood(0), sharedTotal(0), hashesTotal(0),
|
||||
lastStatusUpdate(0)
|
||||
: m_hashrateShort(0), m_hashrateMedium(0), m_hashrateLong(0), m_sharesGood(0), m_sharedTotal(0), m_hashesTotal(0),
|
||||
m_lastStatusUpdate(0)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
const std::string ClientStatus::getMiner() const
|
||||
{
|
||||
return miner;
|
||||
return m_miner;
|
||||
}
|
||||
|
||||
void ClientStatus::setMiner(const std::string &miner)
|
||||
{
|
||||
ClientStatus::miner = miner;
|
||||
m_miner = miner;
|
||||
}
|
||||
|
||||
const std::string ClientStatus::getCurrentPool() const
|
||||
{
|
||||
return currentPool;
|
||||
return m_currentPool;
|
||||
}
|
||||
|
||||
void ClientStatus::setCurrentPool(const std::string ¤tPool)
|
||||
{
|
||||
ClientStatus::currentPool = currentPool;
|
||||
m_currentPool = currentPool;
|
||||
}
|
||||
|
||||
const std::string ClientStatus::getCurrentStatus() const
|
||||
{
|
||||
return currentStatus;
|
||||
return m_currentStatus;
|
||||
}
|
||||
|
||||
void ClientStatus::setCurrentStatus(const std::string ¤tStatus)
|
||||
{
|
||||
ClientStatus::currentStatus = currentStatus;
|
||||
m_currentStatus = currentStatus;
|
||||
}
|
||||
|
||||
double ClientStatus::getHashrateShort() const
|
||||
{
|
||||
return hashrateShort;
|
||||
return m_hashrateShort;
|
||||
}
|
||||
|
||||
void ClientStatus::setHashrateShort(double hashrateShort)
|
||||
{
|
||||
ClientStatus::hashrateShort = hashrateShort;
|
||||
m_hashrateShort = hashrateShort;
|
||||
}
|
||||
|
||||
double ClientStatus::getHashrateMedium() const
|
||||
{
|
||||
return hashrateMedium;
|
||||
return m_hashrateMedium;
|
||||
}
|
||||
|
||||
void ClientStatus::setHashrateMedium(double hashrateMedium)
|
||||
{
|
||||
ClientStatus::hashrateMedium = hashrateMedium;
|
||||
m_hashrateMedium = hashrateMedium;
|
||||
}
|
||||
|
||||
double ClientStatus::getHashrateLong() const
|
||||
{
|
||||
return hashrateLong;
|
||||
return m_hashrateLong;
|
||||
}
|
||||
|
||||
void ClientStatus::setHashrateLong(double hashrateLong)
|
||||
{
|
||||
ClientStatus::hashrateLong = hashrateLong;
|
||||
m_hashrateLong = hashrateLong;
|
||||
}
|
||||
|
||||
uint64_t ClientStatus::getSharesGood() const
|
||||
{
|
||||
return sharesGood;
|
||||
return m_sharesGood;
|
||||
}
|
||||
|
||||
void ClientStatus::setSharesGood(uint64_t sharesGood)
|
||||
{
|
||||
ClientStatus::sharesGood = sharesGood;
|
||||
m_sharesGood = sharesGood;
|
||||
}
|
||||
|
||||
uint64_t ClientStatus::getSharedTotal() const
|
||||
{
|
||||
return sharedTotal;
|
||||
return m_sharedTotal;
|
||||
}
|
||||
|
||||
void ClientStatus::setSharedTotal(uint64_t sharedTotal)
|
||||
{
|
||||
ClientStatus::sharedTotal = sharedTotal;
|
||||
m_sharedTotal = sharedTotal;
|
||||
}
|
||||
|
||||
uint64_t ClientStatus::getHashesTotal() const
|
||||
{
|
||||
return hashesTotal;
|
||||
return m_hashesTotal;
|
||||
}
|
||||
|
||||
void ClientStatus::setHashesTotal(uint64_t hashesTotal)
|
||||
{
|
||||
ClientStatus::hashesTotal = hashesTotal;
|
||||
m_hashesTotal = hashesTotal;
|
||||
}
|
||||
|
||||
const uint32_t ClientStatus::getLastStatusUpdate() const
|
||||
{
|
||||
return lastStatusUpdate;
|
||||
return m_lastStatusUpdate;
|
||||
}
|
||||
|
||||
void ClientStatus::setLastStatusUpdate(uint32_t lastStatusUpdate)
|
||||
{
|
||||
ClientStatus::lastStatusUpdate = lastStatusUpdate;
|
||||
m_lastStatusUpdate = lastStatusUpdate;
|
||||
}
|
||||
|
||||
void ClientStatus::parseFromJson(const rapidjson::Document &doc)
|
||||
void ClientStatus::parseFromJson(const rapidjson::Document &document)
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef __CLIENTSTATUS_H__
|
||||
#define __CLIENTSTATUS_H__
|
||||
#ifndef __CLIENT_STATUS_H__
|
||||
#define __CLIENT_STATUS_H__
|
||||
|
||||
#include <string>
|
||||
#include "rapidjson/document.h"
|
||||
|
@ -65,21 +65,21 @@ public:
|
|||
void setLastStatusUpdate(uint32_t lastStatusUpdate);
|
||||
|
||||
std::string toJson();
|
||||
void parseFromJson(const rapidjson::Document &doc);
|
||||
void parseFromJson(const rapidjson::Document &document);
|
||||
|
||||
private:
|
||||
std::string miner;
|
||||
std::string currentPool;
|
||||
std::string currentStatus;
|
||||
std::string m_miner;
|
||||
std::string m_currentPool;
|
||||
std::string m_currentStatus;
|
||||
|
||||
double hashrateShort;
|
||||
double hashrateMedium;
|
||||
double hashrateLong;
|
||||
double m_hashrateShort;
|
||||
double m_hashrateMedium;
|
||||
double m_hashrateLong;
|
||||
|
||||
uint64_t sharesGood;
|
||||
uint64_t sharedTotal;
|
||||
uint64_t hashesTotal;
|
||||
uint32_t lastStatusUpdate;
|
||||
uint64_t m_sharesGood;
|
||||
uint64_t m_sharedTotal;
|
||||
uint64_t m_hashesTotal;
|
||||
uint32_t m_lastStatusUpdate;
|
||||
};
|
||||
|
||||
#endif /* __CLIENTSTATUS_H__ */
|
||||
#endif /* __CLIENT_STATUS_H__ */
|
||||
|
|
97
src/server/ControlCommand.cpp
Normal file
97
src/server/ControlCommand.cpp
Normal file
|
@ -0,0 +1,97 @@
|
|||
/* 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 2016-2017 XMRig <support@xmrig.com>
|
||||
* Copyright 2017- BenDr0id <ben@graef.in>
|
||||
*
|
||||
*
|
||||
* 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 <cstring>
|
||||
#include <3rdparty/rapidjson/stringbuffer.h>
|
||||
#include <3rdparty/rapidjson/prettywriter.h>
|
||||
|
||||
#include "log/Log.h"
|
||||
#include "server/ControlCommand.h"
|
||||
|
||||
ControlCommand::ControlCommand()
|
||||
: m_command(Command::START)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
ControlCommand::ControlCommand(ControlCommand::Command command)
|
||||
: m_command(command)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool ControlCommand::parseFromJson(const std::string &json)
|
||||
{
|
||||
bool result = false;
|
||||
|
||||
rapidjson::Document document;
|
||||
if (!document.Parse(json.c_str()).HasParseError()) {
|
||||
if (document.HasMember("control_command"))
|
||||
{
|
||||
rapidjson::Value controlCommand = document["control_command"].GetObject();
|
||||
if (controlCommand.HasMember("command")) {
|
||||
m_command = static_cast<Command>(controlCommand["command"].GetUint());
|
||||
result = true;
|
||||
}
|
||||
else {
|
||||
LOG_ERR("Parse Error, JSON does not contain: command");
|
||||
}
|
||||
} else {
|
||||
LOG_ERR("Parse Error, JSON does not contain: control_command");
|
||||
}
|
||||
}
|
||||
else {
|
||||
LOG_ERR("Parse Error Occured: %d", document.GetParseError());
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string ControlCommand::toJson()
|
||||
{
|
||||
rapidjson::Document document;
|
||||
document.SetObject();
|
||||
|
||||
rapidjson::Value controlCommand(rapidjson::kObjectType);
|
||||
controlCommand.AddMember("command", m_command, document.GetAllocator());
|
||||
|
||||
document.AddMember("control_command", controlCommand, document.GetAllocator());
|
||||
|
||||
rapidjson::StringBuffer buffer(0, 1024);
|
||||
rapidjson::PrettyWriter<rapidjson::StringBuffer> writer(buffer);
|
||||
writer.SetMaxDecimalPlaces(10);
|
||||
document.Accept(writer);
|
||||
|
||||
return strdup(buffer.GetString());;
|
||||
}
|
||||
|
||||
void ControlCommand::setCommand(ControlCommand::Command command)
|
||||
{
|
||||
m_command = command;
|
||||
}
|
||||
|
||||
ControlCommand::Command ControlCommand::getCommand() const
|
||||
{
|
||||
return m_command;
|
||||
}
|
54
src/server/ControlCommand.h
Normal file
54
src/server/ControlCommand.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
/* 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 2016-2017 XMRig <support@xmrig.com>
|
||||
* Copyright 2017- BenDr0id <ben@graef.in>
|
||||
*
|
||||
*
|
||||
* 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 __CONTROL_COMMAND_H__
|
||||
#define __CONTROL_COMMAND_H__
|
||||
|
||||
#include <string>
|
||||
#include "rapidjson/document.h"
|
||||
|
||||
class ControlCommand
|
||||
{
|
||||
public:
|
||||
enum Command
|
||||
{
|
||||
START,
|
||||
STOP,
|
||||
UPDATE_CONFIG
|
||||
};
|
||||
|
||||
ControlCommand();
|
||||
explicit ControlCommand(Command command);
|
||||
|
||||
bool parseFromJson(const std::string &json);
|
||||
std::string toJson();
|
||||
|
||||
void setCommand(Command command);
|
||||
Command getCommand() const;
|
||||
|
||||
private:
|
||||
Command m_command;
|
||||
};
|
||||
|
||||
#endif /* __CONTROL_COMMAND_H__ */
|
|
@ -181,10 +181,13 @@ int Httpd::handler(void *cls, MHD_Connection *connection, const char *url, const
|
|||
return MHD_NO;
|
||||
}
|
||||
|
||||
int Httpd::handleGET(struct MHD_Connection *connection, const char *url)
|
||||
{LOG_INFO("HANDLE GET REQUEST");
|
||||
int Httpd::handleGET(struct MHD_Connection *connection, const char *urlPtr)
|
||||
{
|
||||
LOG_INFO("HANDLE GET REQUEST");
|
||||
|
||||
std::string resp;
|
||||
std::string url(urlPtr, strlen(urlPtr));
|
||||
|
||||
unsigned status = Service::get(url, resp);
|
||||
|
||||
MHD_Response *rsp = nullptr;
|
||||
|
@ -195,7 +198,7 @@ int Httpd::handleGET(struct MHD_Connection *connection, const char *url)
|
|||
return sendJSONResponse(connection, status, rsp);
|
||||
}
|
||||
|
||||
int Httpd::handlePOST(struct MHD_Connection *connection, const char* url, const char *upload_data,
|
||||
int Httpd::handlePOST(struct MHD_Connection *connection, const char* urlPtr, const char *upload_data,
|
||||
size_t *upload_data_size, void **con_cls)
|
||||
{
|
||||
LOG_INFO("HANDLE POST REQUEST");
|
||||
|
@ -212,6 +215,8 @@ int Httpd::handlePOST(struct MHD_Connection *connection, const char* url, const
|
|||
} else {
|
||||
|
||||
std::string resp;
|
||||
std::string url(urlPtr, strlen(urlPtr));
|
||||
|
||||
unsigned status = Service::post(url, cc->data.str(), resp);
|
||||
|
||||
MHD_Response *rsp = nullptr;
|
||||
|
|
|
@ -26,7 +26,6 @@
|
|||
#include "server/Service.h"
|
||||
#include "log/Log.h"
|
||||
|
||||
char Service::m_buf[4096];
|
||||
uv_mutex_t Service::m_mutex;
|
||||
|
||||
|
||||
|
@ -40,98 +39,44 @@ bool Service::start()
|
|||
|
||||
void Service::release()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
unsigned Service::get(const char *url, std::string &resp)
|
||||
{
|
||||
//if (!m_state) {
|
||||
// *size = 0;
|
||||
// return nullptr;
|
||||
//}
|
||||
|
||||
uv_mutex_lock(&m_mutex);
|
||||
|
||||
LOG_INFO("GET(%s)", url);
|
||||
m_clientStatus.clear();
|
||||
m_clientCommand.clear();
|
||||
|
||||
/*
|
||||
uv_mutex_unlock(&m_mutex);
|
||||
}
|
||||
|
||||
Handle request here
|
||||
unsigned Service::get(const std::string &url, std::string &resp)
|
||||
{
|
||||
uv_mutex_lock(&m_mutex);
|
||||
|
||||
const char *buf = m_state->get(url, size);
|
||||
if (*size) {
|
||||
memcpy(m_buf, buf, *size);
|
||||
}
|
||||
else {
|
||||
*status = 500;
|
||||
}
|
||||
*/
|
||||
LOG_INFO("GET(%s)", url.c_str());
|
||||
|
||||
uv_mutex_unlock(&m_mutex);
|
||||
|
||||
return 200;
|
||||
}
|
||||
|
||||
unsigned Service::post(const char *url, const std::string &data, std::string &resp)
|
||||
unsigned Service::post(const std::string &url, const std::string &data, std::string &resp)
|
||||
{
|
||||
//if (!m_state) {
|
||||
// *size = 0;
|
||||
// return nullptr;
|
||||
//}
|
||||
|
||||
uv_mutex_lock(&m_mutex);
|
||||
|
||||
LOG_INFO("POST(%s, %s)", url, data.c_str());
|
||||
LOG_INFO("POST(url='%s', data='%s')", url.c_str(), data.c_str());
|
||||
|
||||
rapidjson::Document document;
|
||||
if (!document.Parse(data.c_str()).HasParseError()) {
|
||||
LOG_ERR("Status from miner: %s", document['miner'].GetString());
|
||||
LOG_INFO("Status from miner: %s", document["miner"].GetString());
|
||||
} else {
|
||||
LOG_ERR("Parse Error Occured: %d", document.GetParseError());
|
||||
return MHD_HTTP_BAD_REQUEST;
|
||||
}
|
||||
|
||||
ControlCommand controlCommand;
|
||||
resp = controlCommand.toJson();
|
||||
|
||||
/*
|
||||
|
||||
Handle request here
|
||||
|
||||
const char *buf = m_state->get(url, size);
|
||||
if (*size) {
|
||||
memcpy(m_buf, buf, *size);
|
||||
}
|
||||
else {
|
||||
*status = 500;
|
||||
}
|
||||
*/
|
||||
|
||||
uv_mutex_unlock(&m_mutex);
|
||||
|
||||
return 200;
|
||||
}
|
||||
|
||||
/*
|
||||
void Service::tick(const Hashrate *hashrate)
|
||||
{
|
||||
if (!m_state) {
|
||||
return;
|
||||
}
|
||||
|
||||
uv_mutex_lock(&m_mutex);
|
||||
m_state->tick(hashrate);
|
||||
uv_mutex_unlock(&m_mutex);
|
||||
}
|
||||
|
||||
|
||||
void Service::tick(const NetworkState &network)
|
||||
{
|
||||
if (!m_state) {
|
||||
return;
|
||||
}
|
||||
|
||||
uv_mutex_lock(&m_mutex);
|
||||
m_state->tick(network);
|
||||
uv_mutex_unlock(&m_mutex);
|
||||
}
|
||||
*/
|
||||
|
|
|
@ -28,12 +28,9 @@
|
|||
#include <string>
|
||||
#include <uv.h>
|
||||
#include <microhttpd.h>
|
||||
|
||||
|
||||
//class ServiceState;
|
||||
//class Hashrate;
|
||||
//class NetworkState;
|
||||
|
||||
#include <map>
|
||||
#include "ClientStatus.h"
|
||||
#include "ControlCommand.h"
|
||||
|
||||
class Service
|
||||
{
|
||||
|
@ -41,14 +38,13 @@ public:
|
|||
static bool start();
|
||||
static void release();
|
||||
|
||||
static unsigned get(const char *url, std::string &resp);
|
||||
static unsigned post(const char *url, const std::string &data, std::string &resp);
|
||||
// static void tick(const Hashrate *hashrate);
|
||||
// static void tick(const NetworkState &results);
|
||||
static unsigned get(const std::string &url, std::string &resp);
|
||||
static unsigned post(const std::string &url, const std::string &data, std::string &resp);
|
||||
|
||||
private:
|
||||
//static ServiceState *m_state;
|
||||
static char m_buf[4096];
|
||||
static std::map<std::string, ClientStatus> m_clientStatus;
|
||||
static std::map<std::string, ControlCommand> m_clientCommand;
|
||||
|
||||
static uv_mutex_t m_mutex;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue