This commit is contained in:
commit
e71c1b51bf
58 changed files with 10426 additions and 2437 deletions
|
@ -5,9 +5,9 @@
|
|||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2019 Howard Chu <https://github.com/hyc>
|
||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||
*
|
||||
* 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
|
||||
|
@ -27,16 +27,11 @@
|
|||
#pragma warning(disable:4244)
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <ctime>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
|
||||
|
||||
#include "net/Network.h"
|
||||
#include "backend/common/Tags.h"
|
||||
#include "base/io/log/Log.h"
|
||||
#include "base/net/stratum/Client.h"
|
||||
#include "base/net/stratum/NetworkState.h"
|
||||
#include "base/net/stratum/SubmitResult.h"
|
||||
#include "base/tools/Chrono.h"
|
||||
#include "base/tools/Timer.h"
|
||||
|
@ -45,7 +40,6 @@
|
|||
#include "core/Miner.h"
|
||||
#include "net/JobResult.h"
|
||||
#include "net/JobResults.h"
|
||||
#include "net/Network.h"
|
||||
#include "net/strategies/DonateStrategy.h"
|
||||
#include "rapidjson/document.h"
|
||||
|
||||
|
@ -56,6 +50,13 @@
|
|||
#endif
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
#include <cinttypes>
|
||||
#include <ctime>
|
||||
#include <iterator>
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
|
@ -73,9 +74,7 @@ const char *xmrig::net_tag()
|
|||
|
||||
|
||||
xmrig::Network::Network(Controller *controller) :
|
||||
m_controller(controller),
|
||||
m_donate(nullptr),
|
||||
m_timer(nullptr)
|
||||
m_controller(controller)
|
||||
{
|
||||
JobResults::setListener(this, controller->config()->cpu().isHwAES());
|
||||
controller->addListener(this);
|
||||
|
@ -84,8 +83,10 @@ xmrig::Network::Network(Controller *controller) :
|
|||
controller->api()->addListener(this);
|
||||
# endif
|
||||
|
||||
m_state = new NetworkState(this);
|
||||
|
||||
const Pools &pools = controller->config()->pools();
|
||||
m_strategy = pools.createStrategy(this);
|
||||
m_strategy = pools.createStrategy(m_state);
|
||||
|
||||
if (pools.donateLevel() > 0) {
|
||||
m_donate = new DonateStrategy(controller, this);
|
||||
|
@ -102,6 +103,7 @@ xmrig::Network::~Network()
|
|||
delete m_timer;
|
||||
delete m_donate;
|
||||
delete m_strategy;
|
||||
delete m_state;
|
||||
}
|
||||
|
||||
|
||||
|
@ -118,8 +120,6 @@ void xmrig::Network::onActive(IStrategy *strategy, IClient *client)
|
|||
return;
|
||||
}
|
||||
|
||||
m_state.onActive(client);
|
||||
|
||||
const char *tlsVersion = client->tlsVersion();
|
||||
LOG_INFO("%s " WHITE_BOLD("use %s ") CYAN_BOLD("%s:%d ") GREEN_BOLD("%s") " " BLACK_BOLD("%s"),
|
||||
tag, client->mode(), client->pool().host().data(), client->pool().port(), tlsVersion ? tlsVersion : "", client->ip().data());
|
||||
|
@ -209,7 +209,6 @@ void xmrig::Network::onPause(IStrategy *strategy)
|
|||
|
||||
if (!m_strategy->isActive()) {
|
||||
LOG_ERR("%s " RED("no active pools, stop mining"), tag);
|
||||
m_state.stop();
|
||||
|
||||
return m_controller->miner()->pause();
|
||||
}
|
||||
|
@ -218,15 +217,13 @@ void xmrig::Network::onPause(IStrategy *strategy)
|
|||
|
||||
void xmrig::Network::onResultAccepted(IStrategy *, IClient *, const SubmitResult &result, const char *error)
|
||||
{
|
||||
m_state.add(result, error);
|
||||
|
||||
if (error) {
|
||||
LOG_INFO("%s " RED_BOLD("rejected") " (%" PRId64 "/%" PRId64 ") diff " WHITE_BOLD("%" PRIu64) " " RED("\"%s\"") " " BLACK_BOLD("(%" PRIu64 " ms)"),
|
||||
backend_tag(result.backend), m_state.accepted, m_state.rejected, result.diff, error, result.elapsed);
|
||||
backend_tag(result.backend), m_state->accepted(), m_state->rejected(), result.diff, error, result.elapsed);
|
||||
}
|
||||
else {
|
||||
LOG_INFO("%s " GREEN_BOLD("accepted") " (%" PRId64 "/%" PRId64 ") diff " WHITE_BOLD("%" PRIu64) " " BLACK_BOLD("(%" PRIu64 " ms)"),
|
||||
backend_tag(result.backend), m_state.accepted, m_state.rejected, result.diff, result.elapsed);
|
||||
backend_tag(result.backend), m_state->accepted(), m_state->rejected(), result.diff, result.elapsed);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -269,7 +266,6 @@ void xmrig::Network::setJob(IClient *client, const Job &job, bool donate)
|
|||
m_donate->setAlgo(job.algorithm());
|
||||
}
|
||||
|
||||
m_state.diff = job.diff();
|
||||
m_controller->miner()->setJob(job, donate);
|
||||
}
|
||||
|
||||
|
@ -292,22 +288,8 @@ void xmrig::Network::getConnection(rapidjson::Value &reply, rapidjson::Document
|
|||
using namespace rapidjson;
|
||||
auto &allocator = doc.GetAllocator();
|
||||
|
||||
reply.AddMember("algo", StringRef(m_strategy->client()->job().algorithm().shortName()), allocator);
|
||||
|
||||
Value connection(kObjectType);
|
||||
connection.AddMember("pool", StringRef(m_state.pool), allocator);
|
||||
connection.AddMember("ip", m_state.ip().toJSON(), allocator);
|
||||
connection.AddMember("uptime", m_state.connectionTime(), allocator);
|
||||
connection.AddMember("ping", m_state.latency(), allocator);
|
||||
connection.AddMember("failures", m_state.failures, allocator);
|
||||
connection.AddMember("tls", m_state.tls().toJSON(), allocator);
|
||||
connection.AddMember("tls-fingerprint", m_state.fingerprint().toJSON(), allocator);
|
||||
|
||||
if (version == 1) {
|
||||
connection.AddMember("error_log", Value(kArrayType), allocator);
|
||||
}
|
||||
|
||||
reply.AddMember("connection", connection, allocator);
|
||||
reply.AddMember("algo", m_state->algorithm().toJSON(), allocator);
|
||||
reply.AddMember("connection", m_state->getConnection(doc, version), allocator);
|
||||
}
|
||||
|
||||
|
||||
|
@ -316,25 +298,6 @@ void xmrig::Network::getResults(rapidjson::Value &reply, rapidjson::Document &do
|
|||
using namespace rapidjson;
|
||||
auto &allocator = doc.GetAllocator();
|
||||
|
||||
Value results(kObjectType);
|
||||
|
||||
results.AddMember("diff_current", m_state.diff, allocator);
|
||||
results.AddMember("shares_good", m_state.accepted, allocator);
|
||||
results.AddMember("shares_total", m_state.accepted + m_state.rejected, allocator);
|
||||
results.AddMember("avg_time", m_state.avgTime(), allocator);
|
||||
results.AddMember("hashes_total", m_state.total, allocator);
|
||||
|
||||
Value best(kArrayType);
|
||||
for (uint64_t i : m_state.topDiff) {
|
||||
best.PushBack(i, allocator);
|
||||
}
|
||||
|
||||
results.AddMember("best", best, allocator);
|
||||
|
||||
if (version == 1) {
|
||||
results.AddMember("error_log", Value(kArrayType), allocator);
|
||||
}
|
||||
|
||||
reply.AddMember("results", results, allocator);
|
||||
reply.AddMember("results", m_state->getResults(doc, version), allocator);
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue