From bc341918f6fc866d42a63b45e68d7aacff92ea56 Mon Sep 17 00:00:00 2001 From: WeebDataHoarder <57538841+WeebDataHoarder@users.noreply.github.com> Date: Fri, 15 Oct 2021 23:02:21 +0200 Subject: [PATCH] Decode custom user from stratum client, display stratum client+user on SHARE FOUND and client mainchain found message --- src/stratum_server.cpp | 31 +++++++++++++++++++++++++++++-- src/stratum_server.h | 2 ++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/stratum_server.cpp b/src/stratum_server.cpp index 25d5817..081f333 100644 --- a/src/stratum_server.cpp +++ b/src/stratum_server.cpp @@ -176,6 +176,28 @@ void StratumServer::on_block(const BlockTemplate& block) } } +bool StratumServer::get_custom_user(const char* s, std::string& user) +{ + user.clear(); + // Find first of '+' or '.', drop non-printable characters + while (s) { + const char c = *s; + if (!c) { + break; + } + if ((c == '+') || (c == '.')) { + break; + } + // Limit to printable ASCII characters + if (c >= ' ' && c <= '~') { + user += c; + } + ++s; + } + + return !user.empty(); +} + bool StratumServer::get_custom_diff(const char* s, difficulty_type& diff) { const char* diff_str = nullptr; @@ -225,6 +247,10 @@ bool StratumServer::on_login(StratumClient* client, uint32_t id, const char* log target = std::max(target, client->m_customDiff.target()); } + if (get_custom_user(login, client->m_customUser)) { + LOGINFO(5, "client " << log::Gray() << static_cast(client->m_addrString) << " set custom user " << client->m_customUser); + } + uint32_t job_id; { MutexLock lock(client->m_jobsLock); @@ -334,7 +360,7 @@ bool StratumServer::on_submit(StratumClient* client, uint32_t id, const char* jo } if (mainchain_diff.check_pow(resultHash)) { - LOGINFO(0, log::Green() << "client " << static_cast(client->m_addrString) << " found a mainchain block, submitting it"); + LOGINFO(0, log::Green() << "client " << static_cast(client->m_addrString) << (!client->m_customUser.empty() ? " user " + client->m_customUser : "") << " found a mainchain block, submitting it"); m_pool->submit_block_async(template_id, nonce, extra_nonce); block.update_tx_keys(); } @@ -645,7 +671,7 @@ void StratumServer::on_share_found(uv_work_t* req) server->m_cumulativeFoundSharesDiff += diff; ++server->m_totalFoundShares; - LOGINFO(0, log::Green() << "SHARE FOUND: mainchain height " << height << ", diff " << sidechain_difficulty << ", effort " << effort << '%'); + LOGINFO(0, log::Green() << "SHARE FOUND: mainchain height " << height << ", diff " << sidechain_difficulty << ", client " << static_cast(client->m_addrString) << (!client->m_customUser.empty() ? " user " + client->m_customUser : "") << ", effort " << effort << '%'); pool->submit_sidechain_block(share->m_templateId, share->m_nonce, share->m_extraNonce); } @@ -742,6 +768,7 @@ void StratumServer::StratumClient::reset() memset(m_jobs, 0, sizeof(m_jobs)); m_perConnectionJobId = 0; m_customDiff = {}; + m_customUser.clear(); } bool StratumServer::StratumClient::on_read(char* data, uint32_t size) diff --git a/src/stratum_server.h b/src/stratum_server.h index 18e7f43..56a30e9 100644 --- a/src/stratum_server.h +++ b/src/stratum_server.h @@ -65,6 +65,7 @@ public: uint32_t m_perConnectionJobId; difficulty_type m_customDiff; + std::string m_customUser; }; bool on_login(StratumClient* client, uint32_t id, const char* login); @@ -77,6 +78,7 @@ private: void print_stratum_status() const; static bool get_custom_diff(const char* s, difficulty_type& diff); + static bool get_custom_user(const char* s, std::string& user); static void on_share_found(uv_work_t* req); static void on_after_share_found(uv_work_t* req, int status);