diff options
Diffstat (limited to 'xmrstak/misc/executor.cpp')
-rw-r--r-- | xmrstak/misc/executor.cpp | 103 |
1 files changed, 98 insertions, 5 deletions
diff --git a/xmrstak/misc/executor.cpp b/xmrstak/misc/executor.cpp index 4a3a77b..43e3d6b 100644 --- a/xmrstak/misc/executor.cpp +++ b/xmrstak/misc/executor.cpp @@ -400,12 +400,13 @@ void executor::on_pool_have_job(size_t pool_id, pool_job& oPoolJob) void executor::on_miner_result(size_t pool_id, job_result& oResult) { jpsock* pool = pick_pool_by_id(pool_id); + bool is_monero = jconf::inst()->IsCurrencyMonero(); if(pool->is_dev_pool()) { //Ignore errors silently if(pool->is_running() && pool->is_logged_in()) - pool->cmd_submit(oResult.sJobID, oResult.iNonce, oResult.bResult); + pool->cmd_submit(oResult.sJobID, oResult.iNonce, oResult.bResult, pvThreads->at(oResult.iThreadId), is_monero); return; } @@ -418,7 +419,7 @@ void executor::on_miner_result(size_t pool_id, job_result& oResult) using namespace std::chrono; size_t t_start = time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count(); - bool bResult = pool->cmd_submit(oResult.sJobID, oResult.iNonce, oResult.bResult); + bool bResult = pool->cmd_submit(oResult.sJobID, oResult.iNonce, oResult.bResult, pvThreads->at(oResult.iThreadId), is_monero); size_t t_len = time_point_cast<milliseconds>(high_resolution_clock::now()).time_since_epoch().count() - t_start; if(t_len > 0xFFFF) @@ -630,8 +631,75 @@ inline const char* hps_format(double h, char* buf, size_t l) return " (na)"; } +bool executor::motd_filter_console(std::string& motd) +{ + if(motd.size() > motd_max_length) + return false; + + motd.erase(std::remove_if(motd.begin(), motd.end(), [](int chr)->bool { return !((chr >= 0x20 && chr <= 0x7e) || chr == '\n');}), motd.end()); + return motd.size() > 0; +} + +bool executor::motd_filter_web(std::string& motd) +{ + if(!motd_filter_console(motd)) + return false; + + std::string tmp; + tmp.reserve(motd.size() + 128); + + for(size_t i=0; i < motd.size(); i++) + { + char c = motd[i]; + switch(c) + { + case '&': + tmp.append("&"); + break; + case '"': + tmp.append("""); + break; + case '\'': + tmp.append("'"); + break; + case '<': + tmp.append("<"); + break; + case '>': + tmp.append(">"); + break; + case '\n': + tmp.append("<br>"); + break; + default: + tmp.append(1, c); + break; + } + } + + motd = std::move(tmp); + return true; +} + void executor::hashrate_report(std::string& out) { + out.reserve(2048 + pvThreads->size() * 64); + + if(jconf::inst()->PrintMotd()) + { + std::string motd; + for(jpsock& pool : pools) + { + motd.empty(); + if(pool.get_pool_motd(motd) && motd_filter_console(motd)) + { + out.append("Message from ").append(pool.get_pool_addr()).append(":\n"); + out.append(motd).append("\n"); + out.append("-----------------------------------------------------\n"); + } + } + } + char num[32]; double fTotal[3] = { 0.0, 0.0, 0.0}; @@ -648,11 +716,12 @@ void executor::hashrate_report(std::string& out) size_t nthd = backEnds.size(); if(nthd != 0) { - out.reserve(256 + nthd * 64); - size_t i; auto bType = static_cast<xmrstak::iBackend::BackendType>(b); - out.append("HASHRATE REPORT - ").append(xmrstak::iBackend::getName(bType)).append("\n"); + std::string name(xmrstak::iBackend::getName(bType)); + std::transform(name.begin(), name.end(), name.begin(), ::toupper); + + out.append("HASHRATE REPORT - ").append(name).append("\n"); out.append("| ID | 10s | 60s | 15m |"); if(nthd != 1) out.append(" ID | 10s | 60s | 15m |\n"); @@ -864,6 +933,30 @@ void executor::http_hashrate_report(std::string& out) snprintf(buffer, sizeof(buffer), sHtmlCommonHeader, "Hashrate Report", ver_html, "Hashrate Report"); out.append(buffer); + bool have_motd = false; + if(jconf::inst()->PrintMotd()) + { + std::string motd; + for(jpsock& pool : pools) + { + motd.empty(); + if(pool.get_pool_motd(motd) && motd_filter_web(motd)) + { + if(!have_motd) + { + out.append(sHtmlMotdBoxStart); + have_motd = true; + } + + snprintf(buffer, sizeof(buffer), sHtmlMotdEntry, pool.get_pool_addr(), motd.c_str()); + out.append(buffer); + } + } + } + + if(have_motd) + out.append(sHtmlMotdBoxEnd); + snprintf(buffer, sizeof(buffer), sHtmlHashrateBodyHigh, (unsigned int)nthd + 3); out.append(buffer); |