Sync changes with proxy.
This commit is contained in:
parent
b9fec2fcc4
commit
ca149d2eed
22 changed files with 436 additions and 328 deletions
|
@ -232,7 +232,7 @@ bool Client::parseJob(const rapidjson::Value ¶ms, int *code)
|
|||
return false;
|
||||
}
|
||||
|
||||
Job job(m_id, m_nicehash, m_pool.algorithm(), m_pool.variant(), m_rpcId);
|
||||
Job job(m_id, m_nicehash, m_pool.algorithm(), m_rpcId);
|
||||
|
||||
if (!job.setId(params["job_id"].GetString())) {
|
||||
*code = 3;
|
||||
|
@ -250,7 +250,7 @@ bool Client::parseJob(const rapidjson::Value ¶ms, int *code)
|
|||
}
|
||||
|
||||
if (params.HasMember("variant")) {
|
||||
job.setVariant(params["variant"].GetInt());
|
||||
job.algorithm().parseVariant(params["variant"].GetInt());
|
||||
}
|
||||
|
||||
if (m_job != job) {
|
||||
|
|
|
@ -64,14 +64,12 @@ Job::Job() :
|
|||
m_size(0),
|
||||
m_diff(0),
|
||||
m_target(0),
|
||||
m_blob(),
|
||||
m_algorithm(xmrig::INVALID_ALGO),
|
||||
m_variant(xmrig::VARIANT_AUTO)
|
||||
m_blob()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Job::Job(int poolId, bool nicehash, xmrig::Algo algo, xmrig::Variant variant, const xmrig::Id &clientId) :
|
||||
Job::Job(int poolId, bool nicehash, xmrig::Algorithm algorithm, const xmrig::Id &clientId) :
|
||||
m_nicehash(nicehash),
|
||||
m_poolId(poolId),
|
||||
m_threadId(-1),
|
||||
|
@ -79,9 +77,8 @@ Job::Job(int poolId, bool nicehash, xmrig::Algo algo, xmrig::Variant variant, co
|
|||
m_diff(0),
|
||||
m_target(0),
|
||||
m_blob(),
|
||||
m_algorithm(algo),
|
||||
m_clientId(clientId),
|
||||
m_variant(variant)
|
||||
m_algorithm(algorithm),
|
||||
m_clientId(clientId)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -166,23 +163,6 @@ bool Job::setTarget(const char *target)
|
|||
}
|
||||
|
||||
|
||||
void Job::setVariant(int variant)
|
||||
{
|
||||
switch (variant) {
|
||||
case xmrig::VARIANT_AUTO:
|
||||
case xmrig::VARIANT_V0:
|
||||
case xmrig::VARIANT_V1:
|
||||
m_variant = static_cast<xmrig::Variant>(variant);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
m_variant = xmrig::VARIANT_AUTO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Job::fromHex(const char* in, unsigned int len, unsigned char* out)
|
||||
{
|
||||
bool error = false;
|
||||
|
|
|
@ -30,40 +30,44 @@
|
|||
#include <stdint.h>
|
||||
|
||||
|
||||
#include "common/crypto/Algorithm.h"
|
||||
#include "common/net/Id.h"
|
||||
#include "common/xmrig.h"
|
||||
|
||||
|
||||
class Job
|
||||
{
|
||||
public:
|
||||
Job();
|
||||
Job(int poolId, bool nicehash, xmrig::Algo algo, xmrig::Variant variant, const xmrig::Id &clientId);
|
||||
Job(int poolId, bool nicehash, xmrig::Algorithm algorithm, const xmrig::Id &clientId);
|
||||
~Job();
|
||||
|
||||
bool setBlob(const char *blob);
|
||||
bool setTarget(const char *target);
|
||||
void setVariant(int variant);
|
||||
|
||||
inline bool isNicehash() const { return m_nicehash; }
|
||||
inline bool isValid() const { return m_size > 0 && m_diff > 0; }
|
||||
inline bool setId(const char *id) { return m_id.setId(id); }
|
||||
inline const uint32_t *nonce() const { return reinterpret_cast<const uint32_t*>(m_blob + 39); }
|
||||
inline const uint8_t *blob() const { return m_blob; }
|
||||
inline const xmrig::Id &clientId() const { return m_clientId; }
|
||||
inline const xmrig::Id &id() const { return m_id; }
|
||||
inline int poolId() const { return m_poolId; }
|
||||
inline int threadId() const { return m_threadId; }
|
||||
inline size_t size() const { return m_size; }
|
||||
inline uint32_t *nonce() { return reinterpret_cast<uint32_t*>(m_blob + 39); }
|
||||
inline uint32_t diff() const { return static_cast<uint32_t>(m_diff); }
|
||||
inline uint64_t target() const { return m_target; }
|
||||
inline void reset() { m_size = 0; m_diff = 0; }
|
||||
inline void setClientId(const xmrig::Id &id) { m_clientId = id; }
|
||||
inline void setPoolId(int poolId) { m_poolId = poolId; }
|
||||
inline void setThreadId(int threadId) { m_threadId = threadId; }
|
||||
inline xmrig::Algo algorithm() const { return m_algorithm; }
|
||||
inline xmrig::Variant variant() const { return (m_variant == xmrig::VARIANT_AUTO ? (m_blob[0] > 6 ? xmrig::VARIANT_V1 : xmrig::VARIANT_V0) : m_variant); }
|
||||
inline bool isNicehash() const { return m_nicehash; }
|
||||
inline bool isValid() const { return m_size > 0 && m_diff > 0; }
|
||||
inline bool setId(const char *id) { return m_id.setId(id); }
|
||||
inline const uint32_t *nonce() const { return reinterpret_cast<const uint32_t*>(m_blob + 39); }
|
||||
inline const uint8_t *blob() const { return m_blob; }
|
||||
inline const xmrig::Algorithm &algorithm() const { return m_algorithm; }
|
||||
inline const xmrig::Id &clientId() const { return m_clientId; }
|
||||
inline const xmrig::Id &id() const { return m_id; }
|
||||
inline int poolId() const { return m_poolId; }
|
||||
inline int threadId() const { return m_threadId; }
|
||||
inline size_t size() const { return m_size; }
|
||||
inline uint32_t *nonce() { return reinterpret_cast<uint32_t*>(m_blob + 39); }
|
||||
inline uint32_t diff() const { return static_cast<uint32_t>(m_diff); }
|
||||
inline uint64_t target() const { return m_target; }
|
||||
inline void reset() { m_size = 0; m_diff = 0; }
|
||||
inline void setClientId(const xmrig::Id &id) { m_clientId = id; }
|
||||
inline void setPoolId(int poolId) { m_poolId = poolId; }
|
||||
inline void setThreadId(int threadId) { m_threadId = threadId; }
|
||||
inline xmrig::Algorithm &algorithm() { return m_algorithm; }
|
||||
|
||||
inline xmrig::Variant variant() const
|
||||
{
|
||||
return (m_algorithm.variant() == xmrig::VARIANT_AUTO ? (m_blob[0] > 6 ? xmrig::VARIANT_1 : xmrig::VARIANT_0) : m_algorithm.variant());
|
||||
}
|
||||
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
inline char *rawBlob() { return m_rawBlob; }
|
||||
|
@ -90,10 +94,9 @@ private:
|
|||
uint64_t m_diff;
|
||||
uint64_t m_target;
|
||||
uint8_t m_blob[96]; // Max blob size is 84 (75 fixed + 9 variable), aligned to 96. https://github.com/xmrig/xmrig/issues/1 Thanks fireice-uk.
|
||||
xmrig::Algo m_algorithm;
|
||||
xmrig::Algorithm m_algorithm;
|
||||
xmrig::Id m_clientId;
|
||||
xmrig::Id m_id;
|
||||
xmrig::Variant m_variant;
|
||||
|
||||
# ifdef XMRIG_PROXY_PROJECT
|
||||
char m_rawBlob[176];
|
||||
|
|
|
@ -29,6 +29,7 @@
|
|||
|
||||
|
||||
#include "common/net/Pool.h"
|
||||
#include "rapidjson/document.h"
|
||||
|
||||
|
||||
#ifdef APP_DEBUG
|
||||
|
@ -42,52 +43,10 @@
|
|||
#endif
|
||||
|
||||
|
||||
static const char *algoNames[] = {
|
||||
"cryptonight",
|
||||
# ifndef XMRIG_NO_AEON
|
||||
"cryptonight-lite",
|
||||
# else
|
||||
nullptr,
|
||||
# endif
|
||||
# ifndef XMRIG_NO_SUMO
|
||||
"cryptonight-heavy",
|
||||
# else
|
||||
nullptr,
|
||||
# endif
|
||||
# ifndef XMRIG_NO_IPBC
|
||||
"cryptonight-ipbc",
|
||||
# else
|
||||
nullptr,
|
||||
# endif
|
||||
};
|
||||
|
||||
|
||||
static const char *algoNamesShort[] = {
|
||||
"cn",
|
||||
# ifndef XMRIG_NO_AEON
|
||||
"cn-lite",
|
||||
# else
|
||||
nullptr,
|
||||
# endif
|
||||
# ifndef XMRIG_NO_SUMO
|
||||
"cn-heavy",
|
||||
# else
|
||||
nullptr,
|
||||
# endif
|
||||
# ifndef XMRIG_NO_IPBC
|
||||
"cn-ipbc",
|
||||
# else
|
||||
nullptr,
|
||||
# endif
|
||||
};
|
||||
|
||||
|
||||
Pool::Pool() :
|
||||
m_nicehash(false),
|
||||
m_keepAlive(0),
|
||||
m_port(kDefaultPort),
|
||||
m_algorithm(xmrig::INVALID_ALGO),
|
||||
m_variant(xmrig::VARIANT_AUTO)
|
||||
m_port(kDefaultPort)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -106,23 +65,19 @@ Pool::Pool() :
|
|||
Pool::Pool(const char *url) :
|
||||
m_nicehash(false),
|
||||
m_keepAlive(0),
|
||||
m_port(kDefaultPort),
|
||||
m_algorithm(xmrig::INVALID_ALGO),
|
||||
m_variant(xmrig::VARIANT_AUTO)
|
||||
m_port(kDefaultPort)
|
||||
{
|
||||
parse(url);
|
||||
}
|
||||
|
||||
|
||||
Pool::Pool(const char *host, uint16_t port, const char *user, const char *password, int keepAlive, bool nicehash, xmrig::Variant variant) :
|
||||
Pool::Pool(const char *host, uint16_t port, const char *user, const char *password, int keepAlive, bool nicehash) :
|
||||
m_nicehash(nicehash),
|
||||
m_keepAlive(keepAlive),
|
||||
m_port(port),
|
||||
m_algorithm(xmrig::INVALID_ALGO),
|
||||
m_host(host),
|
||||
m_password(password),
|
||||
m_user(user),
|
||||
m_variant(variant)
|
||||
m_user(user)
|
||||
{
|
||||
const size_t size = m_host.size() + 8;
|
||||
assert(size > 8);
|
||||
|
@ -134,41 +89,6 @@ Pool::Pool(const char *host, uint16_t port, const char *user, const char *passwo
|
|||
}
|
||||
|
||||
|
||||
const char *Pool::algoName(xmrig::Algo algorithm, bool shortName)
|
||||
{
|
||||
if (algorithm == xmrig::INVALID_ALGO) {
|
||||
return "invalid";
|
||||
}
|
||||
|
||||
return (shortName ? algoNamesShort : algoNames)[algorithm];
|
||||
}
|
||||
|
||||
|
||||
xmrig::Algo Pool::algorithm(const char *algo)
|
||||
{
|
||||
# ifndef XMRIG_NO_AEON
|
||||
if (strcasecmp(algo, "cryptonight-light") == 0) {
|
||||
fprintf(stderr, "Algorithm \"cryptonight-light\" is deprecated, use \"cryptonight-lite\" instead\n");
|
||||
|
||||
return xmrig::CRYPTONIGHT_LITE;
|
||||
}
|
||||
# endif
|
||||
|
||||
const size_t size = sizeof(algoNames) / sizeof(algoNames[0]);
|
||||
|
||||
assert(size == (sizeof(algoNamesShort) / sizeof(algoNamesShort[0])));
|
||||
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
if ((algoNames[i] && strcasecmp(algo, algoNames[i]) == 0) || (algoNamesShort[i] && strcasecmp(algo, algoNamesShort[i]) == 0)) {
|
||||
return static_cast<xmrig::Algo>(i);
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stderr, "Unknown algorithm \"%s\" specified.\n", algo);
|
||||
return xmrig::INVALID_ALGO;
|
||||
}
|
||||
|
||||
|
||||
bool Pool::isEqual(const Pool &other) const
|
||||
{
|
||||
return (m_nicehash == other.m_nicehash
|
||||
|
@ -179,8 +99,7 @@ bool Pool::isEqual(const Pool &other) const
|
|||
&& m_password == other.m_password
|
||||
&& m_rigId == other.m_rigId
|
||||
&& m_url == other.m_url
|
||||
&& m_user == other.m_user
|
||||
&& m_variant == other.m_variant);
|
||||
&& m_user == other.m_user);
|
||||
}
|
||||
|
||||
|
||||
|
@ -242,14 +161,54 @@ bool Pool::setUserpass(const char *userpass)
|
|||
}
|
||||
|
||||
|
||||
rapidjson::Value Pool::toJSON(rapidjson::Document &doc) const
|
||||
{
|
||||
using namespace rapidjson;
|
||||
|
||||
auto &allocator = doc.GetAllocator();
|
||||
|
||||
Value obj(kObjectType);
|
||||
|
||||
obj.AddMember("url", StringRef(url()), allocator);
|
||||
obj.AddMember("user", StringRef(user()), allocator);
|
||||
obj.AddMember("pass", StringRef(password()), allocator);
|
||||
obj.AddMember("rig-id", rigId() ? Value(StringRef(rigId())).Move() : Value(kNullType).Move(), allocator);
|
||||
|
||||
# ifndef XMRIG_PROXY_PROJECT
|
||||
obj.AddMember("nicehash", isNicehash(), allocator);
|
||||
# endif
|
||||
|
||||
if (m_keepAlive == 0 || m_keepAlive == kKeepAliveTimeout) {
|
||||
obj.AddMember("keepalive", m_keepAlive > 0, allocator);
|
||||
}
|
||||
else {
|
||||
obj.AddMember("keepalive", m_keepAlive, allocator);
|
||||
}
|
||||
|
||||
switch (m_algorithm.variant()) {
|
||||
case xmrig::VARIANT_AUTO:
|
||||
case xmrig::VARIANT_0:
|
||||
case xmrig::VARIANT_1:
|
||||
obj.AddMember("variant", m_algorithm.variant(), allocator);
|
||||
break;
|
||||
|
||||
default:
|
||||
obj.AddMember("variant", StringRef(m_algorithm.variantName()), allocator);
|
||||
break;
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
void Pool::adjust(xmrig::Algo algorithm)
|
||||
{
|
||||
if (!isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_algorithm == xmrig::INVALID_ALGO) {
|
||||
m_algorithm = algorithm;
|
||||
if (!m_algorithm.isValid()) {
|
||||
m_algorithm.setAlgo(algorithm);
|
||||
}
|
||||
|
||||
if (strstr(m_host.data(), ".nicehash.com")) {
|
||||
|
@ -257,50 +216,17 @@ void Pool::adjust(xmrig::Algo algorithm)
|
|||
m_nicehash = true;
|
||||
|
||||
if (strstr(m_host.data(), "cryptonightv7.")) {
|
||||
m_variant = xmrig::VARIANT_V1;
|
||||
m_algorithm.setVariant(xmrig::VARIANT_1);
|
||||
}
|
||||
}
|
||||
|
||||
if (strstr(m_host.data(), ".minergate.com")) {
|
||||
m_variant = xmrig::VARIANT_V1;
|
||||
m_keepAlive = false;
|
||||
m_algorithm.setVariant(xmrig::VARIANT_1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Pool::setVariant(int variant)
|
||||
{
|
||||
switch (variant) {
|
||||
case xmrig::VARIANT_AUTO:
|
||||
case xmrig::VARIANT_V0:
|
||||
case xmrig::VARIANT_V1:
|
||||
m_variant = static_cast<xmrig::Variant>(variant);
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
xmrig::Variant Pool::variant() const
|
||||
{
|
||||
switch (m_algorithm) {
|
||||
case xmrig::CRYPTONIGHT_HEAVY:
|
||||
return xmrig::VARIANT_V0;
|
||||
|
||||
case xmrig::CRYPTONIGHT_IPBC:
|
||||
return xmrig::VARIANT_V1;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return m_variant;
|
||||
}
|
||||
|
||||
|
||||
#ifdef APP_DEBUG
|
||||
void Pool::print() const
|
||||
{
|
||||
|
@ -309,8 +235,8 @@ void Pool::print() const
|
|||
LOG_DEBUG ("port: %d", static_cast<int>(m_port));
|
||||
LOG_DEBUG ("user: %s", m_user.data());
|
||||
LOG_DEBUG ("pass: %s", m_password.data());
|
||||
LOG_DEBUG ("rig_id %s", m_rigId.data());
|
||||
LOG_DEBUG ("algo: %s/%d", algoName(m_algorithm), static_cast<int>(variant()));
|
||||
LOG_DEBUG ("rig-id %s", m_rigId.data());
|
||||
LOG_DEBUG ("algo: %s", m_algorithm.name());
|
||||
LOG_DEBUG ("nicehash: %d", static_cast<int>(m_nicehash));
|
||||
LOG_DEBUG ("keepAlive: %d", m_keepAlive);
|
||||
}
|
||||
|
|
|
@ -28,8 +28,9 @@
|
|||
#include <stdint.h>
|
||||
|
||||
|
||||
#include "common/crypto/Algorithm.h"
|
||||
#include "common/utils/c_str.h"
|
||||
#include "common/xmrig.h"
|
||||
#include "rapidjson/fwd.h"
|
||||
|
||||
|
||||
class Pool
|
||||
|
@ -47,30 +48,25 @@ public:
|
|||
const char *user = nullptr,
|
||||
const char *password = nullptr,
|
||||
int keepAlive = 0,
|
||||
bool nicehash = false,
|
||||
xmrig::Variant variant = xmrig::VARIANT_AUTO
|
||||
bool nicehash = false
|
||||
);
|
||||
|
||||
static const char *algoName(xmrig::Algo algorithm, bool shortName = false);
|
||||
static xmrig::Algo algorithm(const char *algo);
|
||||
|
||||
inline bool isNicehash() const { return m_nicehash; }
|
||||
inline bool isValid() const { return !m_host.isNull() && m_port > 0; }
|
||||
inline const char *host() const { return m_host.data(); }
|
||||
inline const char *password() const { return !m_password.isNull() ? m_password.data() : kDefaultPassword; }
|
||||
inline const char *rigId() const { return m_rigId.data(); }
|
||||
inline const char *url() const { return m_url.data(); }
|
||||
inline const char *user() const { return !m_user.isNull() ? m_user.data() : kDefaultUser; }
|
||||
inline int keepAlive() const { return m_keepAlive; }
|
||||
inline uint16_t port() const { return m_port; }
|
||||
inline void setAlgo(const char *algo) { m_algorithm = algorithm(algo); }
|
||||
inline void setAlgo(xmrig::Algo algorithm) { m_algorithm = algorithm; }
|
||||
inline void setKeepAlive(int keepAlive) { m_keepAlive = keepAlive >= 0 ? keepAlive : 0; }
|
||||
inline void setNicehash(bool nicehash) { m_nicehash = nicehash; }
|
||||
inline void setPassword(const char *password) { m_password = password; }
|
||||
inline void setRigId(const char *rigId) { m_rigId = rigId; }
|
||||
inline void setUser(const char *user) { m_user = user; }
|
||||
inline xmrig::Algo algorithm() const { return m_algorithm; }
|
||||
inline bool isNicehash() const { return m_nicehash; }
|
||||
inline bool isValid() const { return !m_host.isNull() && m_port > 0; }
|
||||
inline const char *host() const { return m_host.data(); }
|
||||
inline const char *password() const { return !m_password.isNull() ? m_password.data() : kDefaultPassword; }
|
||||
inline const char *rigId() const { return m_rigId.data(); }
|
||||
inline const char *url() const { return m_url.data(); }
|
||||
inline const char *user() const { return !m_user.isNull() ? m_user.data() : kDefaultUser; }
|
||||
inline const xmrig::Algorithm &algorithm() const { return m_algorithm; }
|
||||
inline int keepAlive() const { return m_keepAlive; }
|
||||
inline uint16_t port() const { return m_port; }
|
||||
inline void setKeepAlive(int keepAlive) { m_keepAlive = keepAlive >= 0 ? keepAlive : 0; }
|
||||
inline void setNicehash(bool nicehash) { m_nicehash = nicehash; }
|
||||
inline void setPassword(const char *password) { m_password = password; }
|
||||
inline void setRigId(const char *rigId) { m_rigId = rigId; }
|
||||
inline void setUser(const char *user) { m_user = user; }
|
||||
inline xmrig::Algorithm &algorithm() { return m_algorithm; }
|
||||
|
||||
inline bool operator!=(const Pool &other) const { return !isEqual(other); }
|
||||
inline bool operator==(const Pool &other) const { return isEqual(other); }
|
||||
|
@ -78,9 +74,8 @@ public:
|
|||
bool isEqual(const Pool &other) const;
|
||||
bool parse(const char *url);
|
||||
bool setUserpass(const char *userpass);
|
||||
rapidjson::Value toJSON(rapidjson::Document &doc) const;
|
||||
void adjust(xmrig::Algo algorithm);
|
||||
void setVariant(int variant);
|
||||
xmrig::Variant variant() const;
|
||||
|
||||
# ifdef APP_DEBUG
|
||||
void print() const;
|
||||
|
@ -92,13 +87,12 @@ private:
|
|||
bool m_nicehash;
|
||||
int m_keepAlive;
|
||||
uint16_t m_port;
|
||||
xmrig::Algo m_algorithm;
|
||||
xmrig::Algorithm m_algorithm;
|
||||
xmrig::c_str m_host;
|
||||
xmrig::c_str m_password;
|
||||
xmrig::c_str m_rigId;
|
||||
xmrig::c_str m_url;
|
||||
xmrig::c_str m_user;
|
||||
xmrig::Variant m_variant;
|
||||
};
|
||||
|
||||
#endif /* __POOL_H__ */
|
||||
|
|
|
@ -29,9 +29,6 @@
|
|||
#include <map>
|
||||
|
||||
|
||||
#include "common/log/Log.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue