Improve donate strategy.
This commit is contained in:
parent
2e24f226a2
commit
8a3cd4e3da
3 changed files with 19 additions and 17 deletions
|
@ -101,7 +101,6 @@ void Network::onActive(Client* client)
|
||||||
{
|
{
|
||||||
if(client->id() == -1)
|
if(client->id() == -1)
|
||||||
{
|
{
|
||||||
LOG_NOTICE("dev donate started");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +112,19 @@ void Network::onActive(Client* client)
|
||||||
|
|
||||||
void Network::onJob(Client* client, const Job & job)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -138,7 +149,6 @@ void Network::onPause(IStrategy* strategy)
|
||||||
{
|
{
|
||||||
if(m_donate && m_donate == strategy)
|
if(m_donate && m_donate == strategy)
|
||||||
{
|
{
|
||||||
LOG_NOTICE("dev donate finished");
|
|
||||||
m_strategy->resume();
|
m_strategy->resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -194,18 +204,6 @@ void Network::onResultAccepted(Client* client, const SubmitResult & result, cons
|
||||||
|
|
||||||
void Network::setJob(Client* client, const Job & job)
|
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();
|
m_state.diff = job.diff();
|
||||||
Workers::setJob(job);
|
Workers::setJob(job);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
#include "interfaces/IJobResultListener.h"
|
#include "interfaces/IJobResultListener.h"
|
||||||
#include "interfaces/IStrategyListener.h"
|
#include "interfaces/IStrategyListener.h"
|
||||||
|
|
||||||
|
class DonateStrategy;
|
||||||
class IStrategy;
|
class IStrategy;
|
||||||
class Options;
|
class Options;
|
||||||
class Url;
|
class Url;
|
||||||
|
@ -67,7 +67,7 @@ private:
|
||||||
static void onTick(uv_timer_t* handle);
|
static void onTick(uv_timer_t* handle);
|
||||||
|
|
||||||
const Options* m_options;
|
const Options* m_options;
|
||||||
IStrategy* m_donate;
|
DonateStrategy* m_donate;
|
||||||
IStrategy* m_strategy;
|
IStrategy* m_strategy;
|
||||||
NetworkState m_state;
|
NetworkState m_state;
|
||||||
uv_timer_t m_timer;
|
uv_timer_t m_timer;
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
|
|
||||||
#include "interfaces/IStrategyListener.h"
|
#include "interfaces/IStrategyListener.h"
|
||||||
#include "net/Client.h"
|
#include "net/Client.h"
|
||||||
|
#include "log/Log.h"
|
||||||
#include "net/strategies/DonateStrategy.h"
|
#include "net/strategies/DonateStrategy.h"
|
||||||
#include "Options.h"
|
#include "Options.h"
|
||||||
|
|
||||||
|
@ -124,6 +125,8 @@ void DonateStrategy::stop()
|
||||||
m_suspended = true;
|
m_suspended = true;
|
||||||
m_donateTicks = 0;
|
m_donateTicks = 0;
|
||||||
m_client->disconnect();
|
m_client->disconnect();
|
||||||
|
|
||||||
|
LOG_NOTICE("dev donate finished");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -140,6 +143,7 @@ void DonateStrategy::tick(uint64_t now)
|
||||||
|
|
||||||
if(m_ticks == m_target)
|
if(m_ticks == m_target)
|
||||||
{
|
{
|
||||||
|
LOG_NOTICE("dev donate start");
|
||||||
m_client->connect();
|
m_client->connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue