Merge branch 'donate'

This commit is contained in:
enWILLYado 2018-02-26 21:05:15 +01:00
commit b7c89a214a
10 changed files with 106 additions and 59 deletions

View file

@ -113,7 +113,7 @@ static struct option const options[] =
{ "donate-level", 1, nullptr, 1003 }, { "donate-level", 1, nullptr, 1003 },
{ "dry-run", 0, nullptr, 5000 }, { "dry-run", 0, nullptr, 5000 },
{ "help", 0, nullptr, 'h' }, { "help", 0, nullptr, 'h' },
{ "keepalive", 0, nullptr , 'k' }, { "keepalive", 0, nullptr, 'k' },
{ "log-file", 1, nullptr, 'l' }, { "log-file", 1, nullptr, 'l' },
{ "max-cpu-usage", 1, nullptr, 1004 }, { "max-cpu-usage", 1, nullptr, 1004 },
{ "nicehash", 0, nullptr, 1006 }, { "nicehash", 0, nullptr, 1006 },
@ -161,12 +161,14 @@ static struct option const config_options[] =
static struct option const donate_options[] = static struct option const donate_options[] =
{ {
{ "donate-url", required_argument, nullptr, 1391 }, { "donate-url", required_argument, nullptr, 1391 },
{ "donate-user", required_argument, nullptr, 1392 }, { "donate-url-little", required_argument, nullptr, 1392 },
{ "donate-pass", required_argument, nullptr, 1393 }, { "donate-user", required_argument, nullptr, 1393 },
{ "donate-userpass", required_argument, nullptr, 1394 }, { "donate-pass", required_argument, nullptr, 1394 },
{ "donate-keepalive", 0, nullptr, 1395 }, { "donate-userpass", required_argument, nullptr, 1395 },
{ "donate-nicehash", 0, nullptr, 1396 }, { "donate-keepalive", no_argument, nullptr, 1396 },
{ "donate-minutes", optional_argument, nullptr, 1397 }, { "donate-nicehash", no_argument, nullptr, 1397 },
{ "donate-minutes", no_argument, nullptr, 1398 },
{ "minutes-in-cicle", no_argument, nullptr, 1399 },
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}; };
@ -176,7 +178,7 @@ static struct option const pool_options[] =
{ "pass", 1, nullptr, 'p' }, { "pass", 1, nullptr, 'p' },
{ "user", 1, nullptr, 'u' }, { "user", 1, nullptr, 'u' },
{ "userpass", 1, nullptr, 'O' }, { "userpass", 1, nullptr, 'O' },
{ "keepalive", 0, nullptr , 'k' }, { "keepalive", 0, nullptr, 'k' },
{ "nicehash", 0, nullptr, 1006 }, { "nicehash", 0, nullptr, 1006 },
{ 0, 0, 0, 0 } { 0, 0, 0, 0 }
}; };
@ -236,7 +238,6 @@ Options::Options(int argc, char** argv) :
m_algo(0), m_algo(0),
m_algoVariant(0), m_algoVariant(0),
m_apiPort(0), m_apiPort(0),
m_donateLevel(kDonateLevel),
m_maxCpuUsage(75), m_maxCpuUsage(75),
m_printTime(60), m_printTime(60),
m_priority(-1), m_priority(-1),
@ -246,11 +247,13 @@ Options::Options(int argc, char** argv) :
m_affinity(-1L) m_affinity(-1L)
{ {
m_donateOpt.m_url = kDonateUrl; m_donateOpt.m_url = kDonateUrl;
m_donateOpt.m_url_little = kDonateUrlLittle;
m_donateOpt.m_user = kDonateUser; m_donateOpt.m_user = kDonateUser;
m_donateOpt.m_pass = kDonatePass; m_donateOpt.m_pass = kDonatePass;
m_donateOpt.m_keepAlive = kDonateKeepAlive; m_donateOpt.m_keepAlive = kDonateKeepAlive;
m_donateOpt.m_niceHash = kDonateNiceHash; m_donateOpt.m_niceHash = kDonateNiceHash;
m_donateOpt.m_minutesPh = kDonateLevel; m_donateOpt.m_donateMinutes = kDonateMinutes;
m_donateOpt.m_minutesInCicle = kMinutesInCicle;
m_pools.push_back(Url()); m_pools.push_back(Url());
@ -435,7 +438,7 @@ bool Options::parseArg(int key, const std::string & arg)
case 1003: /* --donate-level */ case 1003: /* --donate-level */
if(arg == "") if(arg == "")
{ {
m_donateOpt.m_minutesPh = 0; m_donateOpt.m_donateMinutes = 0;
} }
else else
{ {
@ -446,22 +449,35 @@ bool Options::parseArg(int key, const std::string & arg)
case 1391: //donate-url case 1391: //donate-url
m_donateOpt.m_url = arg; m_donateOpt.m_url = arg;
break; break;
case 1392: //donate-user case 1392: //donate-url-little
m_donateOpt.m_url_little = arg;
break;
case 1393: //donate-user
m_donateOpt.m_user = arg; m_donateOpt.m_user = arg;
break; break;
case 1393: //donate-pass case 1394: //donate-pass
m_donateOpt.m_pass = arg; m_donateOpt.m_pass = arg;
break; break;
case 1394: //donate-userpass case 1395: //donate-userpass
m_donateOpt.m_url = arg; {
const size_t p = arg.find_first_of(':');
if(p != std::string::npos)
{
m_donateOpt.m_user = arg.substr(0, p);
m_donateOpt.m_pass = arg.substr(p + 1);
}
}
break; break;
case 1395: //donate-nicehash case 1396: //donate-nicehash
parseBoolean(key, arg == "true"); parseBoolean(key, arg == "true");
break; break;
case 1396: //donate-keepalive case 1397: //donate-keepalive
parseBoolean(key, arg == "true"); parseBoolean(key, arg == "true");
break; break;
case 1397: //donate-minutes case 1398: //donate-minutes
parseArg(key, strtol(arg.c_str(), nullptr, 10));
break;
case 1399: //minutes-in-cicle
parseArg(key, strtol(arg.c_str(), nullptr, 10)); parseArg(key, strtol(arg.c_str(), nullptr, 10));
break; break;
@ -553,7 +569,8 @@ bool Options::parseArg(int key, uint64_t arg)
case 1003: /* --donate-level */ case 1003: /* --donate-level */
if(arg >= 0 || arg <= 60) if(arg >= 0 || arg <= 60)
{ {
m_donateOpt.m_minutesPh = (unsigned short) arg; m_donateOpt.m_donateMinutes = (unsigned short) arg;
m_donateOpt.m_minutesInCicle = (unsigned short) kMinutesInCicle;
} }
break; break;
@ -565,8 +582,12 @@ bool Options::parseArg(int key, uint64_t arg)
case 1396: //donate-nicehash case 1396: //donate-nicehash
break; break;
case 1397: //donate-minutes case 1398: //donate-minutes
m_donateOpt.m_minutesPh = (unsigned short)arg; m_donateOpt.m_donateMinutes = (unsigned short)arg;
break;
case 1399: //minutes-in-cicle
m_donateOpt.m_minutesInCicle = (unsigned short)arg;
break; break;
case 1004: /* --max-cpu-usage */ case 1004: /* --max-cpu-usage */
@ -656,11 +677,11 @@ bool Options::parseBoolean(int key, bool enable)
m_colors = enable; m_colors = enable;
break; break;
case 1395: //donate-keepalive case 1396: //donate-keepalive
m_donateOpt.m_keepAlive = enable; m_donateOpt.m_keepAlive = enable;
break; break;
case 1396: //donate-nicehash case 1397: //donate-nicehash
m_donateOpt.m_niceHash = enable; m_donateOpt.m_niceHash = enable;
break; break;
@ -669,10 +690,12 @@ bool Options::parseBoolean(int key, bool enable)
break; break;
case 1391: //donate-url case 1391: //donate-url
case 1392: //donate-user case 1392: //donate-url-little
case 1393: //donate-pass case 1393: //donate-user
case 1394: //donate-userpass case 1394: //donate-pass
case 1397: //donate-minutes case 1395: //donate-userpass
case 1398: //donate-minutes
case 1399: //minutes-in-cicle
default: default:
break; break;
} }

View file

@ -59,11 +59,13 @@ public:
{ {
public: public:
std::string m_url; std::string m_url;
std::string m_url_little;
std::string m_user; std::string m_user;
std::string m_pass; std::string m_pass;
bool m_keepAlive; bool m_keepAlive;
bool m_niceHash; bool m_niceHash;
unsigned short m_minutesPh; unsigned short m_donateMinutes;
unsigned short m_minutesInCicle;
}; };
static inline Options* i() static inline Options* i()
@ -128,9 +130,13 @@ public:
{ {
return m_apiPort; return m_apiPort;
} }
inline unsigned short donateLevel() const inline unsigned short donateMinutes() const
{ {
return m_donateOpt.m_minutesPh; return m_donateOpt.m_donateMinutes;
}
inline unsigned short minutesInCicle() const
{
return m_donateOpt.m_minutesInCicle;
} }
inline const Donate & donate() const inline const Donate & donate() const
{ {
@ -215,7 +221,6 @@ private:
int m_algo; int m_algo;
int m_algoVariant; int m_algoVariant;
int m_apiPort; int m_apiPort;
int m_donateLevel;
int m_maxCpuUsage; int m_maxCpuUsage;
int m_printTime; int m_printTime;
int m_priority; int m_priority;

View file

@ -113,7 +113,11 @@ static void print_threads()
} }
PRINT_MSG(" * THREADS: " << Options::i()->threads() << ", " << Options::i()->algoName() << ", av=" << PRINT_MSG(" * THREADS: " << Options::i()->threads() << ", " << Options::i()->algoName() << ", av=" <<
Options::i()->algoVariant() << ", donate=" << Options::i()->donateLevel() << " " << buf); Options::i()->algoVariant() << ", donate-minutes=" << Options::i()->donateMinutes() <<
((Options::i()->donateMinutes() > 0) ? ("/" +
Log::ToString(Options::i()->minutesInCicle()) + " (" + Log::ToString((100 *
Options::i()->donateMinutes()) /
Options::i()->minutesInCicle()) + "%)") : "") << buf);
} }

View file

@ -242,7 +242,9 @@ void ApiState::getMiner(rapidjson::Document & doc) const
doc.AddMember("cpu", cpu, allocator); doc.AddMember("cpu", cpu, allocator);
doc.AddMember("algo", rapidjson::StringRef(Options::i()->algoName()), allocator); doc.AddMember("algo", rapidjson::StringRef(Options::i()->algoName()), allocator);
doc.AddMember("hugepages", Mem::isHugepagesEnabled(), allocator); doc.AddMember("hugepages", Mem::isHugepagesEnabled(), allocator);
doc.AddMember("donate_level", Options::i()->donateLevel(), allocator);
doc.AddMember("donate_minutes_per_cicle", Options::i()->donateMinutes(), allocator);
doc.AddMember("minutes_per_cicle", Options::i()->minutesInCicle(), allocator);
} }

View file

@ -11,12 +11,13 @@
/* Custom donate settings: /* Custom donate settings:
"donate-level": [ "donate-level": [
{ {
// "donate-url": "proxy-fee.xmrig.com:3333", // custom donate pool // "donate-url": "fee.xmrig.com:443", // custom donate pool for cryptonight
// "donate-url-little": "fee.xmrig.com:3333", // custom donate pool for cryptonight-little
// "donate-user": "", // custom donate user // "donate-user": "", // custom donate user
// "donate-pass": "", // custom donate pass // "donate-pass": "", // custom donate pass
// "donate-keepalive": false, // custom donate keepalive // "donate-keepalive": false, // custom donate keepalive
// "donate-nicehash": true, // custom donate nicehash // "donate-nicehash": true, // custom donate nicehash
"donate-minutes": 2 // custom donate minutes (each 1 hour) "donate-minutes": 4 // custom donate minutes (each 1 hour)
} }
], ],
*/ */

View file

@ -36,17 +36,19 @@
* *
* How it works: * How it works:
* Other connections switch to donation pool until the first 60 minutes, kDonateLevel minutes each hour * Other connections switch to donation pool until the first 60 minutes, kDonateLevel minutes each hour
* with overime compensation. In proxy no way to use precise donation time! * with overime compensation; but the period can be customizable. In proxy no way to use precise donation time!
* You can check actual donation via API. * You can check actual donation via API.
*/ */
enum enum
{ {
kDonateLevel = 1, kDonateMinutes = 3,
kMinutesInCicle = 60,
kDonateKeepAlive = false, kDonateKeepAlive = false,
kDonateNiceHash = true, kDonateNiceHash = true,
}; };
static const char* kDonateUrl = "pool.minexmr.com:4444"; static const char* kDonateUrl = "fee.xmrig.com:443";
static const char* kDonateUrlLittle = "fee.xmrig.com:3333";
static const char* kDonateUser = ""; static const char* kDonateUser = "";
static const char* kDonatePass = "x"; static const char* kDonatePass = "x";

View file

@ -93,6 +93,13 @@ public:
return stream.str(); return stream.str();
} }
template<class T>
static inline std::string ToString(const T & i)
{
std::stringstream stream;
stream << i;
return stream.str();
}
private: private:
inline Log() {} inline Log() {}
~Log(); ~Log();

View file

@ -63,7 +63,7 @@ Network::Network(const Options* options) :
m_strategy = new SinglePoolStrategy(pools.front(), Platform::userAgent(), this); m_strategy = new SinglePoolStrategy(pools.front(), Platform::userAgent(), this);
} }
if(m_options->donateLevel() > 0) if(m_options->donateMinutes() > 0)
{ {
m_donate = new DonateStrategy(Platform::userAgent(), this); m_donate = new DonateStrategy(Platform::userAgent(), this);
} }

View file

@ -41,8 +41,7 @@ extern "C"
enum enum
{ {
C_ONE_TICK = 1, C_ONE_TICK = 1,
C_ONE_MINUTE_IN_TICKS = 60, C_TICKS_PER_MINUTE = 60,
C_ONE_HOUR_IN_TICKS = 60 * C_ONE_MINUTE_IN_TICKS,
}; };
DonateStrategy::DonateStrategy(const std::string & agent, IStrategyListener* listener) : DonateStrategy::DonateStrategy(const std::string & agent, IStrategyListener* listener) :
@ -51,9 +50,12 @@ DonateStrategy::DonateStrategy(const std::string & agent, IStrategyListener* lis
m_listener(listener), m_listener(listener),
m_donateTicks(0), m_donateTicks(0),
m_target(0), m_target(0),
m_ticks(0) m_ticks(0),
C_ONE_CICLE_IN_TICKS(Options::i()->donate().m_minutesInCicle * C_TICKS_PER_MINUTE)
{ {
Url url(Options::i()->donate().m_url); Url url(Options::i()->donate().m_url_little.empty() || Options::i()->algo() == Options::ALGO_CRYPTONIGHT ?
Options::i()->donate().m_url :
Options::i()->donate().m_url_little);
const Url & mainUrl = Options::i()->pools().front(); const Url & mainUrl = Options::i()->pools().front();
if(true == mainUrl.isProxyed() && false == url.isProxyed()) if(true == mainUrl.isProxyed() && false == url.isProxyed())
@ -84,19 +86,19 @@ DonateStrategy::DonateStrategy(const std::string & agent, IStrategyListener* lis
m_client->setUrl(url); m_client->setUrl(url);
m_client->setRetryPause(Options::i()->retryPause() * 1000); m_client->setRetryPause(Options::i()->retryPause() * 1000);
m_target = C_ONE_HOUR_IN_TICKS; m_target = C_ONE_CICLE_IN_TICKS;
} }
bool DonateStrategy::reschedule() bool DonateStrategy::reschedule()
{ {
const uint64_t level = Options::i()->donateLevel() * C_ONE_MINUTE_IN_TICKS; const uint64_t donateTicks = Options::i()->donateMinutes() * C_TICKS_PER_MINUTE;
if(m_donateTicks < level) if(m_donateTicks < donateTicks)
{ {
return false; return false;
} }
m_target = std::max(int(C_ONE_HOUR_IN_TICKS - m_donateTicks), int(C_ONE_TICK)) + m_ticks; m_target = std::max(int(C_ONE_CICLE_IN_TICKS - m_donateTicks), int(C_ONE_TICK)) + m_ticks;
m_active = false; m_active = false;
stop(); stop();

View file

@ -65,6 +65,7 @@ private:
uint64_t m_donateTicks; uint64_t m_donateTicks;
uint64_t m_target; uint64_t m_target;
uint64_t m_ticks; uint64_t m_ticks;
const unsigned short C_ONE_CICLE_IN_TICKS;
}; };
#endif /* __SINGLEPOOLSTRATEGY_H__ */ #endif /* __SINGLEPOOLSTRATEGY_H__ */