mirror of
https://github.com/xmrig/xmrig.git
synced 2025-01-10 21:04:37 +00:00
Implemented SinglePoolStrategy.
This commit is contained in:
parent
bd8776b7ee
commit
25faeabd61
10 changed files with 98 additions and 22 deletions
|
@ -120,7 +120,7 @@ else()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_definitions(/DUNICODE)
|
add_definitions(/DUNICODE)
|
||||||
add_definitions(/DAPP_DEBUG)
|
#add_definitions(/DAPP_DEBUG)
|
||||||
|
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake")
|
||||||
|
|
||||||
|
|
|
@ -25,12 +25,17 @@
|
||||||
#define __ISTRATEGY_H__
|
#define __ISTRATEGY_H__
|
||||||
|
|
||||||
|
|
||||||
|
class JobResult;
|
||||||
|
|
||||||
|
|
||||||
class IStrategy
|
class IStrategy
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~IStrategy() {}
|
virtual ~IStrategy() {}
|
||||||
|
|
||||||
virtual void connect() = 0;
|
virtual bool isActive() const = 0;
|
||||||
|
virtual void connect() = 0;
|
||||||
|
virtual void submit(const JobResult &result) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -25,10 +25,19 @@
|
||||||
#define __ISTRATEGYLISTENER_H__
|
#define __ISTRATEGYLISTENER_H__
|
||||||
|
|
||||||
|
|
||||||
|
class Client;
|
||||||
|
class IStrategy;
|
||||||
|
class Job;
|
||||||
|
|
||||||
|
|
||||||
class IStrategyListener
|
class IStrategyListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~IStrategyListener() {}
|
virtual ~IStrategyListener() {}
|
||||||
|
|
||||||
|
virtual void onActive(Client *client) = 0;
|
||||||
|
virtual void onJob(Client *client, const Job &job) = 0;
|
||||||
|
virtual void onPause(IStrategy *strategy) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -69,8 +69,19 @@ void Network::connect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Network::onClose(Client *client, int failures)
|
void Network::onActive(Client *client)
|
||||||
{
|
{
|
||||||
|
if (client->id() == -1) {
|
||||||
|
LOG_NOTICE("dev donate started");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_INFO(m_options->colors() ? "\x1B[01;37muse pool: \x1B[01;36m%s:%d" : "use pool: %s:%d", client->host(), client->port());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//void Network::onClose(Client *client, int failures)
|
||||||
|
//{
|
||||||
// const int id = client->id();
|
// const int id = client->id();
|
||||||
// if (id == 0) {
|
// if (id == 0) {
|
||||||
// if (failures == -1) {
|
// if (failures == -1) {
|
||||||
|
@ -88,12 +99,12 @@ void Network::onClose(Client *client, int failures)
|
||||||
// if (id == 1 && m_pools.size() > 2 && failures == m_options->retries()) {
|
// if (id == 1 && m_pools.size() > 2 && failures == m_options->retries()) {
|
||||||
// m_pools[2]->connect();
|
// m_pools[2]->connect();
|
||||||
// }
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
|
|
||||||
void Network::onJobReceived(Client *client, const Job &job)
|
void Network::onJob(Client *client, const Job &job)
|
||||||
{
|
{
|
||||||
if (m_donateActive && client->id() != 0) {
|
if (m_donate && m_donate->isActive() && client->id() != -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,19 +114,18 @@ void Network::onJobReceived(Client *client, const Job &job)
|
||||||
|
|
||||||
void Network::onJobResult(const JobResult &result)
|
void Network::onJobResult(const JobResult &result)
|
||||||
{
|
{
|
||||||
// if (m_options->colors()) {
|
LOG_NOTICE(m_options->colors() ? "\x1B[01;32mSHARE FOUND" : "SHARE FOUND");
|
||||||
// LOG_NOTICE("\x1B[01;32mSHARE FOUND");
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// LOG_NOTICE("SHARE FOUND");
|
|
||||||
// }
|
|
||||||
|
|
||||||
// m_pools[result.poolId]->submit(result);
|
if (result.poolId == -1 && m_donate) {
|
||||||
|
return m_donate->submit(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_strategy->submit(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Network::onLoginSuccess(Client *client)
|
//void Network::onLoginSuccess(Client *client)
|
||||||
{
|
//{
|
||||||
// const int id = client->id();
|
// const int id = client->id();
|
||||||
// if (id == 0) {
|
// if (id == 0) {
|
||||||
// return startDonate();
|
// return startDonate();
|
||||||
|
@ -132,6 +142,15 @@ void Network::onLoginSuccess(Client *client)
|
||||||
// if (m_pool == 1 && m_pools.size() > 2) { // try disconnect from backup pool
|
// if (m_pool == 1 && m_pools.size() > 2) { // try disconnect from backup pool
|
||||||
// m_pools[2]->disconnect();
|
// m_pools[2]->disconnect();
|
||||||
// }
|
// }
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
void Network::onPause(IStrategy *strategy)
|
||||||
|
{
|
||||||
|
if ((m_donate && !m_donate->isActive()) || !m_strategy->isActive()) {
|
||||||
|
LOG_ERR("no active pools, pause mining");
|
||||||
|
Workers::pause();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ class Options;
|
||||||
class Url;
|
class Url;
|
||||||
|
|
||||||
|
|
||||||
class Network : public IClientListener, public IJobResultListener, public IStrategyListener
|
class Network : public IJobResultListener, public IStrategyListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Network(const Options *options);
|
Network(const Options *options);
|
||||||
|
@ -50,10 +50,10 @@ public:
|
||||||
static char *userAgent();
|
static char *userAgent();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void onClose(Client *client, int failures) override;
|
void onActive(Client *client) override;
|
||||||
void onJobReceived(Client *client, const Job &job) override;
|
void onJob(Client *client, const Job &job) override;
|
||||||
void onJobResult(const JobResult &result) override;
|
void onJobResult(const JobResult &result) override;
|
||||||
void onLoginSuccess(Client *client) override;
|
void onPause(IStrategy *strategy) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void addPool(const Url *url);
|
void addPool(const Url *url);
|
||||||
|
|
|
@ -22,12 +22,14 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "interfaces/IStrategyListener.h"
|
||||||
#include "net/Client.h"
|
#include "net/Client.h"
|
||||||
#include "net/strategies/DonateStrategy.h"
|
#include "net/strategies/DonateStrategy.h"
|
||||||
#include "Options.h"
|
#include "Options.h"
|
||||||
|
|
||||||
|
|
||||||
DonateStrategy::DonateStrategy(const char *agent, IStrategyListener *listener) :
|
DonateStrategy::DonateStrategy(const char *agent, IStrategyListener *listener) :
|
||||||
|
m_active(false),
|
||||||
m_listener(listener)
|
m_listener(listener)
|
||||||
{
|
{
|
||||||
Url *url = new Url("donate.xmrig.com", Options::i()->algo() == Options::ALGO_CRYPTONIGHT_LITE ? 3333 : 443, Options::i()->pools().front()->user());
|
Url *url = new Url("donate.xmrig.com", Options::i()->algo() == Options::ALGO_CRYPTONIGHT_LITE ? 3333 : 443, Options::i()->pools().front()->user());
|
||||||
|
@ -45,11 +47,23 @@ DonateStrategy::DonateStrategy(const char *agent, IStrategyListener *listener) :
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool DonateStrategy::isActive() const
|
||||||
|
{
|
||||||
|
return m_active;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void DonateStrategy::connect()
|
void DonateStrategy::connect()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DonateStrategy::submit(const JobResult &result)
|
||||||
|
{
|
||||||
|
m_client->submit(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void DonateStrategy::onClose(Client *client, int failures)
|
void DonateStrategy::onClose(Client *client, int failures)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -58,12 +72,14 @@ void DonateStrategy::onClose(Client *client, int failures)
|
||||||
|
|
||||||
void DonateStrategy::onJobReceived(Client *client, const Job &job)
|
void DonateStrategy::onJobReceived(Client *client, const Job &job)
|
||||||
{
|
{
|
||||||
|
m_listener->onJob(client, job);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DonateStrategy::onLoginSuccess(Client *client)
|
void DonateStrategy::onLoginSuccess(Client *client)
|
||||||
{
|
{
|
||||||
|
m_active = true;
|
||||||
|
m_listener->onActive(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,9 @@ public:
|
||||||
DonateStrategy(const char *agent, IStrategyListener *listener);
|
DonateStrategy(const char *agent, IStrategyListener *listener);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
bool isActive() const override;
|
||||||
void connect() override;
|
void connect() override;
|
||||||
|
void submit(const JobResult &result) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void onClose(Client *client, int failures) override;
|
void onClose(Client *client, int failures) override;
|
||||||
|
@ -53,6 +55,7 @@ protected:
|
||||||
private:
|
private:
|
||||||
static void onTimer(uv_timer_t *handle);
|
static void onTimer(uv_timer_t *handle);
|
||||||
|
|
||||||
|
bool m_active;
|
||||||
Client *m_client;
|
Client *m_client;
|
||||||
IStrategyListener *m_listener;
|
IStrategyListener *m_listener;
|
||||||
uv_timer_t m_timer;
|
uv_timer_t m_timer;
|
||||||
|
|
|
@ -22,12 +22,14 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "interfaces/IStrategyListener.h"
|
||||||
#include "net/Client.h"
|
#include "net/Client.h"
|
||||||
#include "net/strategies/SinglePoolStrategy.h"
|
#include "net/strategies/SinglePoolStrategy.h"
|
||||||
#include "Options.h"
|
#include "Options.h"
|
||||||
|
|
||||||
|
|
||||||
SinglePoolStrategy::SinglePoolStrategy(const Url *url, const char *agent, IStrategyListener *listener) :
|
SinglePoolStrategy::SinglePoolStrategy(const Url *url, const char *agent, IStrategyListener *listener) :
|
||||||
|
m_active(false),
|
||||||
m_listener(listener)
|
m_listener(listener)
|
||||||
{
|
{
|
||||||
m_client = new Client(0, agent, this);
|
m_client = new Client(0, agent, this);
|
||||||
|
@ -36,24 +38,43 @@ SinglePoolStrategy::SinglePoolStrategy(const Url *url, const char *agent, IStrat
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool SinglePoolStrategy::isActive() const
|
||||||
|
{
|
||||||
|
return m_active;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SinglePoolStrategy::connect()
|
void SinglePoolStrategy::connect()
|
||||||
{
|
{
|
||||||
m_client->connect();
|
m_client->connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SinglePoolStrategy::submit(const JobResult &result)
|
||||||
|
{
|
||||||
|
m_client->submit(result);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SinglePoolStrategy::onClose(Client *client, int failures)
|
void SinglePoolStrategy::onClose(Client *client, int failures)
|
||||||
{
|
{
|
||||||
|
if (!isActive()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_active = false;
|
||||||
|
m_listener->onPause(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SinglePoolStrategy::onJobReceived(Client *client, const Job &job)
|
void SinglePoolStrategy::onJobReceived(Client *client, const Job &job)
|
||||||
{
|
{
|
||||||
|
m_listener->onJob(client, job);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SinglePoolStrategy::onLoginSuccess(Client *client)
|
void SinglePoolStrategy::onLoginSuccess(Client *client)
|
||||||
{
|
{
|
||||||
|
m_active = true;
|
||||||
|
m_listener->onActive(client);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,9 @@ public:
|
||||||
SinglePoolStrategy(const Url *url, const char *agent, IStrategyListener *listener);
|
SinglePoolStrategy(const Url *url, const char *agent, IStrategyListener *listener);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
bool isActive() const override;
|
||||||
void connect() override;
|
void connect() override;
|
||||||
|
void submit(const JobResult &result) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void onClose(Client *client, int failures) override;
|
void onClose(Client *client, int failures) override;
|
||||||
|
@ -48,6 +50,7 @@ protected:
|
||||||
void onLoginSuccess(Client *client) override;
|
void onLoginSuccess(Client *client) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool m_active;
|
||||||
Client *m_client;
|
Client *m_client;
|
||||||
IStrategyListener *m_listener;
|
IStrategyListener *m_listener;
|
||||||
};
|
};
|
||||||
|
|
|
@ -50,7 +50,7 @@ public:
|
||||||
static inline bool isOutdated(uint64_t sequence) { return m_sequence.load(std::memory_order_relaxed) != sequence; }
|
static inline bool isOutdated(uint64_t sequence) { return m_sequence.load(std::memory_order_relaxed) != sequence; }
|
||||||
static inline bool isPaused() { return m_paused.load(std::memory_order_relaxed) == 1; }
|
static inline bool isPaused() { return m_paused.load(std::memory_order_relaxed) == 1; }
|
||||||
static inline uint64_t sequence() { return m_sequence.load(std::memory_order_relaxed); }
|
static inline uint64_t sequence() { return m_sequence.load(std::memory_order_relaxed); }
|
||||||
static inline void pause() { m_paused = 1; }
|
static inline void pause() { m_paused = 1; m_sequence++; }
|
||||||
static inline void setListener(IJobResultListener *listener) { m_listener = listener; }
|
static inline void setListener(IJobResultListener *listener) { m_listener = listener; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in a new issue