Options class replaced to xmrig::Config.
This commit is contained in:
parent
aad19f1a35
commit
aac7b0404a
25 changed files with 240 additions and 1104 deletions
|
@ -39,29 +39,30 @@
|
|||
#include "net/strategies/SinglePoolStrategy.h"
|
||||
#include "net/SubmitResult.h"
|
||||
#include "net/Url.h"
|
||||
#include "Options.h"
|
||||
#include "workers/Workers.h"
|
||||
#include "core/Controller.h"
|
||||
#include "core/Config.h"
|
||||
|
||||
|
||||
Network::Network(const Options *options) :
|
||||
m_options(options),
|
||||
m_donate(nullptr)
|
||||
Network::Network(xmrig::Controller *controller) :
|
||||
m_donate(nullptr),
|
||||
m_controller(controller)
|
||||
{
|
||||
srand(time(0) ^ (uintptr_t) this);
|
||||
|
||||
Workers::setListener(this);
|
||||
|
||||
const std::vector<Url*> &pools = options->pools();
|
||||
const std::vector<Url*> &pools = controller->config()->pools();
|
||||
|
||||
if (pools.size() > 1) {
|
||||
m_strategy = new FailoverStrategy(pools, options->retryPause(), options->retries(), this);
|
||||
m_strategy = new FailoverStrategy(pools, controller->config()->retryPause(), controller->config()->retries(), this);
|
||||
}
|
||||
else {
|
||||
m_strategy = new SinglePoolStrategy(pools.front(), options->retryPause(), this);
|
||||
m_strategy = new SinglePoolStrategy(pools.front(), controller->config()->retryPause(), this);
|
||||
}
|
||||
|
||||
if (m_options->donateLevel() > 0) {
|
||||
m_donate = new DonateStrategy(options->donateLevel(), options->pools().front()->user(), options->algo(), this);
|
||||
if (controller->config()->donateLevel() > 0) {
|
||||
m_donate = new DonateStrategy(controller->config()->donateLevel(), controller->config()->pools().front()->user(), controller->config()->algorithm(), this);
|
||||
}
|
||||
|
||||
m_timer.data = this;
|
||||
|
@ -101,7 +102,7 @@ void Network::onActive(IStrategy *strategy, Client *client)
|
|||
|
||||
m_state.setPool(client->host(), client->port(), client->ip());
|
||||
|
||||
LOG_INFO(m_options->colors() ? "\x1B[01;37muse pool \x1B[01;36m%s:%d \x1B[01;30m%s" : "use pool %s:%d %s", client->host(), client->port(), client->ip());
|
||||
LOG_INFO(isColors() ? "\x1B[01;37muse pool \x1B[01;36m%s:%d \x1B[01;30m%s" : "use pool %s:%d %s", client->host(), client->port(), client->ip());
|
||||
}
|
||||
|
||||
|
||||
|
@ -146,21 +147,27 @@ void Network::onResultAccepted(IStrategy *strategy, Client *client, const Submit
|
|||
m_state.add(result, error);
|
||||
|
||||
if (error) {
|
||||
LOG_INFO(m_options->colors() ? "\x1B[01;31mrejected\x1B[0m (%" PRId64 "/%" PRId64 ") diff \x1B[01;37m%u\x1B[0m \x1B[31m\"%s\"\x1B[0m \x1B[01;30m(%" PRIu64 " ms)"
|
||||
: "rejected (%" PRId64 "/%" PRId64 ") diff %u \"%s\" (%" PRIu64 " ms)",
|
||||
LOG_INFO(isColors() ? "\x1B[01;31mrejected\x1B[0m (%" PRId64 "/%" PRId64 ") diff \x1B[01;37m%u\x1B[0m \x1B[31m\"%s\"\x1B[0m \x1B[01;30m(%" PRIu64 " ms)"
|
||||
: "rejected (%" PRId64 "/%" PRId64 ") diff %u \"%s\" (%" PRIu64 " ms)",
|
||||
m_state.accepted, m_state.rejected, result.diff, error, result.elapsed);
|
||||
}
|
||||
else {
|
||||
LOG_INFO(m_options->colors() ? "\x1B[01;32maccepted\x1B[0m (%" PRId64 "/%" PRId64 ") diff \x1B[01;37m%u\x1B[0m \x1B[01;30m(%" PRIu64 " ms)"
|
||||
: "accepted (%" PRId64 "/%" PRId64 ") diff %u (%" PRIu64 " ms)",
|
||||
LOG_INFO(isColors() ? "\x1B[01;32maccepted\x1B[0m (%" PRId64 "/%" PRId64 ") diff \x1B[01;37m%u\x1B[0m \x1B[01;30m(%" PRIu64 " ms)"
|
||||
: "accepted (%" PRId64 "/%" PRId64 ") diff %u (%" PRIu64 " ms)",
|
||||
m_state.accepted, m_state.rejected, result.diff, result.elapsed);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool Network::isColors() const
|
||||
{
|
||||
return m_controller->config()->isColors();
|
||||
}
|
||||
|
||||
|
||||
void Network::setJob(Client *client, const Job &job, bool donate)
|
||||
{
|
||||
if (m_options->colors()) {
|
||||
if (isColors()) {
|
||||
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 {
|
||||
|
|
|
@ -35,14 +35,18 @@
|
|||
|
||||
|
||||
class IStrategy;
|
||||
class Options;
|
||||
class Url;
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
class Controller;
|
||||
}
|
||||
|
||||
|
||||
class Network : public IJobResultListener, public IStrategyListener
|
||||
{
|
||||
public:
|
||||
Network(const Options *options);
|
||||
Network(xmrig::Controller *controller);
|
||||
~Network();
|
||||
|
||||
void connect();
|
||||
|
@ -58,16 +62,17 @@ protected:
|
|||
private:
|
||||
constexpr static int kTickInterval = 1 * 1000;
|
||||
|
||||
bool isColors() const;
|
||||
void setJob(Client *client, const Job &job, bool donate);
|
||||
void tick();
|
||||
|
||||
static void onTick(uv_timer_t *handle);
|
||||
|
||||
const Options *m_options;
|
||||
IStrategy *m_donate;
|
||||
IStrategy *m_strategy;
|
||||
NetworkState m_state;
|
||||
uv_timer_t m_timer;
|
||||
xmrig::Controller *m_controller;
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue