mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-08-20 05:28:47 -06:00
Decode custom user from stratum client, display stratum client+user on SHARE FOUND and client mainchain found message
This commit is contained in:
parent
f17c23528a
commit
bc341918f6
@ -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)
|
bool StratumServer::get_custom_diff(const char* s, difficulty_type& diff)
|
||||||
{
|
{
|
||||||
const char* diff_str = nullptr;
|
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());
|
target = std::max(target, client->m_customDiff.target());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (get_custom_user(login, client->m_customUser)) {
|
||||||
|
LOGINFO(5, "client " << log::Gray() << static_cast<char*>(client->m_addrString) << " set custom user " << client->m_customUser);
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t job_id;
|
uint32_t job_id;
|
||||||
{
|
{
|
||||||
MutexLock lock(client->m_jobsLock);
|
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)) {
|
if (mainchain_diff.check_pow(resultHash)) {
|
||||||
LOGINFO(0, log::Green() << "client " << static_cast<char*>(client->m_addrString) << " found a mainchain block, submitting it");
|
LOGINFO(0, log::Green() << "client " << static_cast<char*>(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);
|
m_pool->submit_block_async(template_id, nonce, extra_nonce);
|
||||||
block.update_tx_keys();
|
block.update_tx_keys();
|
||||||
}
|
}
|
||||||
@ -645,7 +671,7 @@ void StratumServer::on_share_found(uv_work_t* req)
|
|||||||
server->m_cumulativeFoundSharesDiff += diff;
|
server->m_cumulativeFoundSharesDiff += diff;
|
||||||
++server->m_totalFoundShares;
|
++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<char*>(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);
|
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));
|
memset(m_jobs, 0, sizeof(m_jobs));
|
||||||
m_perConnectionJobId = 0;
|
m_perConnectionJobId = 0;
|
||||||
m_customDiff = {};
|
m_customDiff = {};
|
||||||
|
m_customUser.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StratumServer::StratumClient::on_read(char* data, uint32_t size)
|
bool StratumServer::StratumClient::on_read(char* data, uint32_t size)
|
||||||
|
@ -65,6 +65,7 @@ public:
|
|||||||
|
|
||||||
uint32_t m_perConnectionJobId;
|
uint32_t m_perConnectionJobId;
|
||||||
difficulty_type m_customDiff;
|
difficulty_type m_customDiff;
|
||||||
|
std::string m_customUser;
|
||||||
};
|
};
|
||||||
|
|
||||||
bool on_login(StratumClient* client, uint32_t id, const char* login);
|
bool on_login(StratumClient* client, uint32_t id, const char* login);
|
||||||
@ -77,6 +78,7 @@ private:
|
|||||||
void print_stratum_status() const;
|
void print_stratum_status() const;
|
||||||
|
|
||||||
static bool get_custom_diff(const char* s, difficulty_type& diff);
|
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_share_found(uv_work_t* req);
|
||||||
static void on_after_share_found(uv_work_t* req, int status);
|
static void on_after_share_found(uv_work_t* req, int status);
|
||||||
|
Loading…
Reference in New Issue
Block a user