mirror of
https://github.com/xmrig/xmrig.git
synced 2024-11-18 00:37:46 +00:00
New NetworkState.
This commit is contained in:
parent
8e6f4d4ecb
commit
c5968e8896
8 changed files with 354 additions and 218 deletions
|
@ -53,7 +53,6 @@ set(HEADERS
|
||||||
src/net/JobResult.h
|
src/net/JobResult.h
|
||||||
src/net/JobResults.h
|
src/net/JobResults.h
|
||||||
src/net/Network.h
|
src/net/Network.h
|
||||||
src/net/NetworkState.h
|
|
||||||
src/net/strategies/DonateStrategy.h
|
src/net/strategies/DonateStrategy.h
|
||||||
src/Summary.h
|
src/Summary.h
|
||||||
src/version.h
|
src/version.h
|
||||||
|
@ -103,7 +102,6 @@ set(SOURCES
|
||||||
src/core/Miner.cpp
|
src/core/Miner.cpp
|
||||||
src/net/JobResults.cpp
|
src/net/JobResults.cpp
|
||||||
src/net/Network.cpp
|
src/net/Network.cpp
|
||||||
src/net/NetworkState.cpp
|
|
||||||
src/net/strategies/DonateStrategy.cpp
|
src/net/strategies/DonateStrategy.cpp
|
||||||
src/Summary.cpp
|
src/Summary.cpp
|
||||||
src/xmrig.cpp
|
src/xmrig.cpp
|
||||||
|
|
|
@ -37,10 +37,12 @@ set(HEADERS_BASE
|
||||||
src/base/net/stratum/BaseClient.h
|
src/base/net/stratum/BaseClient.h
|
||||||
src/base/net/stratum/Client.h
|
src/base/net/stratum/Client.h
|
||||||
src/base/net/stratum/Job.h
|
src/base/net/stratum/Job.h
|
||||||
|
src/base/net/stratum/NetworkState.h
|
||||||
src/base/net/stratum/Pool.h
|
src/base/net/stratum/Pool.h
|
||||||
src/base/net/stratum/Pools.h
|
src/base/net/stratum/Pools.h
|
||||||
src/base/net/stratum/strategies/FailoverStrategy.h
|
src/base/net/stratum/strategies/FailoverStrategy.h
|
||||||
src/base/net/stratum/strategies/SinglePoolStrategy.h
|
src/base/net/stratum/strategies/SinglePoolStrategy.h
|
||||||
|
src/base/net/stratum/strategies/StrategyProxy.h
|
||||||
src/base/net/stratum/SubmitResult.h
|
src/base/net/stratum/SubmitResult.h
|
||||||
src/base/net/stratum/Url.h
|
src/base/net/stratum/Url.h
|
||||||
src/base/net/tools/RecvBuf.h
|
src/base/net/tools/RecvBuf.h
|
||||||
|
@ -77,6 +79,7 @@ set(SOURCES_BASE
|
||||||
src/base/net/stratum/BaseClient.cpp
|
src/base/net/stratum/BaseClient.cpp
|
||||||
src/base/net/stratum/Client.cpp
|
src/base/net/stratum/Client.cpp
|
||||||
src/base/net/stratum/Job.cpp
|
src/base/net/stratum/Job.cpp
|
||||||
|
src/base/net/stratum/NetworkState.cpp
|
||||||
src/base/net/stratum/Pool.cpp
|
src/base/net/stratum/Pool.cpp
|
||||||
src/base/net/stratum/Pools.cpp
|
src/base/net/stratum/Pools.cpp
|
||||||
src/base/net/stratum/strategies/FailoverStrategy.cpp
|
src/base/net/stratum/strategies/FailoverStrategy.cpp
|
||||||
|
|
208
src/base/net/stratum/NetworkState.cpp
Normal file
208
src/base/net/stratum/NetworkState.cpp
Normal file
|
@ -0,0 +1,208 @@
|
||||||
|
/* 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>
|
||||||
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
|
* 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
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
#include "base/net/stratum/NetworkState.h"
|
||||||
|
#include "base/kernel/interfaces/IClient.h"
|
||||||
|
#include "base/kernel/interfaces/IStrategy.h"
|
||||||
|
#include "base/net/stratum/Job.h"
|
||||||
|
#include "base/net/stratum/Pool.h"
|
||||||
|
#include "base/net/stratum/SubmitResult.h"
|
||||||
|
#include "base/tools/Chrono.h"
|
||||||
|
#include "rapidjson/document.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <cstring>
|
||||||
|
#include <uv.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
xmrig::NetworkState::NetworkState(IStrategyListener *listener) : StrategyProxy(listener)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef XMRIG_FEATURE_API
|
||||||
|
rapidjson::Value xmrig::NetworkState::getConnection(rapidjson::Document &doc, int version) const
|
||||||
|
{
|
||||||
|
using namespace rapidjson;
|
||||||
|
auto &allocator = doc.GetAllocator();
|
||||||
|
|
||||||
|
Value connection(kObjectType);
|
||||||
|
connection.AddMember("pool", StringRef(m_pool), allocator);
|
||||||
|
connection.AddMember("ip", m_ip.toJSON(), allocator);
|
||||||
|
connection.AddMember("uptime", connectionTime(), allocator);
|
||||||
|
connection.AddMember("ping", latency(), allocator);
|
||||||
|
connection.AddMember("failures", m_failures, allocator);
|
||||||
|
connection.AddMember("tls", m_tls.toJSON(), allocator);
|
||||||
|
connection.AddMember("tls-fingerprint", m_fingerprint.toJSON(), allocator);
|
||||||
|
|
||||||
|
connection.AddMember("algo", m_algorithm.toJSON(), allocator);
|
||||||
|
connection.AddMember("diff", m_diff, allocator);
|
||||||
|
connection.AddMember("accepted", m_accepted, allocator);
|
||||||
|
connection.AddMember("rejected", m_rejected, allocator);
|
||||||
|
connection.AddMember("avg_time", avgTime(), allocator);
|
||||||
|
connection.AddMember("hashes_total", m_hashes, allocator);
|
||||||
|
|
||||||
|
if (version == 1) {
|
||||||
|
connection.AddMember("error_log", Value(kArrayType), allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
rapidjson::Value xmrig::NetworkState::getResults(rapidjson::Document &doc, int version) const
|
||||||
|
{
|
||||||
|
using namespace rapidjson;
|
||||||
|
auto &allocator = doc.GetAllocator();
|
||||||
|
|
||||||
|
Value results(kObjectType);
|
||||||
|
|
||||||
|
results.AddMember("diff_current", m_diff, allocator);
|
||||||
|
results.AddMember("shares_good", m_accepted, allocator);
|
||||||
|
results.AddMember("shares_total", m_accepted + m_rejected, allocator);
|
||||||
|
results.AddMember("avg_time", avgTime(), allocator);
|
||||||
|
results.AddMember("hashes_total", m_hashes, allocator);
|
||||||
|
|
||||||
|
Value best(kArrayType);
|
||||||
|
for (uint64_t i : topDiff) {
|
||||||
|
best.PushBack(i, allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
results.AddMember("best", best, allocator);
|
||||||
|
|
||||||
|
if (version == 1) {
|
||||||
|
results.AddMember("error_log", Value(kArrayType), allocator);
|
||||||
|
}
|
||||||
|
|
||||||
|
return results;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::NetworkState::onActive(IStrategy *strategy, IClient *client)
|
||||||
|
{
|
||||||
|
snprintf(m_pool, sizeof(m_pool) - 1, "%s:%d", client->pool().host().data(), client->pool().port());
|
||||||
|
|
||||||
|
m_ip = client->ip();
|
||||||
|
m_tls = client->tlsVersion();
|
||||||
|
m_fingerprint = client->tlsFingerprint();
|
||||||
|
m_active = true;
|
||||||
|
m_connectionTime = Chrono::steadyMSecs();
|
||||||
|
|
||||||
|
StrategyProxy::onActive(strategy, client);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::NetworkState::onJob(IStrategy *strategy, IClient *client, const Job &job)
|
||||||
|
{
|
||||||
|
m_algorithm = job.algorithm();
|
||||||
|
m_diff = job.diff();
|
||||||
|
|
||||||
|
StrategyProxy::onJob(strategy, client, job);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::NetworkState::onPause(IStrategy *strategy)
|
||||||
|
{
|
||||||
|
if (!strategy->isActive()) {
|
||||||
|
stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
StrategyProxy::onPause(strategy);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::NetworkState::onResultAccepted(IStrategy *strategy, IClient *client, const SubmitResult &result, const char *error)
|
||||||
|
{
|
||||||
|
add(result, error);
|
||||||
|
|
||||||
|
StrategyProxy::onResultAccepted(strategy, client, result, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint32_t xmrig::NetworkState::avgTime() const
|
||||||
|
{
|
||||||
|
if (m_latency.empty()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return connectionTime() / (uint32_t)m_latency.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint32_t xmrig::NetworkState::latency() const
|
||||||
|
{
|
||||||
|
const size_t calls = m_latency.size();
|
||||||
|
if (calls == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto v = m_latency;
|
||||||
|
std::nth_element(v.begin(), v.begin() + calls / 2, v.end());
|
||||||
|
|
||||||
|
return v[calls / 2];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
uint64_t xmrig::NetworkState::connectionTime() const
|
||||||
|
{
|
||||||
|
return m_active ? ((Chrono::steadyMSecs() - m_connectionTime) / 1000) : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::NetworkState::add(const SubmitResult &result, const char *error)
|
||||||
|
{
|
||||||
|
if (error) {
|
||||||
|
m_rejected++;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_accepted++;
|
||||||
|
m_hashes += result.diff;
|
||||||
|
|
||||||
|
const size_t ln = topDiff.size() - 1;
|
||||||
|
if (result.actualDiff > topDiff[ln]) {
|
||||||
|
topDiff[ln] = result.actualDiff;
|
||||||
|
std::sort(topDiff.rbegin(), topDiff.rend());
|
||||||
|
}
|
||||||
|
|
||||||
|
m_latency.push_back(result.elapsed > 0xFFFF ? 0xFFFF : static_cast<uint16_t>(result.elapsed));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void xmrig::NetworkState::stop()
|
||||||
|
{
|
||||||
|
m_active = false;
|
||||||
|
m_diff = 0;
|
||||||
|
m_ip = nullptr;
|
||||||
|
m_tls = nullptr;
|
||||||
|
m_fingerprint = nullptr;
|
||||||
|
|
||||||
|
m_failures++;
|
||||||
|
m_latency.clear();
|
||||||
|
}
|
|
@ -5,8 +5,8 @@
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
* Copyright 2018-2020 SChernykh <https://github.com/SChernykh>
|
||||||
* Copyright 2016-2019 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
* Copyright 2016-2020 XMRig <https://github.com/xmrig>, <support@xmrig.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -26,51 +26,59 @@
|
||||||
#define XMRIG_NETWORKSTATE_H
|
#define XMRIG_NETWORKSTATE_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "base/net/stratum/strategies/StrategyProxy.h"
|
||||||
|
#include "base/tools/String.h"
|
||||||
|
#include "crypto/common/Algorithm.h"
|
||||||
|
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
#include "base/tools/String.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
class IClient;
|
class NetworkState : public StrategyProxy
|
||||||
class SubmitResult;
|
|
||||||
|
|
||||||
|
|
||||||
class NetworkState
|
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
NetworkState();
|
NetworkState(IStrategyListener *listener);
|
||||||
|
|
||||||
inline const String &fingerprint() const { return m_fingerprint; }
|
inline const Algorithm &algorithm() const { return m_algorithm; }
|
||||||
inline const String &ip() const { return m_ip; }
|
inline uint64_t accepted() const { return m_accepted; }
|
||||||
inline const String &tls() const { return m_tls; }
|
inline uint64_t rejected() const { return m_rejected; }
|
||||||
|
|
||||||
|
# ifdef XMRIG_FEATURE_API
|
||||||
|
rapidjson::Value getConnection(rapidjson::Document &doc, int version) const;
|
||||||
|
rapidjson::Value getResults(rapidjson::Document &doc, int version) const;
|
||||||
|
# endif
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void onActive(IStrategy *strategy, IClient *client) override;
|
||||||
|
void onJob(IStrategy *strategy, IClient *client, const Job &job) override;
|
||||||
|
void onPause(IStrategy *strategy) override;
|
||||||
|
void onResultAccepted(IStrategy *strategy, IClient *client, const SubmitResult &result, const char *error) override;
|
||||||
|
|
||||||
|
private:
|
||||||
uint32_t avgTime() const;
|
uint32_t avgTime() const;
|
||||||
uint32_t latency() const;
|
uint32_t latency() const;
|
||||||
uint64_t connectionTime() const;
|
uint64_t connectionTime() const;
|
||||||
void add(const SubmitResult &result, const char *error);
|
void add(const SubmitResult &result, const char *error);
|
||||||
void onActive(IClient *client);
|
|
||||||
void stop();
|
void stop();
|
||||||
|
|
||||||
char pool[256];
|
Algorithm m_algorithm;
|
||||||
|
bool m_active = false;
|
||||||
|
char m_pool[256]{};
|
||||||
std::array<uint64_t, 10> topDiff { { } };
|
std::array<uint64_t, 10> topDiff { { } };
|
||||||
uint64_t accepted;
|
|
||||||
uint64_t diff;
|
|
||||||
uint64_t failures;
|
|
||||||
uint64_t rejected;
|
|
||||||
uint64_t total;
|
|
||||||
|
|
||||||
private:
|
|
||||||
bool m_active;
|
|
||||||
std::vector<uint16_t> m_latency;
|
std::vector<uint16_t> m_latency;
|
||||||
String m_fingerprint;
|
String m_fingerprint;
|
||||||
String m_ip;
|
String m_ip;
|
||||||
String m_tls;
|
String m_tls;
|
||||||
uint64_t m_connectionTime;
|
uint64_t m_accepted = 0;
|
||||||
|
uint64_t m_connectionTime = 0;
|
||||||
|
uint64_t m_diff = 0;
|
||||||
|
uint64_t m_failures = 0;
|
||||||
|
uint64_t m_hashes = 0;
|
||||||
|
uint64_t m_rejected = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
79
src/base/net/stratum/strategies/StrategyProxy.h
Normal file
79
src/base/net/stratum/strategies/StrategyProxy.h
Normal file
|
@ -0,0 +1,79 @@
|
||||||
|
/* 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>
|
||||||
|
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
||||||
|
* 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
|
||||||
|
* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef XMRIG_STRATEGYPROXY_H
|
||||||
|
#define XMRIG_STRATEGYPROXY_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "base/kernel/interfaces/IStrategyListener.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
class StrategyProxy : public IStrategyListener
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
inline StrategyProxy(IStrategyListener *listener) : m_listener(listener) {}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
inline void onActive(IStrategy *strategy, IClient *client) override
|
||||||
|
{
|
||||||
|
m_listener->onActive(strategy, client);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void onJob(IStrategy *strategy, IClient *client, const Job &job) override
|
||||||
|
{
|
||||||
|
m_listener->onJob(strategy, client, job);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void onLogin(IStrategy *strategy, IClient *client, rapidjson::Document &doc, rapidjson::Value ¶ms) override
|
||||||
|
{
|
||||||
|
m_listener->onLogin(strategy, client, doc, params);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void onPause(IStrategy *strategy) override
|
||||||
|
{
|
||||||
|
m_listener->onPause(strategy);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void onResultAccepted(IStrategy *strategy, IClient *client, const SubmitResult &result, const char *error) override
|
||||||
|
{
|
||||||
|
m_listener->onResultAccepted(strategy, client, result, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
inline void onVerifyAlgorithm(IStrategy *strategy, const IClient *client, const Algorithm &algorithm, bool *ok) override
|
||||||
|
{
|
||||||
|
m_listener->onVerifyAlgorithm(strategy, client, algorithm, ok);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
IStrategyListener *m_listener;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} /* namespace xmrig */
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* XMRIG_STRATEGYPROXY_H */
|
|
@ -5,9 +5,9 @@
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
* 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 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
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -27,16 +27,11 @@
|
||||||
#pragma warning(disable:4244)
|
#pragma warning(disable:4244)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <algorithm>
|
#include "net/Network.h"
|
||||||
#include <cinttypes>
|
|
||||||
#include <ctime>
|
|
||||||
#include <iterator>
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
|
|
||||||
#include "backend/common/Tags.h"
|
#include "backend/common/Tags.h"
|
||||||
#include "base/io/log/Log.h"
|
#include "base/io/log/Log.h"
|
||||||
#include "base/net/stratum/Client.h"
|
#include "base/net/stratum/Client.h"
|
||||||
|
#include "base/net/stratum/NetworkState.h"
|
||||||
#include "base/net/stratum/SubmitResult.h"
|
#include "base/net/stratum/SubmitResult.h"
|
||||||
#include "base/tools/Chrono.h"
|
#include "base/tools/Chrono.h"
|
||||||
#include "base/tools/Timer.h"
|
#include "base/tools/Timer.h"
|
||||||
|
@ -45,7 +40,6 @@
|
||||||
#include "core/Miner.h"
|
#include "core/Miner.h"
|
||||||
#include "net/JobResult.h"
|
#include "net/JobResult.h"
|
||||||
#include "net/JobResults.h"
|
#include "net/JobResults.h"
|
||||||
#include "net/Network.h"
|
|
||||||
#include "net/strategies/DonateStrategy.h"
|
#include "net/strategies/DonateStrategy.h"
|
||||||
#include "rapidjson/document.h"
|
#include "rapidjson/document.h"
|
||||||
|
|
||||||
|
@ -56,6 +50,13 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cinttypes>
|
||||||
|
#include <ctime>
|
||||||
|
#include <iterator>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
|
@ -73,9 +74,7 @@ const char *xmrig::net_tag()
|
||||||
|
|
||||||
|
|
||||||
xmrig::Network::Network(Controller *controller) :
|
xmrig::Network::Network(Controller *controller) :
|
||||||
m_controller(controller),
|
m_controller(controller)
|
||||||
m_donate(nullptr),
|
|
||||||
m_timer(nullptr)
|
|
||||||
{
|
{
|
||||||
JobResults::setListener(this, controller->config()->cpu().isHwAES());
|
JobResults::setListener(this, controller->config()->cpu().isHwAES());
|
||||||
controller->addListener(this);
|
controller->addListener(this);
|
||||||
|
@ -84,8 +83,10 @@ xmrig::Network::Network(Controller *controller) :
|
||||||
controller->api()->addListener(this);
|
controller->api()->addListener(this);
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
m_state = new NetworkState(this);
|
||||||
|
|
||||||
const Pools &pools = controller->config()->pools();
|
const Pools &pools = controller->config()->pools();
|
||||||
m_strategy = pools.createStrategy(this);
|
m_strategy = pools.createStrategy(m_state);
|
||||||
|
|
||||||
if (pools.donateLevel() > 0) {
|
if (pools.donateLevel() > 0) {
|
||||||
m_donate = new DonateStrategy(controller, this);
|
m_donate = new DonateStrategy(controller, this);
|
||||||
|
@ -102,6 +103,7 @@ xmrig::Network::~Network()
|
||||||
delete m_timer;
|
delete m_timer;
|
||||||
delete m_donate;
|
delete m_donate;
|
||||||
delete m_strategy;
|
delete m_strategy;
|
||||||
|
delete m_state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -118,8 +120,6 @@ void xmrig::Network::onActive(IStrategy *strategy, IClient *client)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_state.onActive(client);
|
|
||||||
|
|
||||||
const char *tlsVersion = client->tlsVersion();
|
const char *tlsVersion = client->tlsVersion();
|
||||||
LOG_INFO("%s " WHITE_BOLD("use %s ") CYAN_BOLD("%s:%d ") GREEN_BOLD("%s") " " BLACK_BOLD("%s"),
|
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());
|
tag, client->mode(), client->pool().host().data(), client->pool().port(), tlsVersion ? tlsVersion : "", client->ip().data());
|
||||||
|
@ -201,7 +201,6 @@ void xmrig::Network::onPause(IStrategy *strategy)
|
||||||
|
|
||||||
if (!m_strategy->isActive()) {
|
if (!m_strategy->isActive()) {
|
||||||
LOG_ERR("%s " RED("no active pools, stop mining"), tag);
|
LOG_ERR("%s " RED("no active pools, stop mining"), tag);
|
||||||
m_state.stop();
|
|
||||||
|
|
||||||
return m_controller->miner()->pause();
|
return m_controller->miner()->pause();
|
||||||
}
|
}
|
||||||
|
@ -210,15 +209,13 @@ void xmrig::Network::onPause(IStrategy *strategy)
|
||||||
|
|
||||||
void xmrig::Network::onResultAccepted(IStrategy *, IClient *, const SubmitResult &result, const char *error)
|
void xmrig::Network::onResultAccepted(IStrategy *, IClient *, const SubmitResult &result, const char *error)
|
||||||
{
|
{
|
||||||
m_state.add(result, error);
|
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
LOG_INFO("%s " RED_BOLD("rejected") " (%" PRId64 "/%" PRId64 ") diff " WHITE_BOLD("%" PRIu64) " " RED("\"%s\"") " " BLACK_BOLD("(%" PRIu64 " ms)"),
|
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 {
|
else {
|
||||||
LOG_INFO("%s " GREEN_BOLD("accepted") " (%" PRId64 "/%" PRId64 ") diff " WHITE_BOLD("%" PRIu64) " " BLACK_BOLD("(%" PRIu64 " ms)"),
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,7 +258,6 @@ void xmrig::Network::setJob(IClient *client, const Job &job, bool donate)
|
||||||
m_donate->setAlgo(job.algorithm());
|
m_donate->setAlgo(job.algorithm());
|
||||||
}
|
}
|
||||||
|
|
||||||
m_state.diff = job.diff();
|
|
||||||
m_controller->miner()->setJob(job, donate);
|
m_controller->miner()->setJob(job, donate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -284,22 +280,8 @@ void xmrig::Network::getConnection(rapidjson::Value &reply, rapidjson::Document
|
||||||
using namespace rapidjson;
|
using namespace rapidjson;
|
||||||
auto &allocator = doc.GetAllocator();
|
auto &allocator = doc.GetAllocator();
|
||||||
|
|
||||||
reply.AddMember("algo", StringRef(m_strategy->client()->job().algorithm().shortName()), allocator);
|
reply.AddMember("algo", m_state->algorithm().toJSON(), allocator);
|
||||||
|
reply.AddMember("connection", m_state->getConnection(doc, version), 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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -308,25 +290,6 @@ void xmrig::Network::getResults(rapidjson::Value &reply, rapidjson::Document &do
|
||||||
using namespace rapidjson;
|
using namespace rapidjson;
|
||||||
auto &allocator = doc.GetAllocator();
|
auto &allocator = doc.GetAllocator();
|
||||||
|
|
||||||
Value results(kObjectType);
|
reply.AddMember("results", m_state->getResults(doc, version), allocator);
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -5,9 +5,9 @@
|
||||||
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
* Copyright 2014-2016 Wolf9466 <https://github.com/OhGodAPet>
|
||||||
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
* Copyright 2016 Jay D Dee <jayddee246@gmail.com>
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
* 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 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
|
* 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
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -27,24 +27,24 @@
|
||||||
#define XMRIG_NETWORK_H
|
#define XMRIG_NETWORK_H
|
||||||
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
|
|
||||||
#include "base/api/interfaces/IApiListener.h"
|
#include "base/api/interfaces/IApiListener.h"
|
||||||
#include "base/kernel/interfaces/IBaseListener.h"
|
#include "base/kernel/interfaces/IBaseListener.h"
|
||||||
#include "base/kernel/interfaces/IStrategyListener.h"
|
#include "base/kernel/interfaces/IStrategyListener.h"
|
||||||
#include "base/kernel/interfaces/ITimerListener.h"
|
#include "base/kernel/interfaces/ITimerListener.h"
|
||||||
#include "base/tools/Object.h"
|
#include "base/tools/Object.h"
|
||||||
#include "interfaces/IJobResultListener.h"
|
#include "interfaces/IJobResultListener.h"
|
||||||
#include "net/NetworkState.h"
|
|
||||||
#include "rapidjson/fwd.h"
|
#include "rapidjson/fwd.h"
|
||||||
|
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
namespace xmrig {
|
namespace xmrig {
|
||||||
|
|
||||||
|
|
||||||
class Controller;
|
class Controller;
|
||||||
class IStrategy;
|
class IStrategy;
|
||||||
|
class NetworkState;
|
||||||
|
|
||||||
|
|
||||||
class Network : public IJobResultListener, public IStrategyListener, public IBaseListener, public ITimerListener, public IApiListener
|
class Network : public IJobResultListener, public IStrategyListener, public IBaseListener, public ITimerListener, public IApiListener
|
||||||
|
@ -87,10 +87,10 @@ private:
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
Controller *m_controller;
|
Controller *m_controller;
|
||||||
IStrategy *m_donate;
|
IStrategy *m_donate = nullptr;
|
||||||
IStrategy *m_strategy;
|
IStrategy *m_strategy = nullptr;
|
||||||
NetworkState m_state;
|
NetworkState *m_state = nullptr;
|
||||||
Timer *m_timer;
|
Timer *m_timer = nullptr;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,123 +0,0 @@
|
||||||
/* 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>
|
|
||||||
* Copyright 2017-2018 XMR-Stak <https://github.com/fireice-uk>, <https://github.com/psychocrypt>
|
|
||||||
* Copyright 2018-2019 SChernykh <https://github.com/SChernykh>
|
|
||||||
* Copyright 2016-2019 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
|
|
||||||
* 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/>.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <uv.h>
|
|
||||||
|
|
||||||
|
|
||||||
#include "base/kernel/interfaces/IClient.h"
|
|
||||||
#include "base/net/stratum/Pool.h"
|
|
||||||
#include "base/net/stratum/SubmitResult.h"
|
|
||||||
#include "base/tools/Chrono.h"
|
|
||||||
#include "net/NetworkState.h"
|
|
||||||
|
|
||||||
|
|
||||||
xmrig::NetworkState::NetworkState() :
|
|
||||||
pool(),
|
|
||||||
accepted(0),
|
|
||||||
diff(0),
|
|
||||||
failures(0),
|
|
||||||
rejected(0),
|
|
||||||
total(0),
|
|
||||||
m_active(false)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
uint32_t xmrig::NetworkState::avgTime() const
|
|
||||||
{
|
|
||||||
if (m_latency.empty()) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return connectionTime() / (uint32_t)m_latency.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
uint32_t xmrig::NetworkState::latency() const
|
|
||||||
{
|
|
||||||
const size_t calls = m_latency.size();
|
|
||||||
if (calls == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto v = m_latency;
|
|
||||||
std::nth_element(v.begin(), v.begin() + calls / 2, v.end());
|
|
||||||
|
|
||||||
return v[calls / 2];
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
uint64_t xmrig::NetworkState::connectionTime() const
|
|
||||||
{
|
|
||||||
return m_active ? ((Chrono::steadyMSecs() - m_connectionTime) / 1000) : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void xmrig::NetworkState::add(const SubmitResult &result, const char *error)
|
|
||||||
{
|
|
||||||
if (error) {
|
|
||||||
rejected++;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
accepted++;
|
|
||||||
total += result.diff;
|
|
||||||
|
|
||||||
const size_t ln = topDiff.size() - 1;
|
|
||||||
if (result.actualDiff > topDiff[ln]) {
|
|
||||||
topDiff[ln] = result.actualDiff;
|
|
||||||
std::sort(topDiff.rbegin(), topDiff.rend());
|
|
||||||
}
|
|
||||||
|
|
||||||
m_latency.push_back(result.elapsed > 0xFFFF ? 0xFFFF : static_cast<uint16_t>(result.elapsed));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void xmrig::NetworkState::onActive(IClient *client)
|
|
||||||
{
|
|
||||||
snprintf(pool, sizeof(pool) - 1, "%s:%d", client->pool().host().data(), client->pool().port());
|
|
||||||
|
|
||||||
m_ip = client->ip();
|
|
||||||
m_tls = client->tlsVersion();
|
|
||||||
m_fingerprint = client->tlsFingerprint();
|
|
||||||
m_active = true;
|
|
||||||
m_connectionTime = Chrono::steadyMSecs();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void xmrig::NetworkState::stop()
|
|
||||||
{
|
|
||||||
m_active = false;
|
|
||||||
diff = 0;
|
|
||||||
m_ip = nullptr;
|
|
||||||
m_tls = nullptr;
|
|
||||||
m_fingerprint = nullptr;
|
|
||||||
|
|
||||||
failures++;
|
|
||||||
m_latency.clear();
|
|
||||||
}
|
|
Loading…
Reference in a new issue