Move Job to common.

This commit is contained in:
XMRig 2018-04-20 23:44:32 +07:00
parent 36a612af9a
commit 8fe264bbd7
10 changed files with 63 additions and 72 deletions

View File

@ -19,8 +19,12 @@ set(HEADERS
src/common/config/ConfigWatcher.h
src/common/Console.h
src/common/crypto/keccak.h
src/common/log/ConsoleLog.h
src/common/log/FileLog.h
src/common/log/Log.h
src/common/net/Client.h
src/common/net/Id.h
src/common/net/Job.h
src/common/net/Pool.h
src/common/net/Storage.h
src/common/net/strategies/FailoverStrategy.h
@ -46,11 +50,7 @@ set(HEADERS
src/interfaces/IThread.h
src/interfaces/IWatcherListener.h
src/interfaces/IWorker.h
src/common/log/ConsoleLog.h
src/common/log/FileLog.h
src/common/log/Log.h
src/Mem.h
src/net/Job.h
src/net/JobResult.h
src/net/Network.h
src/net/strategies/DonateStrategy.h
@ -93,7 +93,11 @@ set(SOURCES
src/common/config/ConfigWatcher.cpp
src/common/Console.cpp
src/common/crypto/keccak.cpp
src/common/log/ConsoleLog.cpp
src/common/log/FileLog.cpp
src/common/log/Log.cpp
src/common/net/Client.cpp
src/common/net/Job.cpp
src/common/net/Pool.cpp
src/common/net/strategies/FailoverStrategy.cpp
src/common/net/strategies/SinglePoolStrategy.cpp
@ -101,11 +105,7 @@ set(SOURCES
src/common/Platform.cpp
src/core/Config.cpp
src/core/Controller.cpp
src/common/log/ConsoleLog.cpp
src/common/log/FileLog.cpp
src/common/log/Log.cpp
src/Mem.cpp
src/net/Job.cpp
src/net/Network.cpp
src/net/strategies/DonateStrategy.cpp
src/Summary.cpp

View File

@ -36,13 +36,13 @@
#include "common/api/HttpReply.h"
#include "common/api/HttpRequest.h"
#include "common/crypto/keccak.h"
#include "common/net/Job.h"
#include "common/Platform.h"
#include "core/Config.h"
#include "core/Controller.h"
#include "Cpu.h"
#include "interfaces/IThread.h"
#include "Mem.h"
#include "net/Job.h"
#include "rapidjson/document.h"
#include "rapidjson/prettywriter.h"
#include "rapidjson/stringbuffer.h"

View File

@ -32,19 +32,13 @@
#include "common/log/Log.h"
#include "common/net/Client.h"
#include "interfaces/IClientListener.h"
#include "net/JobResult.h"
#include "rapidjson/document.h"
#include "rapidjson/error/en.h"
#include "rapidjson/stringbuffer.h"
#include "rapidjson/writer.h"
#ifdef XMRIG_PROXY_PROJECT
# include "proxy/JobResult.h"
#else
# include "net/JobResult.h"
#endif
#ifdef _MSC_VER
# define strncasecmp(x,y,z) _strnicmp(x,y,z)
#endif
@ -238,12 +232,7 @@ bool Client::parseJob(const rapidjson::Value &params, int *code)
return false;
}
# ifdef XMRIG_PROXY_PROJECT
Job job(m_id, m_pool.variant());
job.setClientId(m_rpcId);
# else
Job job(m_id, m_nicehash, m_pool.algo(), m_pool.variant());
# endif
Job job(m_id, m_nicehash, m_pool.algo(), m_pool.variant(), m_rpcId);
if (!job.setId(params["job_id"].GetString())) {
*code = 3;
@ -260,10 +249,6 @@ bool Client::parseJob(const rapidjson::Value &params, int *code)
return false;
}
if (params.HasMember("coin")) {
job.setCoin(params["coin"].GetString());
}
if (params.HasMember("variant")) {
job.setVariant(params["variant"].GetInt());
}

View File

@ -31,10 +31,10 @@
#include "common/net/Id.h"
#include "common/net/Job.h"
#include "common/net/Pool.h"
#include "common/net/Storage.h"
#include "common/net/SubmitResult.h"
#include "net/Job.h"
#include "rapidjson/fwd.h"

View File

@ -27,7 +27,7 @@
#include <string.h>
#include "net/Job.h"
#include "common/net/Job.h"
static inline unsigned char hf_hex2bin(char c, bool &err)
@ -59,31 +59,30 @@ static inline char hf_bin2hex(unsigned char c)
Job::Job() :
m_nicehash(false),
m_coin(),
m_algo(xmrig::CRYPTONIGHT),
m_poolId(-2),
m_threadId(-1),
m_size(0),
m_diff(0),
m_target(0),
m_blob(),
m_algo(xmrig::INVALID_ALGO),
m_variant(xmrig::VARIANT_AUTO)
{
}
Job::Job(int poolId, bool nicehash, int algo, int variant) :
Job::Job(int poolId, bool nicehash, xmrig::Algo algo, xmrig::Variant variant, const xmrig::Id &clientId) :
m_nicehash(nicehash),
m_coin(),
m_algo(algo),
m_poolId(poolId),
m_threadId(-1),
m_size(0),
m_diff(0),
m_target(0),
m_blob()
m_blob(),
m_algo(algo),
m_clientId(clientId),
m_variant(variant)
{
setVariant(variant);
}
@ -116,6 +115,11 @@ bool Job::setBlob(const char *blob)
m_nicehash = true;
}
# ifdef XMRIG_PROXY_PROJECT
memset(m_rawBlob, 0, sizeof(m_rawBlob));
memcpy(m_rawBlob, blob, m_size * 2);
# endif
return true;
}
@ -152,23 +156,16 @@ bool Job::setTarget(const char *target)
return false;
}
# ifdef XMRIG_PROXY_PROJECT
memset(m_rawTarget, 0, sizeof(m_rawTarget));
memcpy(m_rawTarget, target, len);
# endif
m_diff = toDiff(m_target);
return true;
}
void Job::setCoin(const char *coin)
{
if (!coin || strlen(coin) > 4) {
memset(m_coin, 0, sizeof(m_coin));
return;
}
strncpy(m_coin, coin, sizeof(m_coin));
m_algo = strcmp(m_coin, "AEON") == 0 ? xmrig::CRYPTONIGHT_LITE : xmrig::CRYPTONIGHT;
}
void Job::setVariant(int variant)
{
switch (variant) {

View File

@ -38,31 +38,35 @@ class Job
{
public:
Job();
Job(int poolId, bool nicehash, int algo, int variant);
Job(int poolId, bool nicehash, xmrig::Algo algo, xmrig::Variant variant, const xmrig::Id &clientId);
~Job();
bool setBlob(const char *blob);
bool setTarget(const char *target);
void setCoin(const char *coin);
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 char *coin() const { return m_coin; }
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 &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 (uint32_t) m_diff; }
inline uint64_t target() const { return m_target; }
inline void setNicehash(bool nicehash) { m_nicehash = nicehash; }
inline void setPoolId(int poolId) { m_poolId = poolId; }
inline void setThreadId(int threadId) { m_threadId = threadId; }
inline xmrig::Variant variant() const { return (m_variant == xmrig::VARIANT_AUTO ? (m_blob[0] > 6 ? xmrig::VARIANT_V1 : xmrig::VARIANT_NONE) : 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::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 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::Variant variant() const { return (m_variant == xmrig::VARIANT_AUTO ? (m_blob[0] > 6 ? xmrig::VARIANT_V1 : xmrig::VARIANT_NONE) : m_variant); }
# ifdef XMRIG_PROXY_PROJECT
inline char *rawBlob() { return m_rawBlob; }
inline const char *rawTarget() const { return m_rawTarget; }
# endif
static bool fromHex(const char* in, unsigned int len, unsigned char* out);
static inline uint32_t *nonce(uint8_t *blob) { return reinterpret_cast<uint32_t*>(blob + 39); }
@ -78,16 +82,21 @@ public:
private:
bool m_nicehash;
char m_coin[5];
int m_algo;
int m_poolId;
int m_threadId;
size_t m_size;
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_algo;
xmrig::Id m_clientId;
xmrig::Id m_id;
xmrig::Variant m_variant;
# ifdef XMRIG_PROXY_PROJECT
char m_rawBlob[176];
char m_rawTarget[24];
# endif
};
#endif /* __JOB_H__ */

View File

@ -29,7 +29,7 @@
#include <stdint.h>
#include "Job.h"
#include "common/net/Job.h"
class JobResult

View File

@ -24,11 +24,11 @@
#include "common/crypto/keccak.h"
#include "common/net/Client.h"
#include "common/net/Job.h"
#include "common/net/strategies/FailoverStrategy.h"
#include "common/Platform.h"
#include "common/xmrig.h"
#include "interfaces/IStrategyListener.h"
#include "net/Job.h"
#include "net/strategies/DonateStrategy.h"

View File

@ -26,8 +26,8 @@
#define __MULTIWORKER_H__
#include "common/net/Job.h"
#include "Mem.h"
#include "net/Job.h"
#include "net/JobResult.h"
#include "workers/Worker.h"

View File

@ -30,7 +30,7 @@
#include <uv.h>
#include <vector>
#include "net/Job.h"
#include "common/net/Job.h"
#include "net/JobResult.h"
#include "rapidjson/fwd.h"