Sync changes.

This commit is contained in:
XMRig 2019-02-08 16:55:21 +07:00
parent a6a0fb965a
commit 1a2aaf210c
10 changed files with 107 additions and 45 deletions

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -21,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 __ISTRATEGY_H__ #ifndef XMRIG_ISTRATEGY_H
#define __ISTRATEGY_H__ #define XMRIG_ISTRATEGY_H
#include <stdint.h> #include <stdint.h>
@ -31,6 +32,11 @@
class JobResult; class JobResult;
namespace xmrig {
class Algorithm;
}
class IStrategy class IStrategy
{ {
public: public:
@ -40,9 +46,10 @@ public:
virtual int64_t submit(const JobResult &result) = 0; virtual int64_t submit(const JobResult &result) = 0;
virtual void connect() = 0; virtual void connect() = 0;
virtual void resume() = 0; virtual void resume() = 0;
virtual void setAlgo(const xmrig::Algorithm &algo) = 0;
virtual void stop() = 0; virtual void stop() = 0;
virtual void tick(uint64_t now) = 0; virtual void tick(uint64_t now) = 0;
}; };
#endif // __ISTRATEGY_H__ #endif // XMRIG_ISTRATEGY_H

View file

@ -203,10 +203,10 @@ rapidjson::Value Pool::toJSON(rapidjson::Document &doc) const
Value obj(kObjectType); Value obj(kObjectType);
obj.AddMember("url", StringRef(url()), allocator); obj.AddMember("url", m_url.toJSON(), allocator);
obj.AddMember("user", StringRef(user()), allocator); obj.AddMember("user", m_user.toJSON(), allocator);
obj.AddMember("pass", StringRef(password()), allocator); obj.AddMember("pass", m_password.toJSON(), allocator);
obj.AddMember("rig-id", rigId() ? Value(StringRef(rigId())).Move() : Value(kNullType).Move(), allocator); obj.AddMember("rig-id", m_rigId.toJSON(), allocator);
# ifndef XMRIG_PROXY_PROJECT # ifndef XMRIG_PROXY_PROJECT
obj.AddMember("nicehash", isNicehash(), allocator); obj.AddMember("nicehash", isNicehash(), allocator);
@ -223,17 +223,20 @@ rapidjson::Value Pool::toJSON(rapidjson::Document &doc) const
case xmrig::VARIANT_AUTO: case xmrig::VARIANT_AUTO:
case xmrig::VARIANT_0: case xmrig::VARIANT_0:
case xmrig::VARIANT_1: case xmrig::VARIANT_1:
case xmrig::VARIANT_2:
obj.AddMember("variant", m_algorithm.variant(), allocator); obj.AddMember("variant", m_algorithm.variant(), allocator);
break; break;
case xmrig::VARIANT_2:
obj.AddMember("variant", 2, allocator);
break;
default: default:
obj.AddMember("variant", StringRef(m_algorithm.variantName()), allocator); obj.AddMember("variant", StringRef(m_algorithm.variantName()), allocator);
break; break;
} }
obj.AddMember("tls", isTLS(), allocator); obj.AddMember("tls", isTLS(), allocator);
obj.AddMember("tls-fingerprint", fingerprint() ? Value(StringRef(fingerprint())).Move() : Value(kNullType).Move(), allocator); obj.AddMember("tls-fingerprint", m_fingerprint.toJSON(), allocator);
return obj; return obj;
} }

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -76,6 +77,14 @@ void FailoverStrategy::resume()
} }
void FailoverStrategy::setAlgo(const xmrig::Algorithm &algo)
{
for (Client *client : m_pools) {
client->setAlgo(algo);
}
}
void FailoverStrategy::stop() void FailoverStrategy::stop()
{ {
for (size_t i = 0; i < m_pools.size(); ++i) { for (size_t i = 0; i < m_pools.size(); ++i) {

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -21,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 __FAILOVERSTRATEGY_H__ #ifndef XMRIG_FAILOVERSTRATEGY_H
#define __FAILOVERSTRATEGY_H__ #define XMRIG_FAILOVERSTRATEGY_H
#include <vector> #include <vector>
@ -42,7 +43,7 @@ class FailoverStrategy : public IStrategy, public IClientListener
{ {
public: public:
FailoverStrategy(const std::vector<Pool> &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet = false); FailoverStrategy(const std::vector<Pool> &urls, int retryPause, int retries, IStrategyListener *listener, bool quiet = false);
~FailoverStrategy(); ~FailoverStrategy() override;
public: public:
inline bool isActive() const override { return m_active >= 0; } inline bool isActive() const override { return m_active >= 0; }
@ -50,6 +51,7 @@ public:
int64_t submit(const JobResult &result) override; int64_t submit(const JobResult &result) override;
void connect() override; void connect() override;
void resume() override; void resume() override;
void setAlgo(const xmrig::Algorithm &algo) override;
void stop() override; void stop() override;
void tick(uint64_t now) override; void tick(uint64_t now) override;
@ -71,4 +73,4 @@ private:
std::vector<Client*> m_pools; std::vector<Client*> m_pools;
}; };
#endif /* __FAILOVERSTRATEGY_H__ */ #endif /* XMRIG_FAILOVERSTRATEGY_H */

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -68,6 +69,12 @@ void SinglePoolStrategy::resume()
} }
void SinglePoolStrategy::setAlgo(const xmrig::Algorithm &algo)
{
m_client->setAlgo(algo);
}
void SinglePoolStrategy::stop() void SinglePoolStrategy::stop()
{ {
m_client->disconnect(); m_client->disconnect();

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -21,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 __SINGLEPOOLSTRATEGY_H__ #ifndef XMRIG_SINGLEPOOLSTRATEGY_H
#define __SINGLEPOOLSTRATEGY_H__ #define XMRIG_SINGLEPOOLSTRATEGY_H
#include "common/interfaces/IClientListener.h" #include "common/interfaces/IClientListener.h"
@ -31,14 +32,14 @@
class Client; class Client;
class IStrategyListener; class IStrategyListener;
class Url; class Pool;
class SinglePoolStrategy : public IStrategy, public IClientListener class SinglePoolStrategy : public IStrategy, public IClientListener
{ {
public: public:
SinglePoolStrategy(const Pool &pool, int retryPause, int retries, IStrategyListener *listener, bool quiet = false); SinglePoolStrategy(const Pool &pool, int retryPause, int retries, IStrategyListener *listener, bool quiet = false);
~SinglePoolStrategy(); ~SinglePoolStrategy() override;
public: public:
inline bool isActive() const override { return m_active; } inline bool isActive() const override { return m_active; }
@ -46,6 +47,7 @@ public:
int64_t submit(const JobResult &result) override; int64_t submit(const JobResult &result) override;
void connect() override; void connect() override;
void resume() override; void resume() override;
void setAlgo(const xmrig::Algorithm &algo) override;
void stop() override; void stop() override;
void tick(uint64_t now) override; void tick(uint64_t now) override;
@ -61,4 +63,4 @@ private:
IStrategyListener *m_listener; IStrategyListener *m_listener;
}; };
#endif /* __SINGLEPOOLSTRATEGY_H__ */ #endif /* XMRIG_SINGLEPOOLSTRATEGY_H */

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -154,12 +155,12 @@ void Network::onResultAccepted(IStrategy *strategy, Client *client, const Submit
m_state.add(result, error); m_state.add(result, error);
if (error) { if (error) {
LOG_INFO(isColors() ? "\x1B[01;31mrejected\x1B[0m (%" PRId64 "/%" PRId64 ") diff \x1B[01;37m%u\x1B[0m \x1B[31m\"%s\"\x1B[0m \x1B[01;30m(%" PRIu64 " ms)" LOG_INFO(isColors() ? "\x1B[1;31mrejected\x1B[0m (%" PRId64 "/%" PRId64 ") diff \x1B[1;37m%u\x1B[0m \x1B[31m\"%s\"\x1B[0m \x1B[1;30m(%" PRIu64 " ms)"
: "rejected (%" PRId64 "/%" PRId64 ") diff %u \"%s\" (%" PRIu64 " ms)", : "rejected (%" PRId64 "/%" PRId64 ") diff %u \"%s\" (%" PRIu64 " ms)",
m_state.accepted, m_state.rejected, result.diff, error, result.elapsed); m_state.accepted, m_state.rejected, result.diff, error, result.elapsed);
} }
else { else {
LOG_INFO(isColors() ? "\x1B[01;32maccepted\x1B[0m (%" PRId64 "/%" PRId64 ") diff \x1B[01;37m%u\x1B[0m \x1B[01;30m(%" PRIu64 " ms)" LOG_INFO(isColors() ? "\x1B[1;32maccepted\x1B[0m (%" PRId64 "/%" PRId64 ") diff \x1B[1;37m%u\x1B[0m \x1B[1;30m(%" PRIu64 " ms)"
: "accepted (%" PRId64 "/%" PRId64 ") diff %u (%" PRIu64 " ms)", : "accepted (%" PRId64 "/%" PRId64 ") diff %u (%" PRIu64 " ms)",
m_state.accepted, m_state.rejected, result.diff, result.elapsed); m_state.accepted, m_state.rejected, result.diff, result.elapsed);
} }
@ -178,6 +179,10 @@ void Network::setJob(Client *client, const Job &job, bool donate)
: "new job from %s:%d diff %d algo %s", : "new job from %s:%d diff %d algo %s",
client->host(), client->port(), job.diff(), job.algorithm().shortName()); client->host(), client->port(), job.diff(), job.algorithm().shortName());
if (!donate && m_donate) {
m_donate->setAlgo(job.algorithm());
}
m_state.diff = job.diff(); m_state.diff = job.diff();
Workers::setJob(job, donate); Workers::setJob(job, donate);
} }

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -21,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 __NETWORK_H__ #ifndef XMRIG_NETWORK_H
#define __NETWORK_H__ #define XMRIG_NETWORK_H
#include <vector> #include <vector>
@ -47,7 +48,7 @@ class Network : public IJobResultListener, public IStrategyListener
{ {
public: public:
Network(xmrig::Controller *controller); Network(xmrig::Controller *controller);
~Network(); ~Network() override;
void connect(); void connect();
void stop(); void stop();
@ -76,4 +77,4 @@ private:
}; };
#endif /* __NETWORK_H__ */ #endif /* XMRIG_NETWORK_H */

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -43,7 +44,9 @@ DonateStrategy::DonateStrategy(int level, const char *user, xmrig::Algo algo, IS
m_donateTime(level * 60 * 1000), m_donateTime(level * 60 * 1000),
m_idleTime((100 - level) * 60 * 1000), m_idleTime((100 - level) * 60 * 1000),
m_strategy(nullptr), m_strategy(nullptr),
m_listener(listener) m_listener(listener),
m_now(0),
m_stop(0)
{ {
uint8_t hash[200]; uint8_t hash[200];
char userId[65] = { 0 }; char userId[65] = { 0 };
@ -93,6 +96,12 @@ void DonateStrategy::connect()
} }
void DonateStrategy::setAlgo(const xmrig::Algorithm &algo)
{
m_strategy->setAlgo(algo);
}
void DonateStrategy::stop() void DonateStrategy::stop()
{ {
uv_timer_stop(&m_timer); uv_timer_stop(&m_timer);
@ -102,7 +111,14 @@ void DonateStrategy::stop()
void DonateStrategy::tick(uint64_t now) void DonateStrategy::tick(uint64_t now)
{ {
m_now = now;
m_strategy->tick(now); m_strategy->tick(now);
if (m_stop && now > m_stop) {
m_strategy->stop();
m_stop = 0;
}
} }
@ -119,7 +135,9 @@ void DonateStrategy::onActive(IStrategy *strategy, Client *client)
void DonateStrategy::onJob(IStrategy *strategy, Client *client, const Job &job) void DonateStrategy::onJob(IStrategy *strategy, Client *client, const Job &job)
{ {
if (isActive()) {
m_listener->onJob(this, client, job); m_listener->onJob(this, client, job);
}
} }
@ -142,7 +160,11 @@ void DonateStrategy::idle(uint64_t timeout)
void DonateStrategy::suspend() void DonateStrategy::suspend()
{ {
m_strategy->stop(); # if defined(XMRIG_AMD_PROJECT) || defined(XMRIG_NVIDIA_PROJECT)
m_stop = m_now + 5000;
# else
m_stop = m_now + 500;
# endif
m_active = false; m_active = false;
m_listener->onPause(this); m_listener->onPause(this);

View file

@ -5,7 +5,8 @@
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet> * Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
* Copyright 2016 Jay D Dee <jayddee246@gmail.com> * Copyright 2016 Jay D Dee <jayddee246@gmail.com>
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt> * Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com> * 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 * 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 * it under the terms of the GNU General Public License as published by
@ -44,7 +45,7 @@ class DonateStrategy : public IStrategy, public IStrategyListener
{ {
public: public:
DonateStrategy(int level, const char *user, xmrig::Algo algo, IStrategyListener *listener); DonateStrategy(int level, const char *user, xmrig::Algo algo, IStrategyListener *listener);
~DonateStrategy(); ~DonateStrategy() override;
public: public:
inline bool isActive() const override { return m_active; } inline bool isActive() const override { return m_active; }
@ -52,6 +53,7 @@ public:
int64_t submit(const JobResult &result) override; int64_t submit(const JobResult &result) override;
void connect() override; void connect() override;
void setAlgo(const xmrig::Algorithm &algo) override;
void stop() override; void stop() override;
void tick(uint64_t now) override; void tick(uint64_t now) override;
@ -68,11 +70,13 @@ private:
static void onTimer(uv_timer_t *handle); static void onTimer(uv_timer_t *handle);
bool m_active; bool m_active;
const int m_donateTime; const uint64_t m_donateTime;
const int m_idleTime; const uint64_t m_idleTime;
IStrategy *m_strategy; IStrategy *m_strategy;
IStrategyListener *m_listener; IStrategyListener *m_listener;
std::vector<Pool> m_pools; std::vector<Pool> m_pools;
uint64_t m_now;
uint64_t m_stop;
uv_timer_t m_timer; uv_timer_t m_timer;
}; };