Sync changes.

This commit is contained in:
XMRig 2019-03-14 18:42:27 +07:00
parent fb62ee938a
commit d57b41c673
12 changed files with 113 additions and 12 deletions

View file

@ -32,6 +32,7 @@ set(HEADERS
src/base/net/Pool.h
src/base/net/Pools.h
src/base/tools/Arguments.h
src/base/tools/Chrono.h
src/base/tools/Handle.h
src/base/tools/String.h
src/common/config/CommonConfig.h

View file

@ -165,7 +165,7 @@ bool xmrig::Pool::isCompatible(const Algorithm &algorithm) const
# ifdef XMRIG_PROXY_PROJECT
if (m_algorithm.algo() == xmrig::CRYPTONIGHT && algorithm.algo() == xmrig::CRYPTONIGHT) {
return m_algorithm.variant() == xmrig::VARIANT_XTL || m_algorithm.variant() == xmrig::VARIANT_MSR;
return m_algorithm.variant() == xmrig::VARIANT_RWZ || m_algorithm.variant() == xmrig::VARIANT_ZLS;
}
# endif

60
src/base/tools/Chrono.h Normal file
View file

@ -0,0 +1,60 @@
/* XMRig
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef XMRIG_CHRONO_H
#define XMRIG_CHRONO_H
#include <chrono>
namespace xmrig {
class Chrono
{
public:
static inline uint64_t steadyMSecs()
{
using namespace std::chrono;
if (high_resolution_clock::is_steady) {
return static_cast<uint64_t>(time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count());
}
return static_cast<uint64_t>(time_point_cast<milliseconds>(steady_clock::now()).time_since_epoch().count());
}
static inline uint64_t currentMSecsSinceEpoch()
{
using namespace std::chrono;
return static_cast<uint64_t>(time_point_cast<milliseconds>(system_clock::now()).time_since_epoch().count());
}
};
} /* namespace xmrig */
#endif /* XMRIG_CHRONO_H */

View file

@ -29,6 +29,9 @@
#include <stdint.h>
#include "rapidjson/fwd.h"
namespace xmrig {
@ -43,7 +46,8 @@ public:
virtual ~IClientListener() = default;
virtual void onClose(Client *client, int failures) = 0;
virtual void onJobReceived(Client *client, const Job &job) = 0;
virtual void onJobReceived(Client *client, const Job &job, const rapidjson::Value &params) = 0;
virtual void onLogin(Client *client, rapidjson::Document &doc, rapidjson::Value &params) = 0;
virtual void onLoginSuccess(Client *client) = 0;
virtual void onResultAccepted(Client *client, const SubmitResult &result, const char *error) = 0;
};

View file

@ -117,6 +117,8 @@ public:
TlsCiphersKey = 1112,
TlsCipherSuitesKey = 1113,
TlsProtocolsKey = 1114,
AlgoExtKey = 1115,
ProxyPasswordKey = 1116,
// xmrig nvidia
CudaMaxThreadsKey = 1200,

View file

@ -252,7 +252,7 @@ int64_t xmrig::Client::submit(const JobResult &result)
params.AddMember("nonce", StringRef(nonce), allocator);
params.AddMember("result", StringRef(data), allocator);
if (m_extensions & AlgoExt) {
if ((m_extensions & AlgoExt) && result.algorithm.isValid()) {
params.AddMember("algo", StringRef(result.algorithm.shortName()), allocator);
}
@ -643,6 +643,8 @@ void xmrig::Client::login()
params.AddMember("algo", algo, allocator);
}
m_listener->onLogin(this, doc, params);
doc.AddMember("params", params, allocator);
send(doc);
@ -750,7 +752,7 @@ void xmrig::Client::parseNotification(const char *method, const rapidjson::Value
if (strcmp(method, "job") == 0) {
int code = -1;
if (parseJob(params, &code)) {
m_listener->onJobReceived(this, m_job);
m_listener->onJobReceived(this, m_job, params);
}
return;
@ -799,7 +801,7 @@ void xmrig::Client::parseResponse(int64_t id, const rapidjson::Value &result, co
m_failures = 0;
m_listener->onLoginSuccess(this);
m_listener->onJobReceived(this, m_job);
m_listener->onJobReceived(this, m_job, result["job"]);
return;
}

View file

@ -58,18 +58,19 @@ public:
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 Algorithm &algorithm() const { return m_algorithm; }
inline const Id &clientId() const { return m_clientId; }
inline const Id &id() const { return m_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 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 uint64_t height() const { return m_height; }
inline uint64_t target() const { return m_target; }
inline uint8_t fixedByte() const { return *(m_blob + 42); }
inline void reset() { m_size = 0; m_diff = 0; }
inline void setClientId(const Id &id) { m_clientId = id; }
inline void setPoolId(int poolId) { m_poolId = poolId; }
@ -79,6 +80,7 @@ public:
# ifdef XMRIG_PROXY_PROJECT
inline char *rawBlob() { return m_rawBlob; }
inline const char *rawBlob() const { return m_rawBlob; }
inline const char *rawTarget() const { return m_rawTarget; }
# endif

View file

@ -150,7 +150,7 @@ void xmrig::FailoverStrategy::onClose(Client *client, int failures)
}
void xmrig::FailoverStrategy::onJobReceived(Client *client, const Job &job)
void xmrig::FailoverStrategy::onJobReceived(Client *client, const Job &job, const rapidjson::Value &)
{
if (m_active == client->id()) {
m_listener->onJob(this, client, job);

View file

@ -61,8 +61,10 @@ public:
void tick(uint64_t now) override;
protected:
inline void onLogin(Client *, rapidjson::Document &, rapidjson::Value &) override {}
void onClose(Client *client, int failures) override;
void onJobReceived(Client *client, const Job &job) override;
void onJobReceived(Client *client, const Job &job, const rapidjson::Value &params) override;
void onLoginSuccess(Client *client) override;
void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override;

View file

@ -98,7 +98,7 @@ void xmrig::SinglePoolStrategy::onClose(Client *, int)
}
void xmrig::SinglePoolStrategy::onJobReceived(Client *client, const Job &job)
void xmrig::SinglePoolStrategy::onJobReceived(Client *client, const Job &job, const rapidjson::Value &)
{
m_listener->onJob(this, client, job);
}

View file

@ -55,8 +55,10 @@ public:
void tick(uint64_t now) override;
protected:
inline void onLogin(Client *, rapidjson::Document &, rapidjson::Value &) override {}
void onClose(Client *client, int failures) override;
void onJobReceived(Client *client, const Job &job) override;
void onJobReceived(Client *client, const Job &job, const rapidjson::Value &params) override;
void onLoginSuccess(Client *client) override;
void onResultAccepted(Client *client, const SubmitResult &result, const char *error) override;

View file

@ -215,6 +215,32 @@ template<> inline constexpr Variant cn_base_variant<VARIANT_ZLS>() { return V
template<> inline constexpr Variant cn_base_variant<VARIANT_DOUBLE>() { return VARIANT_2; }
inline Variant cn_base_variant(Variant variant)
{
switch (variant) {
case VARIANT_0:
case VARIANT_XHV:
case VARIANT_XAO:
return VARIANT_0;
case VARIANT_1:
case VARIANT_TUBE:
case VARIANT_XTL:
case VARIANT_MSR:
case VARIANT_RTO:
return VARIANT_1;
case VARIANT_GPU:
return VARIANT_GPU;
default:
break;
}
return VARIANT_2;
}
template<Variant variant> inline constexpr bool cn_is_cryptonight_r() { return false; }
template<> inline constexpr bool cn_is_cryptonight_r<VARIANT_WOW>() { return true; }
template<> inline constexpr bool cn_is_cryptonight_r<VARIANT_4>() { return true; }