mirror of
https://github.com/xmrig/xmrig.git
synced 2024-12-23 03:59:41 +00:00
Implemented switch to donate pool.
This commit is contained in:
parent
c31ea00399
commit
1cf5ad5212
7 changed files with 80 additions and 14 deletions
|
@ -50,7 +50,7 @@ if ("${CMAKE_BUILD_TYPE}" STREQUAL "")
|
|||
set(CMAKE_BUILD_TYPE Release)
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maes -Wall")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -maes -Wall -fno-exceptions")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast -funroll-loops -fvariable-expansion-in-unroller -ftree-loop-if-convert-stores -fmerge-all-constants -fbranch-target-load-optimize2")
|
||||
#set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -gdwarf-2")
|
||||
#set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -fprofile-generate")
|
||||
|
|
|
@ -57,6 +57,7 @@ public:
|
|||
inline const char *user() const { return m_user; }
|
||||
inline const Url *backupUrl() const { return m_backupUrl; }
|
||||
inline const Url *url() const { return m_url; }
|
||||
inline int donateLevel() const { return m_donateLevel; }
|
||||
inline int retries() const { return m_retries; }
|
||||
inline int retryPause() const { return m_retryPause; }
|
||||
|
||||
|
|
|
@ -129,12 +129,16 @@ void Client::send(char *data)
|
|||
free(req);
|
||||
});
|
||||
|
||||
uv_timer_start(&m_responseTimer, [](uv_timer_t* handle) { getClient(handle->data)->close(); }, kResponseTimeout, 0);
|
||||
uv_timer_start(&m_responseTimer, [](uv_timer_t *handle) { getClient(handle->data)->close(); }, kResponseTimeout, 0);
|
||||
}
|
||||
|
||||
|
||||
void Client::setUrl(const Url *url)
|
||||
{
|
||||
if (!url || !url->isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
free(m_host);
|
||||
m_host = strdup(url->host());
|
||||
m_port = url->port();
|
||||
|
|
|
@ -22,7 +22,6 @@
|
|||
*/
|
||||
|
||||
|
||||
#include <uv.h>
|
||||
#include <memory>
|
||||
|
||||
|
||||
|
@ -41,11 +40,12 @@ Network::Network(const Options *options) :
|
|||
m_pools.reserve(2);
|
||||
m_agent = userAgent();
|
||||
|
||||
auto url = std::make_unique<Url>("donate.xmrig.com", 443);
|
||||
|
||||
addPool(url.get());
|
||||
addPool(std::make_unique<Url>().get());
|
||||
addPool(m_options->url());
|
||||
addPool(m_options->backupUrl());
|
||||
|
||||
m_timer.data = this;
|
||||
uv_timer_init(uv_default_loop(), &m_timer);
|
||||
}
|
||||
|
||||
|
||||
|
@ -61,15 +61,22 @@ Network::~Network()
|
|||
|
||||
void Network::connect()
|
||||
{
|
||||
m_pools.at(1)->connect();
|
||||
m_pools[1]->connect();
|
||||
|
||||
if (m_options->donateLevel()) {
|
||||
uv_timer_start(&m_timer, Network::onTimer, (100 - m_options->donateLevel()) * 60 * 1000, 0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void Network::onClose(Client *client, int failures)
|
||||
{
|
||||
const int id = client->id();
|
||||
if (id == 0 && failures == -1) {
|
||||
m_donate = false;
|
||||
if (id == 0) {
|
||||
if (failures == -1) {
|
||||
stopDonate();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -78,7 +85,7 @@ void Network::onClose(Client *client, int failures)
|
|||
}
|
||||
|
||||
if (id == 1 && m_pools.size() > 2 && failures == m_options->retries()) {
|
||||
m_pools.at(2)->connect();
|
||||
m_pools[2]->connect();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,12 +106,11 @@ void Network::onLoginSuccess(Client *client)
|
|||
{
|
||||
const int id = client->id();
|
||||
if (id == 0) {
|
||||
m_donate = true;
|
||||
return;
|
||||
return startDonate();
|
||||
}
|
||||
|
||||
if (id == 2 && m_pool) { // primary pool is already active
|
||||
m_pools.at(2)->disconnect();
|
||||
m_pools[2]->disconnect();
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -112,7 +118,7 @@ void Network::onLoginSuccess(Client *client)
|
|||
m_pool = id;
|
||||
|
||||
if (m_pool == 1 && m_pools.size() > 2) { // try disconnect from backup pool
|
||||
m_pools.at(2)->disconnect();
|
||||
m_pools[2]->disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -130,3 +136,44 @@ void Network::addPool(const Url *url)
|
|||
|
||||
m_pools.push_back(client);
|
||||
}
|
||||
|
||||
|
||||
void Network::startDonate()
|
||||
{
|
||||
if (m_donate) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_NOTICE("dev donate started");
|
||||
|
||||
m_donate = true;
|
||||
}
|
||||
|
||||
|
||||
void Network::stopDonate()
|
||||
{
|
||||
if (!m_donate) {
|
||||
return;
|
||||
}
|
||||
|
||||
LOG_NOTICE("dev donate finished");
|
||||
|
||||
m_donate = false;
|
||||
}
|
||||
|
||||
|
||||
void Network::onTimer(uv_timer_t *handle)
|
||||
{
|
||||
auto net = static_cast<Network*>(handle->data);
|
||||
|
||||
if (!net->m_donate) {
|
||||
auto url = std::make_unique<Url>("donate.xmrig.com", 443);
|
||||
net->m_pools[0]->connect(url.get());
|
||||
|
||||
uv_timer_start(&net->m_timer, Network::onTimer, net->m_options->donateLevel() * 60 * 1000, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
net->m_pools[0]->disconnect();
|
||||
uv_timer_start(&net->m_timer, Network::onTimer, (100 - net->m_options->donateLevel()) * 60 * 1000, 0);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
|
||||
#include <vector>
|
||||
#include <uv.h>
|
||||
|
||||
|
||||
#include "interfaces/IClientListener.h"
|
||||
|
@ -53,12 +54,17 @@ protected:
|
|||
|
||||
private:
|
||||
void addPool(const Url *url);
|
||||
void startDonate();
|
||||
void stopDonate();
|
||||
|
||||
static void onTimer(uv_timer_t *handle);
|
||||
|
||||
bool m_donate;
|
||||
char *m_agent;
|
||||
const Options *m_options;
|
||||
int m_pool;
|
||||
std::vector<Client*> m_pools;
|
||||
uv_timer_t m_timer;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -29,6 +29,13 @@
|
|||
#include "net/Url.h"
|
||||
|
||||
|
||||
Url::Url() :
|
||||
m_host(nullptr),
|
||||
m_port(3333)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief Parse url.
|
||||
*
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
class Url
|
||||
{
|
||||
public:
|
||||
Url();
|
||||
Url(const char *url);
|
||||
Url(const char *host, uint16_t port);
|
||||
~Url();
|
||||
|
|
Loading…
Reference in a new issue