From 73fca9114e032a2c0866d6e8f369fc001b323107 Mon Sep 17 00:00:00 2001 From: XMRig Date: Fri, 31 Aug 2018 18:30:51 +0300 Subject: [PATCH] * Fixed API ID collision. --- src/api/ApiRouter.cpp | 18 ++++++++++++------ src/api/ApiRouter.h | 4 ++-- src/core/Config.cpp | 1 + src/core/ConfigLoader_platform.h | 17 ++++++++++------- 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/api/ApiRouter.cpp b/src/api/ApiRouter.cpp index 07e425f18..2c62696ac 100644 --- a/src/api/ApiRouter.cpp +++ b/src/api/ApiRouter.cpp @@ -42,7 +42,6 @@ #include "core/Controller.h" #include "Cpu.h" #include "interfaces/IThread.h" -#include "Mem.h" #include "rapidjson/document.h" #include "rapidjson/prettywriter.h" #include "rapidjson/stringbuffer.h" @@ -67,7 +66,7 @@ ApiRouter::ApiRouter(xmrig::Controller *controller) : memset(m_workerId, 0, sizeof(m_workerId)); setWorkerId(controller->config()->apiWorkerId()); - genId(); + genId(controller->config()->apiId()); } @@ -145,10 +144,15 @@ void ApiRouter::finalize(xmrig::HttpReply &reply, rapidjson::Document &doc) cons } -void ApiRouter::genId() +void ApiRouter::genId(const char *id) { memset(m_id, 0, sizeof(m_id)); + if (id && strlen(id) > 0) { + strncpy(m_id, id, sizeof(m_id) - 1); + return; + } + uv_interface_address_t *interfaces; int count = 0; @@ -160,11 +164,13 @@ void ApiRouter::genId() if (!interfaces[i].is_internal && interfaces[i].address.address4.sin_family == AF_INET) { uint8_t hash[200]; const size_t addrSize = sizeof(interfaces[i].phys_addr); - const size_t inSize = strlen(APP_KIND) + addrSize; + const size_t inSize = strlen(APP_KIND) + addrSize + sizeof(uint16_t); + const uint16_t port = static_cast(m_controller->config()->apiPort()); uint8_t *input = new uint8_t[inSize](); - memcpy(input, interfaces[i].phys_addr, addrSize); - memcpy(input + addrSize, APP_KIND, strlen(APP_KIND)); + memcpy(input, &port, sizeof(uint16_t)); + memcpy(input + sizeof(uint16_t), interfaces[i].phys_addr, addrSize); + memcpy(input + sizeof(uint16_t) + addrSize, APP_KIND, strlen(APP_KIND)); xmrig::keccak(input, inSize, hash); Job::toHex(hash, 8, m_id); diff --git a/src/api/ApiRouter.h b/src/api/ApiRouter.h index 9e32cdaee..b781d5a28 100644 --- a/src/api/ApiRouter.h +++ b/src/api/ApiRouter.h @@ -56,7 +56,7 @@ protected: private: void finalize(xmrig::HttpReply &reply, rapidjson::Document &doc) const; - void genId(); + void genId(const char *id); void getConnection(rapidjson::Document &doc) const; void getHashrate(rapidjson::Document &doc) const; void getIdentify(rapidjson::Document &doc) const; @@ -66,7 +66,7 @@ private: void setWorkerId(const char *id); void updateWorkerId(const char *id, const char *previousId); - char m_id[17]; + char m_id[32]; char m_workerId[128]; NetworkState m_network; xmrig::Controller *m_controller; diff --git a/src/core/Config.cpp b/src/core/Config.cpp index fa6afdb4d..0380c26d2 100644 --- a/src/core/Config.cpp +++ b/src/core/Config.cpp @@ -75,6 +75,7 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const Value api(kObjectType); api.AddMember("port", apiPort(), allocator); api.AddMember("access-token", apiToken() ? Value(StringRef(apiToken())).Move() : Value(kNullType).Move(), allocator); + api.AddMember("id", apiId() ? Value(StringRef(apiId())).Move() : Value(kNullType).Move(), allocator); api.AddMember("worker-id", apiWorkerId() ? Value(StringRef(apiWorkerId())).Move() : Value(kNullType).Move(), allocator); api.AddMember("ipv6", isApiIPv6(), allocator); api.AddMember("restricted", isApiRestricted(), allocator); diff --git a/src/core/ConfigLoader_platform.h b/src/core/ConfigLoader_platform.h index bc6657d1b..987242716 100644 --- a/src/core/ConfigLoader_platform.h +++ b/src/core/ConfigLoader_platform.h @@ -22,8 +22,8 @@ * along with this program. If not, see . */ -#ifndef __CONFIGLOADER_PLATFORM_H__ -#define __CONFIGLOADER_PLATFORM_H__ +#ifndef XMRIG_CONFIGLOADER_PLATFORM_H +#define XMRIG_CONFIGLOADER_PLATFORM_H #ifdef _MSC_VER @@ -86,6 +86,7 @@ Options:\n\ --api-port=N port for the miner API\n\ --api-access-token=T access token for API\n\ --api-worker-id=ID custom worker-id for API\n\ + --api-id=ID custom instance ID for API\n\ --api-ipv6 enable IPv6 support for API\n\ --api-no-restricted enable full remote access (only if API token set)\n\ -h, --help display this help and exit\n\ @@ -101,6 +102,7 @@ static struct option const options[] = { { "api-access-token", 1, nullptr, xmrig::IConfig::ApiAccessTokenKey }, { "api-port", 1, nullptr, xmrig::IConfig::ApiPort }, { "api-worker-id", 1, nullptr, xmrig::IConfig::ApiWorkerIdKey }, + { "api-id", 1, nullptr, xmrig::IConfig::ApiIdKey }, { "api-ipv6", 0, nullptr, xmrig::IConfig::ApiIPv6Key }, { "api-no-restricted", 0, nullptr, xmrig::IConfig::ApiRestrictedKey }, { "av", 1, nullptr, xmrig::IConfig::AVKey }, @@ -131,7 +133,7 @@ static struct option const options[] = { { "userpass", 1, nullptr, xmrig::IConfig::UserpassKey }, { "rig-id", 1, nullptr, xmrig::IConfig::RigIdKey }, { "version", 0, nullptr, xmrig::IConfig::VersionKey }, - { 0, 0, 0, 0 } + { nullptr, 0, nullptr, 0 } }; @@ -155,7 +157,7 @@ static struct option const config_options[] = { { "threads", 1, nullptr, xmrig::IConfig::ThreadsKey }, { "user-agent", 1, nullptr, xmrig::IConfig::UserAgentKey }, { "hw-aes", 0, nullptr, xmrig::IConfig::HardwareAESKey }, - { 0, 0, 0, 0 } + { nullptr, 0, nullptr, 0 } }; @@ -168,7 +170,7 @@ static struct option const pool_options[] = { { "keepalive", 2, nullptr, xmrig::IConfig::KeepAliveKey }, { "variant", 1, nullptr, xmrig::IConfig::VariantKey }, { "rig-id", 1, nullptr, xmrig::IConfig::RigIdKey }, - { 0, 0, 0, 0 } + { nullptr, 0, nullptr, 0 } }; @@ -178,10 +180,11 @@ static struct option const api_options[] = { { "worker-id", 1, nullptr, xmrig::IConfig::ApiWorkerIdKey }, { "ipv6", 0, nullptr, xmrig::IConfig::ApiIPv6Key }, { "restricted", 0, nullptr, xmrig::IConfig::ApiRestrictedKey }, - { 0, 0, 0, 0 } + { "id", 1, nullptr, xmrig::IConfig::ApiIdKey }, + { nullptr, 0, nullptr, 0 } }; } /* namespace xmrig */ -#endif /* __CONFIGLOADER_PLATFORM_H__ */ +#endif /* XMRIG_CONFIGLOADER_PLATFORM_H */