Added global uptime and extended connection information for API.
This commit is contained in:
parent
a000544fdc
commit
ffb282a11a
6 changed files with 45 additions and 15 deletions
|
@ -100,7 +100,7 @@ void xmrig::Network::onActive(IStrategy *strategy, IClient *client)
|
|||
return;
|
||||
}
|
||||
|
||||
m_state.setPool(client->pool().host(), client->pool().port(), client->ip());
|
||||
m_state.onActive(client);
|
||||
|
||||
const char *tlsVersion = client->tlsVersion();
|
||||
LOG_INFO(WHITE_BOLD("use %s ") CYAN_BOLD("%s:%d ") GREEN_BOLD("%s") " " BLACK_BOLD("%s"),
|
||||
|
@ -235,11 +235,14 @@ void xmrig::Network::getConnection(rapidjson::Value &reply, rapidjson::Document
|
|||
reply.AddMember("algo", StringRef((algo.isValid() ? algo : m_controller->config()->algorithm()).shortName()), allocator);
|
||||
|
||||
Value connection(kObjectType);
|
||||
connection.AddMember("pool", StringRef(m_state.pool), allocator);
|
||||
connection.AddMember("uptime", m_state.connectionTime(), allocator);
|
||||
connection.AddMember("ping", m_state.latency(), allocator);
|
||||
connection.AddMember("failures", m_state.failures, allocator);
|
||||
connection.AddMember("error_log", Value(kArrayType), allocator);
|
||||
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);
|
||||
connection.AddMember("error_log", Value(kArrayType), allocator);
|
||||
|
||||
reply.AddMember("connection", connection, allocator);
|
||||
}
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
#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"
|
||||
|
@ -96,19 +98,25 @@ void xmrig::NetworkState::add(const SubmitResult &result, const char *error)
|
|||
}
|
||||
|
||||
|
||||
void xmrig::NetworkState::setPool(const char *host, int port, const char *ip)
|
||||
void xmrig::NetworkState::onActive(IClient *client)
|
||||
{
|
||||
snprintf(pool, sizeof(pool) - 1, "%s:%d", host, port);
|
||||
snprintf(pool, sizeof(pool) - 1, "%s:%d", client->pool().host().data(), client->pool().port());
|
||||
|
||||
m_active = true;
|
||||
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_active = false;
|
||||
diff = 0;
|
||||
m_ip = nullptr;
|
||||
m_tls = nullptr;
|
||||
m_fingerprint = nullptr;
|
||||
|
||||
failures++;
|
||||
m_latency.clear();
|
||||
|
|
|
@ -30,9 +30,13 @@
|
|||
#include <vector>
|
||||
|
||||
|
||||
#include "base/tools/String.h"
|
||||
|
||||
|
||||
namespace xmrig {
|
||||
|
||||
|
||||
class IClient;
|
||||
class SubmitResult;
|
||||
|
||||
|
||||
|
@ -41,11 +45,15 @@ class NetworkState
|
|||
public:
|
||||
NetworkState();
|
||||
|
||||
inline const String &fingerprint() const { return m_fingerprint; }
|
||||
inline const String &ip() const { return m_ip; }
|
||||
inline const String &tls() const { return m_tls; }
|
||||
|
||||
uint32_t avgTime() const;
|
||||
uint32_t latency() const;
|
||||
uint64_t connectionTime() const;
|
||||
void add(const SubmitResult &result, const char *error);
|
||||
void setPool(const char *host, int port, const char *ip);
|
||||
void onActive(IClient *client);
|
||||
void stop();
|
||||
|
||||
char pool[256];
|
||||
|
@ -59,6 +67,9 @@ public:
|
|||
private:
|
||||
bool m_active;
|
||||
std::vector<uint16_t> m_latency;
|
||||
String m_fingerprint;
|
||||
String m_ip;
|
||||
String m_tls;
|
||||
uint64_t m_connectionTime;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue