mirror of
https://github.com/SChernykh/p2pool.git
synced 2025-01-03 17:29:24 +00:00
StratumServer: added console command workers
This commit is contained in:
parent
6e1f34b168
commit
0818d91f4f
5 changed files with 59 additions and 21 deletions
|
@ -76,7 +76,7 @@ typedef struct cmd {
|
||||||
cmdfunc *func;
|
cmdfunc *func;
|
||||||
} cmd;
|
} cmd;
|
||||||
|
|
||||||
static cmdfunc do_help, do_status, do_loglevel, do_addpeers, do_droppeers, do_showpeers, do_showbans, do_outpeers, do_inpeers, do_exit;
|
static cmdfunc do_help, do_status, do_loglevel, do_addpeers, do_droppeers, do_showpeers, do_showworkers, do_showbans, do_outpeers, do_inpeers, do_exit;
|
||||||
|
|
||||||
#ifdef WITH_RANDOMX
|
#ifdef WITH_RANDOMX
|
||||||
static cmdfunc do_start_mining, do_stop_mining;
|
static cmdfunc do_start_mining, do_stop_mining;
|
||||||
|
@ -89,6 +89,7 @@ static cmd cmds[] = {
|
||||||
{ STRCONST("addpeers"), "<peeraddr>", "add peer", do_addpeers },
|
{ STRCONST("addpeers"), "<peeraddr>", "add peer", do_addpeers },
|
||||||
{ STRCONST("droppeers"), "", "disconnect all peers", do_droppeers },
|
{ STRCONST("droppeers"), "", "disconnect all peers", do_droppeers },
|
||||||
{ STRCONST("peers"), "", "show all peers", do_showpeers },
|
{ STRCONST("peers"), "", "show all peers", do_showpeers },
|
||||||
|
{ STRCONST("workers"), "", "show all connected workers", do_showworkers },
|
||||||
{ STRCONST("bans"), "", "show all banned IPs", do_showbans },
|
{ STRCONST("bans"), "", "show all banned IPs", do_showbans },
|
||||||
{ STRCONST("outpeers"), "", "set maximum number of outgoing connections", do_outpeers },
|
{ STRCONST("outpeers"), "", "set maximum number of outgoing connections", do_outpeers },
|
||||||
{ STRCONST("inpeers"), "", "set maximum number of incoming connections", do_inpeers },
|
{ STRCONST("inpeers"), "", "set maximum number of incoming connections", do_inpeers },
|
||||||
|
@ -158,6 +159,14 @@ static int do_showpeers(p2pool* m_pool, const char* /* args */)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int do_showworkers(p2pool* m_pool, const char* /* args */)
|
||||||
|
{
|
||||||
|
if (m_pool->stratum_server()) {
|
||||||
|
m_pool->stratum_server()->show_workers();
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int do_showbans(p2pool* m_pool, const char* /* args */)
|
static int do_showbans(p2pool* m_pool, const char* /* args */)
|
||||||
{
|
{
|
||||||
if (m_pool->stratum_server()) {
|
if (m_pool->stratum_server()) {
|
||||||
|
|
36
src/log.h
36
src/log.h
|
@ -184,7 +184,10 @@ INT_ENTRY(unsigned long)
|
||||||
template<typename T, int base>
|
template<typename T, int base>
|
||||||
struct BasedValue
|
struct BasedValue
|
||||||
{
|
{
|
||||||
explicit FORCEINLINE BasedValue(T value) : m_value(value) {}
|
explicit FORCEINLINE BasedValue(T value) : m_value(value)
|
||||||
|
{
|
||||||
|
static_assert(std::is_integral<T>::value, "Must be an integer type here");
|
||||||
|
}
|
||||||
|
|
||||||
T m_value;
|
T m_value;
|
||||||
};
|
};
|
||||||
|
@ -192,7 +195,7 @@ struct BasedValue
|
||||||
template<typename T, int base>
|
template<typename T, int base>
|
||||||
struct Stream::Entry<BasedValue<T, base>>
|
struct Stream::Entry<BasedValue<T, base>>
|
||||||
{
|
{
|
||||||
static FORCEINLINE void put(BasedValue<T, base>&& data, Stream* wrapper)
|
static FORCEINLINE void put(BasedValue<T, base> data, Stream* wrapper)
|
||||||
{
|
{
|
||||||
wrapper->writeInt<T, base>(data.m_value);
|
wrapper->writeInt<T, base>(data.m_value);
|
||||||
}
|
}
|
||||||
|
@ -356,7 +359,7 @@ struct XMRAmount
|
||||||
|
|
||||||
template<> struct log::Stream::Entry<XMRAmount>
|
template<> struct log::Stream::Entry<XMRAmount>
|
||||||
{
|
{
|
||||||
static NOINLINE void put(XMRAmount&& value, Stream* wrapper)
|
static NOINLINE void put(XMRAmount value, Stream* wrapper)
|
||||||
{
|
{
|
||||||
constexpr uint64_t denomination = 1000000000000ULL;
|
constexpr uint64_t denomination = 1000000000000ULL;
|
||||||
|
|
||||||
|
@ -375,7 +378,7 @@ template<> struct log::Stream::Entry<XMRAmount>
|
||||||
template<> struct log::Stream::Entry<NetworkType>
|
template<> struct log::Stream::Entry<NetworkType>
|
||||||
{
|
{
|
||||||
// cppcheck-suppress constParameter
|
// cppcheck-suppress constParameter
|
||||||
static NOINLINE void put(const NetworkType& value, Stream* wrapper)
|
static NOINLINE void put(NetworkType value, Stream* wrapper)
|
||||||
{
|
{
|
||||||
switch (value) {
|
switch (value) {
|
||||||
case NetworkType::Invalid: *wrapper << "invalid"; break;
|
case NetworkType::Invalid: *wrapper << "invalid"; break;
|
||||||
|
@ -386,6 +389,31 @@ template<> struct log::Stream::Entry<NetworkType>
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Duration
|
||||||
|
{
|
||||||
|
explicit FORCEINLINE Duration(uint64_t data) : m_data(data) {}
|
||||||
|
|
||||||
|
uint64_t m_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
template<> struct log::Stream::Entry<Duration>
|
||||||
|
{
|
||||||
|
static NOINLINE void put(Duration value, Stream* wrapper)
|
||||||
|
{
|
||||||
|
const uint64_t uptime = value.m_data;
|
||||||
|
|
||||||
|
const int64_t s = uptime % 60;
|
||||||
|
const int64_t m = (uptime / 60) % 60;
|
||||||
|
const int64_t h = (uptime / 3600) % 24;
|
||||||
|
const int64_t d = uptime / 86400;
|
||||||
|
|
||||||
|
if (d > 0) {
|
||||||
|
*wrapper << d << "d ";
|
||||||
|
}
|
||||||
|
*wrapper << h << "h " << m << "m " << s << 's';
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
void put_rawip(const raw_ip& value, Stream* wrapper);
|
void put_rawip(const raw_ip& value, Stream* wrapper);
|
||||||
|
|
||||||
template<> struct log::Stream::Entry<raw_ip>
|
template<> struct log::Stream::Entry<raw_ip>
|
||||||
|
|
|
@ -855,25 +855,10 @@ uint64_t P2PServer::get_random64()
|
||||||
|
|
||||||
void P2PServer::print_status()
|
void P2PServer::print_status()
|
||||||
{
|
{
|
||||||
const int64_t uptime = seconds_since_epoch() - m_pool->start_time();
|
|
||||||
|
|
||||||
const int64_t s = uptime % 60;
|
|
||||||
const int64_t m = (uptime / 60) % 60;
|
|
||||||
const int64_t h = (uptime / 3600) % 24;
|
|
||||||
const int64_t d = uptime / 86400;
|
|
||||||
|
|
||||||
char buf[log::Stream::BUF_SIZE + 1];
|
|
||||||
log::Stream s1(buf);
|
|
||||||
|
|
||||||
if (d > 0) {
|
|
||||||
s1 << d << "d ";
|
|
||||||
}
|
|
||||||
s1 << h << "h " << m << "m " << s << 's';
|
|
||||||
|
|
||||||
LOGINFO(0, "status" <<
|
LOGINFO(0, "status" <<
|
||||||
"\nConnections = " << m_numConnections << " (" << m_numIncomingConnections << " incoming)" <<
|
"\nConnections = " << m_numConnections << " (" << m_numIncomingConnections << " incoming)" <<
|
||||||
"\nPeer list size = " << m_peerList.size() <<
|
"\nPeer list size = " << m_peerList.size() <<
|
||||||
"\nUptime = " << log::const_buf(buf, s1.m_pos)
|
"\nUptime = " << log::Duration(seconds_since_epoch() - m_pool->start_time())
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -441,6 +441,21 @@ void StratumServer::print_status()
|
||||||
print_stratum_status();
|
print_stratum_status();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void StratumServer::show_workers()
|
||||||
|
{
|
||||||
|
const uint64_t cur_time = seconds_since_epoch();
|
||||||
|
|
||||||
|
MutexLock lock(m_clientsListLock);
|
||||||
|
|
||||||
|
for (StratumClient* c = static_cast<StratumClient*>(m_connectedClientsList->m_next); c != m_connectedClientsList; c = static_cast<StratumClient*>(c->m_next)) {
|
||||||
|
LOGINFO(0, static_cast<char*>(c->m_addrString)
|
||||||
|
<< '\t' << (c->m_rpcId ? " " : "*") << log::Duration(cur_time - c->m_connectedTime)
|
||||||
|
<< '\t' << c->m_customDiff
|
||||||
|
<< '\t' << c->m_customUser
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void StratumServer::reset_share_counters()
|
void StratumServer::reset_share_counters()
|
||||||
{
|
{
|
||||||
m_cumulativeHashesAtLastShare = 0;
|
m_cumulativeHashesAtLastShare = 0;
|
||||||
|
|
|
@ -73,6 +73,7 @@ public:
|
||||||
uint64_t get_random64();
|
uint64_t get_random64();
|
||||||
|
|
||||||
void print_status() override;
|
void print_status() override;
|
||||||
|
void show_workers();
|
||||||
|
|
||||||
void reset_share_counters();
|
void reset_share_counters();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue