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)
|
add_definitions(/DXMRIG_NO_API)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (WITH_CC_SERVER AND MHD_FOUND)
|
if (WITH_CC_SERVER)
|
||||||
|
find_package(MHD)
|
||||||
|
|
||||||
|
if (MHD_FOUND)
|
||||||
include_directories(${MHD_INCLUDE_DIRS})
|
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
|
set(CC_SERVER_SOURCES
|
||||||
|
src/server/ControlCommand.cpp
|
||||||
src/server/ClientStatus.cpp
|
src/server/ClientStatus.cpp
|
||||||
src/server/xmrigCC.cpp
|
src/server/xmrigCC.cpp
|
||||||
src/server/CCServer.cpp
|
src/server/CCServer.cpp
|
||||||
|
@ -249,12 +264,14 @@ if (WITH_CC_SERVER AND MHD_FOUND)
|
||||||
src/server/Httpd.cpp)
|
src/server/Httpd.cpp)
|
||||||
|
|
||||||
set(CC_SERVER_HEADERS
|
set(CC_SERVER_HEADERS
|
||||||
|
src/server/ControlCommand.h
|
||||||
src/server/ClientStatus.h
|
src/server/ClientStatus.h
|
||||||
src/server/CCServer.h
|
src/server/CCServer.h
|
||||||
src/server/Service.h
|
src/server/Service.h
|
||||||
src/server/version.h
|
src/server/version.h
|
||||||
src/server/Httpd.h)
|
src/server/Httpd.h)
|
||||||
|
else()
|
||||||
|
add_definitions(/DXMRIG_NO_CC_SERVER)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include_directories(src)
|
include_directories(src)
|
||||||
|
@ -262,9 +279,9 @@ include_directories(src/3rdparty)
|
||||||
include_directories(${UV_INCLUDE_DIR})
|
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})
|
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})
|
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})
|
target_link_libraries(xmrigCC ${UV_LIBRARIES} ${MHD_LIBRARY} ${EXTRA_LIBS} ${CPUID_LIB})
|
||||||
endif()
|
endif()
|
|
@ -28,113 +28,113 @@
|
||||||
#include "server/ClientStatus.h"
|
#include "server/ClientStatus.h"
|
||||||
|
|
||||||
ClientStatus::ClientStatus()
|
ClientStatus::ClientStatus()
|
||||||
: hashrateShort(0), hashrateMedium(0), hashrateLong(0), sharesGood(0), sharedTotal(0), hashesTotal(0),
|
: m_hashrateShort(0), m_hashrateMedium(0), m_hashrateLong(0), m_sharesGood(0), m_sharedTotal(0), m_hashesTotal(0),
|
||||||
lastStatusUpdate(0)
|
m_lastStatusUpdate(0)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string ClientStatus::getMiner() const
|
const std::string ClientStatus::getMiner() const
|
||||||
{
|
{
|
||||||
return miner;
|
return m_miner;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientStatus::setMiner(const std::string &miner)
|
void ClientStatus::setMiner(const std::string &miner)
|
||||||
{
|
{
|
||||||
ClientStatus::miner = miner;
|
m_miner = miner;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string ClientStatus::getCurrentPool() const
|
const std::string ClientStatus::getCurrentPool() const
|
||||||
{
|
{
|
||||||
return currentPool;
|
return m_currentPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientStatus::setCurrentPool(const std::string ¤tPool)
|
void ClientStatus::setCurrentPool(const std::string ¤tPool)
|
||||||
{
|
{
|
||||||
ClientStatus::currentPool = currentPool;
|
m_currentPool = currentPool;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string ClientStatus::getCurrentStatus() const
|
const std::string ClientStatus::getCurrentStatus() const
|
||||||
{
|
{
|
||||||
return currentStatus;
|
return m_currentStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientStatus::setCurrentStatus(const std::string ¤tStatus)
|
void ClientStatus::setCurrentStatus(const std::string ¤tStatus)
|
||||||
{
|
{
|
||||||
ClientStatus::currentStatus = currentStatus;
|
m_currentStatus = currentStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
double ClientStatus::getHashrateShort() const
|
double ClientStatus::getHashrateShort() const
|
||||||
{
|
{
|
||||||
return hashrateShort;
|
return m_hashrateShort;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientStatus::setHashrateShort(double hashrateShort)
|
void ClientStatus::setHashrateShort(double hashrateShort)
|
||||||
{
|
{
|
||||||
ClientStatus::hashrateShort = hashrateShort;
|
m_hashrateShort = hashrateShort;
|
||||||
}
|
}
|
||||||
|
|
||||||
double ClientStatus::getHashrateMedium() const
|
double ClientStatus::getHashrateMedium() const
|
||||||
{
|
{
|
||||||
return hashrateMedium;
|
return m_hashrateMedium;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientStatus::setHashrateMedium(double hashrateMedium)
|
void ClientStatus::setHashrateMedium(double hashrateMedium)
|
||||||
{
|
{
|
||||||
ClientStatus::hashrateMedium = hashrateMedium;
|
m_hashrateMedium = hashrateMedium;
|
||||||
}
|
}
|
||||||
|
|
||||||
double ClientStatus::getHashrateLong() const
|
double ClientStatus::getHashrateLong() const
|
||||||
{
|
{
|
||||||
return hashrateLong;
|
return m_hashrateLong;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientStatus::setHashrateLong(double hashrateLong)
|
void ClientStatus::setHashrateLong(double hashrateLong)
|
||||||
{
|
{
|
||||||
ClientStatus::hashrateLong = hashrateLong;
|
m_hashrateLong = hashrateLong;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t ClientStatus::getSharesGood() const
|
uint64_t ClientStatus::getSharesGood() const
|
||||||
{
|
{
|
||||||
return sharesGood;
|
return m_sharesGood;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientStatus::setSharesGood(uint64_t sharesGood)
|
void ClientStatus::setSharesGood(uint64_t sharesGood)
|
||||||
{
|
{
|
||||||
ClientStatus::sharesGood = sharesGood;
|
m_sharesGood = sharesGood;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t ClientStatus::getSharedTotal() const
|
uint64_t ClientStatus::getSharedTotal() const
|
||||||
{
|
{
|
||||||
return sharedTotal;
|
return m_sharedTotal;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientStatus::setSharedTotal(uint64_t sharedTotal)
|
void ClientStatus::setSharedTotal(uint64_t sharedTotal)
|
||||||
{
|
{
|
||||||
ClientStatus::sharedTotal = sharedTotal;
|
m_sharedTotal = sharedTotal;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t ClientStatus::getHashesTotal() const
|
uint64_t ClientStatus::getHashesTotal() const
|
||||||
{
|
{
|
||||||
return hashesTotal;
|
return m_hashesTotal;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientStatus::setHashesTotal(uint64_t hashesTotal)
|
void ClientStatus::setHashesTotal(uint64_t hashesTotal)
|
||||||
{
|
{
|
||||||
ClientStatus::hashesTotal = hashesTotal;
|
m_hashesTotal = hashesTotal;
|
||||||
}
|
}
|
||||||
|
|
||||||
const uint32_t ClientStatus::getLastStatusUpdate() const
|
const uint32_t ClientStatus::getLastStatusUpdate() const
|
||||||
{
|
{
|
||||||
return lastStatusUpdate;
|
return m_lastStatusUpdate;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ClientStatus::setLastStatusUpdate(uint32_t 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/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __CLIENTSTATUS_H__
|
#ifndef __CLIENT_STATUS_H__
|
||||||
#define __CLIENTSTATUS_H__
|
#define __CLIENT_STATUS_H__
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "rapidjson/document.h"
|
#include "rapidjson/document.h"
|
||||||
|
@ -65,21 +65,21 @@ public:
|
||||||
void setLastStatusUpdate(uint32_t lastStatusUpdate);
|
void setLastStatusUpdate(uint32_t lastStatusUpdate);
|
||||||
|
|
||||||
std::string toJson();
|
std::string toJson();
|
||||||
void parseFromJson(const rapidjson::Document &doc);
|
void parseFromJson(const rapidjson::Document &document);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string miner;
|
std::string m_miner;
|
||||||
std::string currentPool;
|
std::string m_currentPool;
|
||||||
std::string currentStatus;
|
std::string m_currentStatus;
|
||||||
|
|
||||||
double hashrateShort;
|
double m_hashrateShort;
|
||||||
double hashrateMedium;
|
double m_hashrateMedium;
|
||||||
double hashrateLong;
|
double m_hashrateLong;
|
||||||
|
|
||||||
uint64_t sharesGood;
|
uint64_t m_sharesGood;
|
||||||
uint64_t sharedTotal;
|
uint64_t m_sharedTotal;
|
||||||
uint64_t hashesTotal;
|
uint64_t m_hashesTotal;
|
||||||
uint32_t lastStatusUpdate;
|
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;
|
return MHD_NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Httpd::handleGET(struct MHD_Connection *connection, const char *url)
|
int Httpd::handleGET(struct MHD_Connection *connection, const char *urlPtr)
|
||||||
{LOG_INFO("HANDLE GET REQUEST");
|
{
|
||||||
|
LOG_INFO("HANDLE GET REQUEST");
|
||||||
|
|
||||||
std::string resp;
|
std::string resp;
|
||||||
|
std::string url(urlPtr, strlen(urlPtr));
|
||||||
|
|
||||||
unsigned status = Service::get(url, resp);
|
unsigned status = Service::get(url, resp);
|
||||||
|
|
||||||
MHD_Response *rsp = nullptr;
|
MHD_Response *rsp = nullptr;
|
||||||
|
@ -195,7 +198,7 @@ int Httpd::handleGET(struct MHD_Connection *connection, const char *url)
|
||||||
return sendJSONResponse(connection, status, rsp);
|
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)
|
size_t *upload_data_size, void **con_cls)
|
||||||
{
|
{
|
||||||
LOG_INFO("HANDLE POST REQUEST");
|
LOG_INFO("HANDLE POST REQUEST");
|
||||||
|
@ -212,6 +215,8 @@ int Httpd::handlePOST(struct MHD_Connection *connection, const char* url, const
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
std::string resp;
|
std::string resp;
|
||||||
|
std::string url(urlPtr, strlen(urlPtr));
|
||||||
|
|
||||||
unsigned status = Service::post(url, cc->data.str(), resp);
|
unsigned status = Service::post(url, cc->data.str(), resp);
|
||||||
|
|
||||||
MHD_Response *rsp = nullptr;
|
MHD_Response *rsp = nullptr;
|
||||||
|
|
|
@ -26,7 +26,6 @@
|
||||||
#include "server/Service.h"
|
#include "server/Service.h"
|
||||||
#include "log/Log.h"
|
#include "log/Log.h"
|
||||||
|
|
||||||
char Service::m_buf[4096];
|
|
||||||
uv_mutex_t Service::m_mutex;
|
uv_mutex_t Service::m_mutex;
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,98 +39,44 @@ bool Service::start()
|
||||||
|
|
||||||
void Service::release()
|
void Service::release()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
unsigned Service::get(const char *url, std::string &resp)
|
|
||||||
{
|
|
||||||
//if (!m_state) {
|
|
||||||
// *size = 0;
|
|
||||||
// return nullptr;
|
|
||||||
//}
|
|
||||||
|
|
||||||
uv_mutex_lock(&m_mutex);
|
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);
|
LOG_INFO("GET(%s)", url.c_str());
|
||||||
if (*size) {
|
|
||||||
memcpy(m_buf, buf, *size);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
*status = 500;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
uv_mutex_unlock(&m_mutex);
|
uv_mutex_unlock(&m_mutex);
|
||||||
|
|
||||||
return 200;
|
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);
|
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;
|
rapidjson::Document document;
|
||||||
if (!document.Parse(data.c_str()).HasParseError()) {
|
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 {
|
} else {
|
||||||
LOG_ERR("Parse Error Occured: %d", document.GetParseError());
|
LOG_ERR("Parse Error Occured: %d", document.GetParseError());
|
||||||
return MHD_HTTP_BAD_REQUEST;
|
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);
|
uv_mutex_unlock(&m_mutex);
|
||||||
|
|
||||||
return 200;
|
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 <string>
|
||||||
#include <uv.h>
|
#include <uv.h>
|
||||||
#include <microhttpd.h>
|
#include <microhttpd.h>
|
||||||
|
#include <map>
|
||||||
|
#include "ClientStatus.h"
|
||||||
//class ServiceState;
|
#include "ControlCommand.h"
|
||||||
//class Hashrate;
|
|
||||||
//class NetworkState;
|
|
||||||
|
|
||||||
|
|
||||||
class Service
|
class Service
|
||||||
{
|
{
|
||||||
|
@ -41,14 +38,13 @@ public:
|
||||||
static bool start();
|
static bool start();
|
||||||
static void release();
|
static void release();
|
||||||
|
|
||||||
static unsigned get(const char *url, std::string &resp);
|
static unsigned get(const std::string &url, std::string &resp);
|
||||||
static unsigned post(const char *url, const std::string &data, std::string &resp);
|
static unsigned post(const std::string &url, const std::string &data, std::string &resp);
|
||||||
// static void tick(const Hashrate *hashrate);
|
|
||||||
// static void tick(const NetworkState &results);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//static ServiceState *m_state;
|
static std::map<std::string, ClientStatus> m_clientStatus;
|
||||||
static char m_buf[4096];
|
static std::map<std::string, ControlCommand> m_clientCommand;
|
||||||
|
|
||||||
static uv_mutex_t m_mutex;
|
static uv_mutex_t m_mutex;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue