Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
xmrig committed Dec 21, 2019
2 parents bae9edc + e1d82fe commit 2e14958
Show file tree
Hide file tree
Showing 46 changed files with 392 additions and 355 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# v5.4.0
- [#1434](https://github.com/xmrig/xmrig/pull/1434) Added RandomSFX (`rx/sfx`) algorithm for Safex Cash.
- [#1445](https://github.com/xmrig/xmrig/pull/1445) Added RandomV (`rx/v`) algorithm for *new* MoneroV.
- [#367](https://github.com/xmrig/xmrig-proxy/issues/367) Added "cert-key" alias, fixed --tls-cert-key command line option.

# v5.0.1
- **Fixed memory leak.**
- Fixed crash if no valid configuration found.
Expand Down
20 changes: 13 additions & 7 deletions src/Summary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*/


#include <stdio.h>
#include <cstdio>
#include <uv.h>


Expand All @@ -35,18 +35,21 @@
#include "version.h"


namespace xmrig {


static void print_mode(xmrig::Controller *controller)
{
xmrig::Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") MAGENTA_BOLD("%s"), "MODE", controller->config()->modeName());
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("%-13s") MAGENTA_BOLD("%s"), "MODE", controller->config()->modeName());
}


static void print_bind(xmrig::Controller *controller)
{
const xmrig::BindHosts &bind = controller->config()->bind();
const BindHosts &bind = controller->config()->bind();

for (size_t i = 0; i < bind.size(); ++i) {
xmrig::Log::print(GREEN_BOLD(" * ") WHITE_BOLD("BIND #%-7zu") CYAN("%s%s%s:") "\x1B[1;%dm%d\x1B[0m",
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("BIND #%-7zu") CYAN("%s%s%s:") "\x1B[1;%dm%d\x1B[0m",
i + 1,
bind[i].isIPv6() ? "[" : "",
bind[i].host(),
Expand All @@ -59,18 +62,21 @@ static void print_bind(xmrig::Controller *controller)

static void print_commands(xmrig::Controller *)
{
if (xmrig::Log::colors) {
xmrig::Log::print(GREEN_BOLD(" * ") WHITE_BOLD("COMMANDS ") MAGENTA_BOLD("h") WHITE_BOLD("ashrate, ")
if (Log::isColors()) {
Log::print(GREEN_BOLD(" * ") WHITE_BOLD("COMMANDS ") MAGENTA_BOLD("h") WHITE_BOLD("ashrate, ")
MAGENTA_BOLD("c") WHITE_BOLD("onnections, ")
MAGENTA_BOLD("v") WHITE_BOLD("erbose, ")
MAGENTA_BOLD("w") WHITE_BOLD("orkers"));
}
else {
xmrig::Log::print(" * COMMANDS 'h' hashrate, 'c' connections, 'v' verbose, 'w' workers");
Log::print(" * COMMANDS 'h' hashrate, 'c' connections, 'v' verbose, 'w' workers");
}
}


} // namespace xmrig


void Summary::print(xmrig::Controller *controller)
{
controller->config()->printVersions();
Expand Down
52 changes: 9 additions & 43 deletions src/api/v1/ApiRouter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <cmath>
#include <string.h>
#include <uv.h>
#include <thread>


#include "base/api/interfaces/IApiRequest.h"
#include "api/v1/ApiRouter.h"
#include "base/api/interfaces/IApiRequest.h"
#include "base/kernel/Platform.h"
#include "base/tools/Buffer.h"
#include "core/config/Config.h"
Expand All @@ -41,6 +35,11 @@
#include "version.h"


#include <cmath>
#include <cstring>
#include <uv.h>


static inline double normalize(double d)
{
if (!std::isnormal(d)) {
Expand All @@ -57,9 +56,7 @@ xmrig::ApiRouter::ApiRouter(Base *base) :
}


xmrig::ApiRouter::~ApiRouter()
{
}
xmrig::ApiRouter::~ApiRouter() = default;


void xmrig::ApiRouter::onRequest(IApiRequest &request)
Expand All @@ -69,7 +66,6 @@ void xmrig::ApiRouter::onRequest(IApiRequest &request)
request.accept();
getMiner(request.reply(), request.doc());
getHashrate(request.reply(), request.doc());
getResourcesSummary(request.reply(), request.doc());
getMinersSummary(request.reply(), request.doc());
getResults(request.reply(), request.doc());
}
Expand Down Expand Up @@ -196,36 +192,6 @@ void xmrig::ApiRouter::getMinersSummary(rapidjson::Value &reply, rapidjson::Docu
}



void xmrig::ApiRouter::getResourcesSummary(rapidjson::Value &reply, rapidjson::Document &doc) const
{
using namespace rapidjson;
auto &allocator = doc.GetAllocator();

size_t rss = 0;
uv_resident_set_memory(&rss);

Value resources(kObjectType);
Value memory(kObjectType);
Value load_average(kArrayType);

memory.AddMember("total", uv_get_total_memory(), allocator);
memory.AddMember("resident_set_memory", static_cast<uint64_t>(rss), allocator);

double loadavg[3] = { 1.0 };
uv_loadavg(loadavg);
load_average.PushBack(loadavg[0], allocator);
load_average.PushBack(loadavg[1], allocator);
load_average.PushBack(loadavg[2], allocator);

resources.AddMember("memory", memory, allocator);
resources.AddMember("load_average", load_average, allocator);
resources.AddMember("hardware_concurrency", std::thread::hardware_concurrency(), allocator);

reply.AddMember("resources", resources, allocator);
}


void xmrig::ApiRouter::getResults(rapidjson::Value &reply, rapidjson::Document &doc) const
{
auto &allocator = doc.GetAllocator();
Expand All @@ -243,8 +209,8 @@ void xmrig::ApiRouter::getResults(rapidjson::Value &reply, rapidjson::Document &
results.AddMember("hashes_donate", stats.donateHashes, allocator);

rapidjson::Value best(rapidjson::kArrayType);
for (size_t i = 0; i < stats.topDiff.size(); ++i) {
best.PushBack(stats.topDiff[i], allocator);
for (uint64_t i : stats.topDiff) {
best.PushBack(i, allocator);
}

results.AddMember("best", best, allocator);
Expand Down
4 changes: 3 additions & 1 deletion src/api/v1/ApiRouter.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@


#include "base/api/interfaces/IApiListener.h"
#include "base/tools/Object.h"
#include "proxy/StatsData.h"
#include "rapidjson/fwd.h"

Expand All @@ -40,6 +41,8 @@ class Base;
class ApiRouter : public xmrig::IApiListener
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(ApiRouter)

ApiRouter(Base *base);
~ApiRouter() override;

Expand All @@ -52,7 +55,6 @@ class ApiRouter : public xmrig::IApiListener
void getMiner(rapidjson::Value &reply, rapidjson::Document &doc) const;
void getMiners(rapidjson::Value &reply, rapidjson::Document &doc) const;
void getMinersSummary(rapidjson::Value &reply, rapidjson::Document &doc) const;
void getResourcesSummary(rapidjson::Value &reply, rapidjson::Document &doc) const;
void getResults(rapidjson::Value &reply, rapidjson::Document &doc) const;
void getWorkers(rapidjson::Value &reply, rapidjson::Document &doc) const;

Expand Down
68 changes: 56 additions & 12 deletions src/base/api/Api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,11 @@
#endif


#include "3rdparty/http-parser/http_parser.h"
#include "base/api/Api.h"
#include "3rdparty/http-parser/http_parser.h"
#include "base/api/interfaces/IApiListener.h"
#include "base/api/requests/HttpApiRequest.h"
#include "base/io/json/Json.h"
#include "base/kernel/Base.h"
#include "base/tools/Buffer.h"
#include "base/tools/Chrono.h"
Expand All @@ -49,12 +50,49 @@
#endif


#include <thread>


namespace xmrig {


static rapidjson::Value getResources(rapidjson::Document &doc)
{
using namespace rapidjson;
auto &allocator = doc.GetAllocator();

size_t rss = 0;
uv_resident_set_memory(&rss);

Value out(kObjectType);
Value memory(kObjectType);
Value load_average(kArrayType);

memory.AddMember("free", uv_get_free_memory(), allocator);
memory.AddMember("total", uv_get_total_memory(), allocator);
memory.AddMember("resident_set_memory", static_cast<uint64_t>(rss), allocator);

double loadavg[3] = { 0.0 };
uv_loadavg(loadavg);

for (double value : loadavg) {
load_average.PushBack(Json::normalize(value, true), allocator);
}

out.AddMember("memory", memory, allocator);
out.AddMember("load_average", load_average, allocator);
out.AddMember("hardware_concurrency", std::thread::hardware_concurrency(), allocator);

return out;
}


} // namespace xmrig


xmrig::Api::Api(Base *base) :
m_base(base),
m_id(),
m_workerId(),
m_timestamp(Chrono::currentMSecsSinceEpoch()),
m_httpd(nullptr)
m_timestamp(Chrono::currentMSecsSinceEpoch())
{
base->addListener(this);

Expand Down Expand Up @@ -117,10 +155,13 @@ void xmrig::Api::exec(IApiRequest &request)
auto &allocator = request.doc().GetAllocator();

request.accept();
request.reply().AddMember("id", StringRef(m_id), allocator);
request.reply().AddMember("worker_id", StringRef(m_workerId), allocator);
request.reply().AddMember("uptime", (Chrono::currentMSecsSinceEpoch() - m_timestamp) / 1000, allocator);
request.reply().AddMember("restricted", request.isRestricted(), allocator);

auto &reply = request.reply();
reply.AddMember("id", StringRef(m_id), allocator);
reply.AddMember("worker_id", StringRef(m_workerId), allocator);
reply.AddMember("uptime", (Chrono::currentMSecsSinceEpoch() - m_timestamp) / 1000, allocator);
reply.AddMember("restricted", request.isRestricted(), allocator);
reply.AddMember("resources", getResources(request.doc()), allocator);

Value features(kArrayType);
# ifdef XMRIG_FEATURE_API
Expand All @@ -144,7 +185,10 @@ void xmrig::Api::exec(IApiRequest &request)
# ifdef XMRIG_FEATURE_OPENCL
features.PushBack("opencl", allocator);
# endif
request.reply().AddMember("features", features, allocator);
# ifdef XMRIG_FEATURE_CUDA
features.PushBack("cuda", allocator);
# endif
reply.AddMember("features", features, allocator);
}

for (IApiListener *listener : m_listeners) {
Expand Down Expand Up @@ -180,9 +224,9 @@ void xmrig::Api::genId(const String &id)
uint8_t hash[200];
const size_t addrSize = sizeof(interfaces[i].phys_addr);
const size_t inSize = (sizeof(APP_KIND) - 1) + addrSize + sizeof(uint16_t);
const uint16_t port = static_cast<uint16_t>(m_base->config()->http().port());
const auto port = static_cast<uint16_t>(m_base->config()->http().port());

uint8_t *input = new uint8_t[inSize]();
auto*input = new uint8_t[inSize]();
memcpy(input, &port, sizeof(uint16_t));
memcpy(input + sizeof(uint16_t), interfaces[i].phys_addr, addrSize);
memcpy(input + sizeof(uint16_t) + addrSize, APP_KIND, (sizeof(APP_KIND) - 1));
Expand Down
6 changes: 3 additions & 3 deletions src/base/api/Api.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,10 @@ class Api : public IBaseListener
void genWorkerId(const String &id);

Base *m_base;
char m_id[32];
char m_workerId[128];
char m_id[32]{};
char m_workerId[128]{};
const uint64_t m_timestamp;
Httpd *m_httpd;
Httpd *m_httpd = nullptr;
std::vector<IApiListener *> m_listeners;
};

Expand Down
6 changes: 2 additions & 4 deletions src/base/api/Httpd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
*/


#include "base/api/Httpd.h"
#include "3rdparty/http-parser/http_parser.h"
#include "base/api/Api.h"
#include "base/api/Httpd.h"
#include "base/io/log/Log.h"
#include "base/net/http/HttpApiResponse.h"
#include "base/net/http/HttpData.h"
Expand Down Expand Up @@ -58,9 +58,7 @@ xmrig::Httpd::Httpd(Base *base) :
}


xmrig::Httpd::~Httpd()
{
}
xmrig::Httpd::~Httpd() = default;


bool xmrig::Httpd::start()
Expand Down
5 changes: 4 additions & 1 deletion src/base/api/Httpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
#define XMRIG_HTTPD_H


#include <stdint.h>
#include <cstdint>


#include "base/kernel/interfaces/IBaseListener.h"
#include "base/kernel/interfaces/IHttpListener.h"
#include "base/tools/Object.h"


namespace xmrig {
Expand All @@ -44,6 +45,8 @@ class TcpServer;
class Httpd : public IBaseListener, public IHttpListener
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(Httpd)

Httpd(Base *base);
~Httpd() override;

Expand Down
4 changes: 1 addition & 3 deletions src/base/api/requests/ApiRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,4 @@ xmrig::ApiRequest::ApiRequest(Source source, bool restricted) :
}


xmrig::ApiRequest::~ApiRequest()
{
}
xmrig::ApiRequest::~ApiRequest() = default;
7 changes: 5 additions & 2 deletions src/base/api/requests/ApiRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

#include "base/api/interfaces/IApiRequest.h"
#include "base/tools/String.h"
#include "base/tools/Object.h"


namespace xmrig {
Expand All @@ -37,6 +38,8 @@ namespace xmrig {
class ApiRequest : public IApiRequest
{
public:
XMRIG_DISABLE_COPY_MOVE_DEFAULT(ApiRequest)

ApiRequest(Source source, bool restricted);
~ApiRequest() override;

Expand All @@ -63,8 +66,8 @@ class ApiRequest : public IApiRequest
String m_rpcMethod;

private:
bool m_restricted;
Source m_source;
const bool m_restricted;
const Source m_source;
};


Expand Down
Loading

0 comments on commit 2e14958

Please sign in to comment.