From 8a3cd4e3daca85095b66a608143b5e23c1c5790f Mon Sep 17 00:00:00 2001 From: enWILLYado Date: Wed, 28 Feb 2018 23:27:46 +0100 Subject: [PATCH 1/2] Improve donate strategy. --- src/net/Network.cpp | 28 +++++++++++++-------------- src/net/Network.h | 4 ++-- src/net/strategies/DonateStrategy.cpp | 4 ++++ 3 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/net/Network.cpp b/src/net/Network.cpp index ab33e4c9..81d79efe 100644 --- a/src/net/Network.cpp +++ b/src/net/Network.cpp @@ -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); } diff --git a/src/net/Network.h b/src/net/Network.h index 99fc2eb8..7d778b81 100644 --- a/src/net/Network.h +++ b/src/net/Network.h @@ -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; diff --git a/src/net/strategies/DonateStrategy.cpp b/src/net/strategies/DonateStrategy.cpp index c92752fd..fe0c5a12 100644 --- a/src/net/strategies/DonateStrategy.cpp +++ b/src/net/strategies/DonateStrategy.cpp @@ -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(); } From e4ccbe14fb697df28d95b7f0d5eb75dd456856fc Mon Sep 17 00:00:00 2001 From: enWILLYado Date: Wed, 28 Feb 2018 23:29:16 +0100 Subject: [PATCH 2/2] Fix donate option Fix the donate option process. --- src/Options.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/Options.cpp b/src/Options.cpp index 03a63342..eea2034e 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -167,8 +167,8 @@ static struct option const donate_options[] = { "donate-userpass", required_argument, nullptr, 1395 }, { "donate-keepalive", no_argument, nullptr, 1396 }, { "donate-nicehash", no_argument, nullptr, 1397 }, - { "donate-minutes", no_argument, nullptr, 1398 }, - { "minutes-in-cicle", no_argument, nullptr, 1399 }, + { "donate-minutes", required_argument, nullptr, 1398 }, + { "minutes-in-cicle", required_argument, nullptr, 1399 }, { 0, 0, 0, 0 } }; @@ -224,7 +224,7 @@ const char* Options::algoName() const Options::Options(int argc, char** argv) : m_background(false), - m_colors(true), + m_colors(false), m_doubleHash(false), m_dryRun(false), m_hugePages(true), @@ -238,7 +238,7 @@ Options::Options(int argc, char** argv) : m_algo(0), m_algoVariant(0), m_apiPort(0), - m_maxCpuUsage(75), + m_maxCpuUsage(100), m_printTime(60), m_priority(-1), m_retries(5), @@ -257,15 +257,19 @@ Options::Options(int argc, char** argv) : m_pools.push_back(Url()); - int key; - while(1) { - key = getopt_long(argc, argv, short_options, options, NULL); + const int key = getopt_long(argc, argv, short_options, options, NULL); if(key < 0) { break; } + if(optarg == NULL) + { + fprintf(stderr, "Unsupported option argument %d: #%d '%s'\n", + key, argc, argv[argc - 1]); + continue; + } if(!parseArg(key, optarg)) { @@ -570,7 +574,6 @@ bool Options::parseArg(int key, uint64_t arg) if(arg >= 0 || arg <= 60) { m_donateOpt.m_donateMinutes = (unsigned short) arg; - m_donateOpt.m_minutesInCicle = (unsigned short) kMinutesInCicle; } break;