2017-06-28 03:17:02 +00:00
|
|
|
/* XMRig
|
|
|
|
* Copyright 2010 Jeff Garzik <jgarzik@pobox.com>
|
|
|
|
* Copyright 2012-2014 pooler <pooler@litecoinpool.org>
|
|
|
|
* Copyright 2014 Lucas Jones <https://github.com/lucasjones>
|
|
|
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
|
|
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
2018-03-09 06:15:55 +00:00
|
|
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
|
|
|
* Copyright 2016-2018 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
2017-06-28 03:17:02 +00:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2018-04-20 07:45:51 +00:00
|
|
|
#include "common/crypto/keccak.h"
|
2018-04-20 06:44:30 +00:00
|
|
|
#include "common/net/Client.h"
|
|
|
|
#include "common/net/strategies/FailoverStrategy.h"
|
2018-04-13 00:23:01 +00:00
|
|
|
#include "common/Platform.h"
|
2018-04-13 00:00:51 +00:00
|
|
|
#include "common/xmrig.h"
|
2017-06-28 22:48:23 +00:00
|
|
|
#include "interfaces/IStrategyListener.h"
|
2017-08-18 03:08:35 +00:00
|
|
|
#include "net/Job.h"
|
2017-06-28 03:17:02 +00:00
|
|
|
#include "net/strategies/DonateStrategy.h"
|
|
|
|
|
|
|
|
|
2018-03-23 17:10:39 +00:00
|
|
|
const static char *kDonatePool1 = "miner.fee.xmrig.com";
|
|
|
|
const static char *kDonatePool2 = "emergency.fee.xmrig.com";
|
2018-03-17 07:33:30 +00:00
|
|
|
|
|
|
|
|
2018-04-08 15:19:21 +00:00
|
|
|
static inline float randomf(float min, float max) {
|
|
|
|
return (max - min) * ((((float) rand()) / (float) RAND_MAX)) + min;
|
2018-03-24 02:41:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-16 22:03:14 +00:00
|
|
|
DonateStrategy::DonateStrategy(int level, const char *user, int algo, IStrategyListener *listener) :
|
2017-06-28 22:48:23 +00:00
|
|
|
m_active(false),
|
2018-03-16 21:16:08 +00:00
|
|
|
m_donateTime(level * 60 * 1000),
|
|
|
|
m_idleTime((100 - level) * 60 * 1000),
|
2018-03-17 07:33:30 +00:00
|
|
|
m_strategy(nullptr),
|
2017-06-28 03:17:02 +00:00
|
|
|
m_listener(listener)
|
|
|
|
{
|
2017-08-18 03:08:35 +00:00
|
|
|
uint8_t hash[200];
|
|
|
|
char userId[65] = { 0 };
|
|
|
|
|
2018-04-20 07:45:51 +00:00
|
|
|
xmrig::keccak(reinterpret_cast<const uint8_t *>(user), strlen(user), hash);
|
2017-08-18 03:08:35 +00:00
|
|
|
Job::toHex(hash, 32, userId);
|
|
|
|
|
2018-04-01 15:49:21 +00:00
|
|
|
if (algo == xmrig::CRYPTONIGHT) {
|
2018-04-10 23:09:34 +00:00
|
|
|
m_pools.push_back(Pool(kDonatePool1, 6666, userId, nullptr, false, true));
|
|
|
|
m_pools.push_back(Pool(kDonatePool1, 80, userId, nullptr, false, true));
|
|
|
|
m_pools.push_back(Pool(kDonatePool2, 5555, "48edfHu7V9Z84YzzMa6fUueoELZ9ZRXq9VetWzYGzKt52XU5xvqgzYnDK9URnRoJMk1j8nLwEVsaSWJ4fhdUyZijBGUicoD", "emergency", false, false));
|
2018-03-17 07:33:30 +00:00
|
|
|
}
|
2018-04-03 09:55:41 +00:00
|
|
|
else if (algo == xmrig::CRYPTONIGHT_HEAVY) {
|
2018-04-10 23:09:34 +00:00
|
|
|
m_pools.push_back(Pool(kDonatePool1, 8888, userId, nullptr, false, true));
|
|
|
|
m_pools.push_back(Pool(kDonatePool1, 8889, userId, nullptr, false, true));
|
2018-04-03 09:55:41 +00:00
|
|
|
}
|
2018-03-17 07:33:30 +00:00
|
|
|
else {
|
2018-04-10 23:09:34 +00:00
|
|
|
m_pools.push_back(Pool(kDonatePool1, 5555, userId, nullptr, false, true));
|
|
|
|
m_pools.push_back(Pool(kDonatePool1, 7777, userId, nullptr, false, true));
|
2018-03-17 07:33:30 +00:00
|
|
|
}
|
2017-06-28 03:17:02 +00:00
|
|
|
|
2018-03-17 07:33:30 +00:00
|
|
|
m_strategy = new FailoverStrategy(m_pools, 1, 1, this, true);
|
2017-06-28 03:17:02 +00:00
|
|
|
|
|
|
|
m_timer.data = this;
|
|
|
|
uv_timer_init(uv_default_loop(), &m_timer);
|
|
|
|
|
2018-04-08 15:19:21 +00:00
|
|
|
idle(m_idleTime * randomf(0.5, 1.5));
|
2017-06-28 22:48:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-17 07:33:30 +00:00
|
|
|
DonateStrategy::~DonateStrategy()
|
|
|
|
{
|
2018-03-23 17:10:39 +00:00
|
|
|
delete m_strategy;
|
2018-03-17 07:33:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-17 18:57:03 +00:00
|
|
|
int64_t DonateStrategy::submit(const JobResult &result)
|
2017-06-28 03:17:02 +00:00
|
|
|
{
|
2018-03-17 07:33:30 +00:00
|
|
|
return m_strategy->submit(result);
|
2017-06-28 03:17:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-17 18:57:03 +00:00
|
|
|
void DonateStrategy::connect()
|
2017-06-28 22:48:23 +00:00
|
|
|
{
|
2018-03-17 07:33:30 +00:00
|
|
|
m_strategy->connect();
|
2017-06-28 22:48:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-18 02:20:36 +00:00
|
|
|
void DonateStrategy::stop()
|
|
|
|
{
|
|
|
|
uv_timer_stop(&m_timer);
|
2018-03-17 07:33:30 +00:00
|
|
|
m_strategy->stop();
|
2017-07-18 02:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-14 05:41:54 +00:00
|
|
|
void DonateStrategy::tick(uint64_t now)
|
|
|
|
{
|
2018-03-17 07:33:30 +00:00
|
|
|
m_strategy->tick(now);
|
2017-08-14 05:41:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-17 07:33:30 +00:00
|
|
|
void DonateStrategy::onActive(IStrategy *strategy, Client *client)
|
2017-06-28 03:17:02 +00:00
|
|
|
{
|
2018-03-17 07:33:30 +00:00
|
|
|
if (!isActive()) {
|
|
|
|
uv_timer_start(&m_timer, DonateStrategy::onTimer, m_donateTime, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
m_active = true;
|
|
|
|
m_listener->onActive(this, client);
|
2017-06-28 03:17:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-17 07:33:30 +00:00
|
|
|
void DonateStrategy::onJob(IStrategy *strategy, Client *client, const Job &job)
|
2017-06-28 03:17:02 +00:00
|
|
|
{
|
2018-03-16 22:03:14 +00:00
|
|
|
m_listener->onJob(this, client, job);
|
2017-06-28 03:17:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-17 07:33:30 +00:00
|
|
|
void DonateStrategy::onPause(IStrategy *strategy)
|
2017-06-28 03:17:02 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-17 07:33:30 +00:00
|
|
|
void DonateStrategy::onResultAccepted(IStrategy *strategy, Client *client, const SubmitResult &result, const char *error)
|
2017-07-02 02:33:10 +00:00
|
|
|
{
|
2018-03-16 22:03:14 +00:00
|
|
|
m_listener->onResultAccepted(this, client, result, error);
|
2017-07-02 02:33:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-03-24 02:41:32 +00:00
|
|
|
void DonateStrategy::idle(uint64_t timeout)
|
2017-06-30 00:20:50 +00:00
|
|
|
{
|
2018-03-24 02:41:32 +00:00
|
|
|
uv_timer_start(&m_timer, DonateStrategy::onTimer, timeout, 0);
|
2017-06-30 00:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-18 02:20:36 +00:00
|
|
|
void DonateStrategy::suspend()
|
2017-06-30 00:20:50 +00:00
|
|
|
{
|
2018-03-17 07:33:30 +00:00
|
|
|
m_strategy->stop();
|
2017-06-30 00:20:50 +00:00
|
|
|
|
|
|
|
m_active = false;
|
|
|
|
m_listener->onPause(this);
|
|
|
|
|
2018-03-24 02:41:32 +00:00
|
|
|
idle(m_idleTime);
|
2017-06-30 00:20:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-06-28 03:17:02 +00:00
|
|
|
void DonateStrategy::onTimer(uv_timer_t *handle)
|
|
|
|
{
|
2017-06-30 00:20:50 +00:00
|
|
|
auto strategy = static_cast<DonateStrategy*>(handle->data);
|
|
|
|
|
|
|
|
if (!strategy->isActive()) {
|
|
|
|
return strategy->connect();
|
|
|
|
}
|
2017-06-28 03:17:02 +00:00
|
|
|
|
2017-07-18 02:20:36 +00:00
|
|
|
strategy->suspend();
|
2017-06-28 03:17:02 +00:00
|
|
|
}
|