Prepare for per pool and per job algorithms.

This commit is contained in:
XMRig 2018-04-21 19:55:51 +07:00
parent 274992e50d
commit 45e8a0525c
14 changed files with 116 additions and 84 deletions

View file

@ -141,7 +141,7 @@ bool xmrig::CommonConfig::parseString(int key, const char *arg)
{
switch (key) {
case AlgorithmKey: /* --algo */
setAlgo(arg);
m_algorithm = Pool::algorithm(arg);
break;
case UserpassKey: /* --userpass */
@ -204,7 +204,7 @@ bool xmrig::CommonConfig::parseString(int key, const char *arg)
case SyslogKey: /* --syslog */
case KeepAliveKey: /* --keepalive */
case NicehashKey: /* --nicehash */
case ApiIPv6Key: /* --api-ipv6 */
case ApiIPv6Key: /* --api-ipv6 */
return parseBoolean(key, true);
case ColorKey: /* --no-color */
@ -322,9 +322,3 @@ bool xmrig::CommonConfig::parseInt(int key, int arg)
return true;
}
void xmrig::CommonConfig::setAlgo(const char *algo)
{
m_algorithm = Pool::algorithm(algo);
}

View file

@ -96,7 +96,6 @@ protected:
private:
bool parseInt(int key, int arg);
void setAlgo(const char *algo);
};

View file

@ -80,6 +80,12 @@ private:
};
#define MAGENTA_BOLD(x) "\e[1;35m" x "\e[0m"
#define MAGENTA(x) "\e[0;35m" x "\e[0m"
#define WHITE_BOLD(x) "\e[1;37m" x "\e[0m"
#define WHITE(x) "\e[0;37m" x "\e[0m"
#define LOG_ERR(x, ...) Log::i()->message(Log::ERR, x, ##__VA_ARGS__)
#define LOG_WARN(x, ...) Log::i()->message(Log::WARNING, x, ##__VA_ARGS__)
#define LOG_NOTICE(x, ...) Log::i()->message(Log::NOTICE, x, ##__VA_ARGS__)

View file

@ -232,7 +232,7 @@ bool Client::parseJob(const rapidjson::Value &params, int *code)
return false;
}
Job job(m_id, m_nicehash, m_pool.algo(), m_pool.variant(), m_rpcId);
Job job(m_id, m_nicehash, m_pool.algorithm(), m_pool.variant(), m_rpcId);
if (!job.setId(params["job_id"].GetString())) {
*code = 3;

View file

@ -65,7 +65,7 @@ Job::Job() :
m_diff(0),
m_target(0),
m_blob(),
m_algo(xmrig::INVALID_ALGO),
m_algorithm(xmrig::INVALID_ALGO),
m_variant(xmrig::VARIANT_AUTO)
{
}
@ -79,7 +79,7 @@ Job::Job(int poolId, bool nicehash, xmrig::Algo algo, xmrig::Variant variant, co
m_diff(0),
m_target(0),
m_blob(),
m_algo(algo),
m_algorithm(algo),
m_clientId(clientId),
m_variant(variant)
{
@ -170,7 +170,7 @@ void Job::setVariant(int variant)
{
switch (variant) {
case xmrig::VARIANT_AUTO:
case xmrig::VARIANT_NONE:
case xmrig::VARIANT_V0:
case xmrig::VARIANT_V1:
m_variant = static_cast<xmrig::Variant>(variant);
break;

View file

@ -61,7 +61,8 @@ public:
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); }
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); }
# ifdef XMRIG_PROXY_PROJECT
inline char *rawBlob() { return m_rawBlob; }
@ -88,7 +89,7 @@ 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_algo;
xmrig::Algo m_algorithm;
xmrig::Id m_clientId;
xmrig::Id m_id;
xmrig::Variant m_variant;

View file

@ -81,7 +81,7 @@ Pool::Pool() :
m_nicehash(false),
m_keepAlive(0),
m_port(kDefaultPort),
m_algo(xmrig::CRYPTONIGHT),
m_algorithm(xmrig::INVALID_ALGO),
m_variant(xmrig::VARIANT_AUTO)
{
}
@ -102,7 +102,7 @@ Pool::Pool(const char *url) :
m_nicehash(false),
m_keepAlive(0),
m_port(kDefaultPort),
m_algo(xmrig::CRYPTONIGHT),
m_algorithm(xmrig::INVALID_ALGO),
m_variant(xmrig::VARIANT_AUTO)
{
parse(url);
@ -113,11 +113,11 @@ Pool::Pool(const char *host, uint16_t port, const char *user, const char *passwo
m_nicehash(nicehash),
m_keepAlive(keepAlive),
m_port(port),
m_algo(xmrig::CRYPTONIGHT),
m_algorithm(xmrig::INVALID_ALGO),
m_host(host),
m_password(password),
m_user(user),
m_variant(variant)
m_variant(variant)
{
const size_t size = m_host.size() + 8;
assert(size > 8);
@ -131,6 +131,10 @@ 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];
}
@ -160,6 +164,20 @@ xmrig::Algo Pool::algorithm(const char *algo)
}
bool Pool::isEqual(const Pool &other) const
{
return (m_nicehash == other.m_nicehash
&& m_keepAlive == other.m_keepAlive
&& m_port == other.m_port
&& m_algorithm == other.m_algorithm
&& m_host == other.m_host
&& m_password == other.m_password
&& m_url == other.m_url
&& m_user == other.m_user
&& m_variant == other.m_variant);
}
bool Pool::parse(const char *url)
{
assert(url != nullptr);
@ -218,13 +236,15 @@ bool Pool::setUserpass(const char *userpass)
}
void Pool::adjust(xmrig::Algo algo)
void Pool::adjust(xmrig::Algo algorithm)
{
if (!isValid()) {
return;
}
m_algo = algo;
if (m_algorithm == xmrig::INVALID_ALGO) {
m_algorithm = algorithm;
}
if (strstr(m_host.data(), ".nicehash.com")) {
m_keepAlive = false;
@ -241,7 +261,7 @@ void Pool::setVariant(int variant)
{
switch (variant) {
case xmrig::VARIANT_AUTO:
case xmrig::VARIANT_NONE:
case xmrig::VARIANT_V0:
case xmrig::VARIANT_V1:
m_variant = static_cast<xmrig::Variant>(variant);
break;
@ -253,17 +273,20 @@ void Pool::setVariant(int variant)
}
bool Pool::isEqual(const Pool &other) const
xmrig::Variant Pool::variant() const
{
return (m_nicehash == other.m_nicehash
&& m_keepAlive == other.m_keepAlive
&& m_port == other.m_port
&& m_algo == other.m_algo
&& m_host == other.m_host
&& m_password == other.m_password
&& m_url == other.m_url
&& m_user == other.m_user
&& m_variant == other.m_variant);
switch (m_algorithm) {
case xmrig::CRYPTONIGHT_HEAVY:
return xmrig::VARIANT_V0;
case xmrig::CRYPTONIGHT_IPBC:
return xmrig::VARIANT_V1;
default:
break;
}
return m_variant;
}

View file

@ -62,22 +62,23 @@ public:
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 setUser(const char *user) { m_user = user; }
inline xmrig::Algo algo() const { return m_algo; }
inline xmrig::Variant variant() const { return m_variant; }
inline xmrig::Algo algorithm() const { return m_algorithm; }
inline bool operator!=(const Pool &other) const { return !isEqual(other); }
inline bool operator==(const Pool &other) const { return isEqual(other); }
bool isEqual(const Pool &other) const;
bool parse(const char *url);
bool setUserpass(const char *userpass);
void adjust(xmrig::Algo algo);
void adjust(xmrig::Algo algorithm);
void setVariant(int variant);
bool isEqual(const Pool &other) const;
xmrig::Variant variant() const;
private:
bool parseIPv6(const char *addr);
@ -85,7 +86,7 @@ private:
bool m_nicehash;
int m_keepAlive;
uint16_t m_port;
xmrig::Algo m_algo;
xmrig::Algo m_algorithm;
xmrig::c_str m_host;
xmrig::c_str m_password;
xmrig::c_str m_url;

View file

@ -60,7 +60,7 @@ enum AlgoVariant {
enum Variant {
VARIANT_AUTO = -1, // Autodetect
VARIANT_NONE = 0, // Original CryptoNight
VARIANT_V0 = 0, // Original CryptoNight or CryptoNight-Heavy
VARIANT_V1 = 1 // Monero v7 PoW
};