Improve donate strategy.

This commit is contained in:
enWILLYado 2018-02-28 23:27:46 +01:00
parent 2e24f226a2
commit 8a3cd4e3da
3 changed files with 19 additions and 17 deletions

View file

@ -101,7 +101,6 @@ void Network::onActive(Client* client)
{
if(client->id() == -1)
{
LOG_NOTICE("dev donate started");
return;
}
@ -113,7 +112,19 @@ void Network::onActive(Client* client)
void Network::onJob(Client* client, const Job & job)
{
if(m_donate && m_donate->isActive() && client->id() != -1)
if(m_options->colors())
{
/*
LOG_INFO("\x1B[01;35mnew job\x1B[0m from \x1B[01;37m%s:%d\x1B[0m diff \x1B[01;37m%d", client->host(),
client->port(), job.diff());
*/
}
else
{
LOG_INFO("new job from " << client->host() << ":" << client->port() << " diff " << job.diff());
}
if(m_donate && m_donate->isActive() && client->id() != -1 && !m_donate->reschedule())
{
return;
}
@ -138,7 +149,6 @@ void Network::onPause(IStrategy* strategy)
{
if(m_donate && m_donate == strategy)
{
LOG_NOTICE("dev donate finished");
m_strategy->resume();
}
@ -194,18 +204,6 @@ void Network::onResultAccepted(Client* client, const SubmitResult & result, cons
void Network::setJob(Client* client, const Job & job)
{
if(m_options->colors())
{
/*
LOG_INFO("\x1B[01;35mnew job\x1B[0m from \x1B[01;37m%s:%d\x1B[0m diff \x1B[01;37m%d", client->host(),
client->port(), job.diff());
*/
}
else
{
LOG_INFO("new job from " << client->host() << ":" << client->port() << " diff " << job.diff());
}
m_state.diff = job.diff();
Workers::setJob(job);
}

View file

@ -33,7 +33,7 @@
#include "interfaces/IJobResultListener.h"
#include "interfaces/IStrategyListener.h"
class DonateStrategy;
class IStrategy;
class Options;
class Url;
@ -67,7 +67,7 @@ private:
static void onTick(uv_timer_t* handle);
const Options* m_options;
IStrategy* m_donate;
DonateStrategy* m_donate;
IStrategy* m_strategy;
NetworkState m_state;
uv_timer_t m_timer;

View file

@ -24,6 +24,7 @@
#include "interfaces/IStrategyListener.h"
#include "net/Client.h"
#include "log/Log.h"
#include "net/strategies/DonateStrategy.h"
#include "Options.h"
@ -124,6 +125,8 @@ void DonateStrategy::stop()
m_suspended = true;
m_donateTicks = 0;
m_client->disconnect();
LOG_NOTICE("dev donate finished");
}
@ -140,6 +143,7 @@ void DonateStrategy::tick(uint64_t now)
if(m_ticks == m_target)
{
LOG_NOTICE("dev donate start");
m_client->connect();
}