* Fixed API ID collision.

This commit is contained in:
XMRig 2018-08-31 18:30:51 +03:00
parent 57479cef8c
commit 73fca9114e
4 changed files with 25 additions and 15 deletions

View file

@ -42,7 +42,6 @@
#include "core/Controller.h" #include "core/Controller.h"
#include "Cpu.h" #include "Cpu.h"
#include "interfaces/IThread.h" #include "interfaces/IThread.h"
#include "Mem.h"
#include "rapidjson/document.h" #include "rapidjson/document.h"
#include "rapidjson/prettywriter.h" #include "rapidjson/prettywriter.h"
#include "rapidjson/stringbuffer.h" #include "rapidjson/stringbuffer.h"
@ -67,7 +66,7 @@ ApiRouter::ApiRouter(xmrig::Controller *controller) :
memset(m_workerId, 0, sizeof(m_workerId)); memset(m_workerId, 0, sizeof(m_workerId));
setWorkerId(controller->config()->apiWorkerId()); 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)); 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; uv_interface_address_t *interfaces;
int count = 0; int count = 0;
@ -160,11 +164,13 @@ void ApiRouter::genId()
if (!interfaces[i].is_internal && interfaces[i].address.address4.sin_family == AF_INET) { if (!interfaces[i].is_internal && interfaces[i].address.address4.sin_family == AF_INET) {
uint8_t hash[200]; uint8_t hash[200];
const size_t addrSize = sizeof(interfaces[i].phys_addr); 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<uint16_t>(m_controller->config()->apiPort());
uint8_t *input = new uint8_t[inSize](); uint8_t *input = new uint8_t[inSize]();
memcpy(input, interfaces[i].phys_addr, addrSize); memcpy(input, &port, sizeof(uint16_t));
memcpy(input + addrSize, APP_KIND, strlen(APP_KIND)); 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); xmrig::keccak(input, inSize, hash);
Job::toHex(hash, 8, m_id); Job::toHex(hash, 8, m_id);

View file

@ -56,7 +56,7 @@ protected:
private: private:
void finalize(xmrig::HttpReply &reply, rapidjson::Document &doc) const; void finalize(xmrig::HttpReply &reply, rapidjson::Document &doc) const;
void genId(); void genId(const char *id);
void getConnection(rapidjson::Document &doc) const; void getConnection(rapidjson::Document &doc) const;
void getHashrate(rapidjson::Document &doc) const; void getHashrate(rapidjson::Document &doc) const;
void getIdentify(rapidjson::Document &doc) const; void getIdentify(rapidjson::Document &doc) const;
@ -66,7 +66,7 @@ private:
void setWorkerId(const char *id); void setWorkerId(const char *id);
void updateWorkerId(const char *id, const char *previousId); void updateWorkerId(const char *id, const char *previousId);
char m_id[17]; char m_id[32];
char m_workerId[128]; char m_workerId[128];
NetworkState m_network; NetworkState m_network;
xmrig::Controller *m_controller; xmrig::Controller *m_controller;

View file

@ -75,6 +75,7 @@ void xmrig::Config::getJSON(rapidjson::Document &doc) const
Value api(kObjectType); Value api(kObjectType);
api.AddMember("port", apiPort(), allocator); api.AddMember("port", apiPort(), allocator);
api.AddMember("access-token", apiToken() ? Value(StringRef(apiToken())).Move() : Value(kNullType).Move(), 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("worker-id", apiWorkerId() ? Value(StringRef(apiWorkerId())).Move() : Value(kNullType).Move(), allocator);
api.AddMember("ipv6", isApiIPv6(), allocator); api.AddMember("ipv6", isApiIPv6(), allocator);
api.AddMember("restricted", isApiRestricted(), allocator); api.AddMember("restricted", isApiRestricted(), allocator);

View file

@ -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 __CONFIGLOADER_PLATFORM_H__ #ifndef XMRIG_CONFIGLOADER_PLATFORM_H
#define __CONFIGLOADER_PLATFORM_H__ #define XMRIG_CONFIGLOADER_PLATFORM_H
#ifdef _MSC_VER #ifdef _MSC_VER
@ -86,6 +86,7 @@ Options:\n\
--api-port=N port for the miner API\n\ --api-port=N port for the miner API\n\
--api-access-token=T access token for API\n\ --api-access-token=T access token for API\n\
--api-worker-id=ID custom worker-id 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-ipv6 enable IPv6 support for API\n\
--api-no-restricted enable full remote access (only if API token set)\n\ --api-no-restricted enable full remote access (only if API token set)\n\
-h, --help display this help and exit\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-access-token", 1, nullptr, xmrig::IConfig::ApiAccessTokenKey },
{ "api-port", 1, nullptr, xmrig::IConfig::ApiPort }, { "api-port", 1, nullptr, xmrig::IConfig::ApiPort },
{ "api-worker-id", 1, nullptr, xmrig::IConfig::ApiWorkerIdKey }, { "api-worker-id", 1, nullptr, xmrig::IConfig::ApiWorkerIdKey },
{ "api-id", 1, nullptr, xmrig::IConfig::ApiIdKey },
{ "api-ipv6", 0, nullptr, xmrig::IConfig::ApiIPv6Key }, { "api-ipv6", 0, nullptr, xmrig::IConfig::ApiIPv6Key },
{ "api-no-restricted", 0, nullptr, xmrig::IConfig::ApiRestrictedKey }, { "api-no-restricted", 0, nullptr, xmrig::IConfig::ApiRestrictedKey },
{ "av", 1, nullptr, xmrig::IConfig::AVKey }, { "av", 1, nullptr, xmrig::IConfig::AVKey },
@ -131,7 +133,7 @@ static struct option const options[] = {
{ "userpass", 1, nullptr, xmrig::IConfig::UserpassKey }, { "userpass", 1, nullptr, xmrig::IConfig::UserpassKey },
{ "rig-id", 1, nullptr, xmrig::IConfig::RigIdKey }, { "rig-id", 1, nullptr, xmrig::IConfig::RigIdKey },
{ "version", 0, nullptr, xmrig::IConfig::VersionKey }, { "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 }, { "threads", 1, nullptr, xmrig::IConfig::ThreadsKey },
{ "user-agent", 1, nullptr, xmrig::IConfig::UserAgentKey }, { "user-agent", 1, nullptr, xmrig::IConfig::UserAgentKey },
{ "hw-aes", 0, nullptr, xmrig::IConfig::HardwareAESKey }, { "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 }, { "keepalive", 2, nullptr, xmrig::IConfig::KeepAliveKey },
{ "variant", 1, nullptr, xmrig::IConfig::VariantKey }, { "variant", 1, nullptr, xmrig::IConfig::VariantKey },
{ "rig-id", 1, nullptr, xmrig::IConfig::RigIdKey }, { "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 }, { "worker-id", 1, nullptr, xmrig::IConfig::ApiWorkerIdKey },
{ "ipv6", 0, nullptr, xmrig::IConfig::ApiIPv6Key }, { "ipv6", 0, nullptr, xmrig::IConfig::ApiIPv6Key },
{ "restricted", 0, nullptr, xmrig::IConfig::ApiRestrictedKey }, { "restricted", 0, nullptr, xmrig::IConfig::ApiRestrictedKey },
{ 0, 0, 0, 0 } { "id", 1, nullptr, xmrig::IConfig::ApiIdKey },
{ nullptr, 0, nullptr, 0 }
}; };
} /* namespace xmrig */ } /* namespace xmrig */
#endif /* __CONFIGLOADER_PLATFORM_H__ */ #endif /* XMRIG_CONFIGLOADER_PLATFORM_H */