diff options
Diffstat (limited to 'xmrstak')
-rw-r--r-- | xmrstak/backend/amd/minethd.cpp | 1 | ||||
-rw-r--r-- | xmrstak/backend/cpu/minethd.cpp | 1 | ||||
-rw-r--r-- | xmrstak/backend/iBackend.hpp | 18 | ||||
-rw-r--r-- | xmrstak/backend/nvidia/minethd.cpp | 1 | ||||
-rw-r--r-- | xmrstak/config.tpl | 15 | ||||
-rw-r--r-- | xmrstak/http/httpd.cpp | 26 | ||||
-rw-r--r-- | xmrstak/http/webdesign.cpp | 11 | ||||
-rw-r--r-- | xmrstak/http/webdesign.hpp | 6 | ||||
-rw-r--r-- | xmrstak/jconf.cpp | 14 | ||||
-rw-r--r-- | xmrstak/jconf.hpp | 2 | ||||
-rw-r--r-- | xmrstak/misc/executor.cpp | 102 |
11 files changed, 159 insertions, 38 deletions
diff --git a/xmrstak/backend/amd/minethd.cpp b/xmrstak/backend/amd/minethd.cpp index f12e12c..912587b 100644 --- a/xmrstak/backend/amd/minethd.cpp +++ b/xmrstak/backend/amd/minethd.cpp @@ -49,6 +49,7 @@ namespace amd minethd::minethd(miner_work& pWork, size_t iNo, GpuContext* ctx, const jconf::thd_cfg cfg) { + this->backendType = iBackend::AMD; oWork = pWork; bQuit = 0; iThreadNo = (uint8_t)iNo; diff --git a/xmrstak/backend/cpu/minethd.cpp b/xmrstak/backend/cpu/minethd.cpp index d36ebf1..8b913cf 100644 --- a/xmrstak/backend/cpu/minethd.cpp +++ b/xmrstak/backend/cpu/minethd.cpp @@ -94,6 +94,7 @@ bool minethd::thd_setaffinity(std::thread::native_handle_type h, uint64_t cpu_id minethd::minethd(miner_work& pWork, size_t iNo, bool double_work, bool no_prefetch, int64_t affinity) { + this->backendType = iBackend::CPU; oWork = pWork; bQuit = 0; iThreadNo = (uint8_t)iNo; diff --git a/xmrstak/backend/iBackend.hpp b/xmrstak/backend/iBackend.hpp index ab964ce..dbfbc99 100644 --- a/xmrstak/backend/iBackend.hpp +++ b/xmrstak/backend/iBackend.hpp @@ -5,15 +5,31 @@ #include <atomic> #include <cstdint> #include <climits> - +#include <vector> +#include <string> namespace xmrstak { struct iBackend { + + enum BackendType : uint32_t { UNKNOWN = 0, CPU = 1u, AMD = 2u, NVIDIA = 3u }; + + static std::string getName(const BackendType type) + { + std::vector<std::string> backendNames = { + "UNKNOWN", + "CPU", + "AMD", + "NVIDIA" + }; + return backendNames[static_cast<uint32_t>(type)]; + } + std::atomic<uint64_t> iHashCount; std::atomic<uint64_t> iTimestamp; uint32_t iThreadNo; + BackendType backendType = UNKNOWN; iBackend() : iHashCount(0), iTimestamp(0) { diff --git a/xmrstak/backend/nvidia/minethd.cpp b/xmrstak/backend/nvidia/minethd.cpp index 0cf9a42..a1cafa7 100644 --- a/xmrstak/backend/nvidia/minethd.cpp +++ b/xmrstak/backend/nvidia/minethd.cpp @@ -66,6 +66,7 @@ namespace nvidia minethd::minethd(miner_work& pWork, size_t iNo, const jconf::thd_cfg& cfg) { + this->backendType = iBackend::NVIDIA; oWork = pWork; bQuit = 0; iThreadNo = (uint8_t)iNo; diff --git a/xmrstak/config.tpl b/xmrstak/config.tpl index c06d121..c3ea061 100644 --- a/xmrstak/config.tpl +++ b/xmrstak/config.tpl @@ -106,7 +106,7 @@ POOLCONF], */ /* - * use_slow_memory defines our behavior with regards to large pages. There are three possible options here: + * use_slow_memory defines our behaviour with regards to large pages. There are three possible options here: * always - Don't even try to use large pages. Always use slow memory. * warn - We will try to use large pages, but fall back to slow memory if that fails. * no_mlck - This option is only relevant on Linux, where we can use large pages without locking memory. @@ -159,6 +159,19 @@ POOLCONF], "httpd_port" : 0, /* + * HTTP Authentication + * + * This allows you to set a password to keep people on the Internet from snooping on your hashrate. + * Keep in mind that this is based on HTTP Digest, which is based on MD5. To a determined attacker + * who is able to read your traffic it is as easy to break a bog door latch. + * + * http_login - Login. Empty login disables authentication. + * http_pass - Password. + */ +"http_login" : "", +"http_pass" : "", + +/* * prefer_ipv4 - IPv6 preference. If the host is available on both IPv4 and IPv6 net, which one should be choose? * This setting will only be needed in 2020's. No need to worry about it now. */ diff --git a/xmrstak/http/httpd.cpp b/xmrstak/http/httpd.cpp index a112bbb..8debfa7 100644 --- a/xmrstak/http/httpd.cpp +++ b/xmrstak/http/httpd.cpp @@ -62,8 +62,32 @@ int httpd::req_handler(void * cls, if (strcmp(method, "GET") != 0) return MHD_NO; - *ptr = nullptr; + if(strlen(jconf::inst()->GetHttpUsername()) != 0) + { + char* username; + int ret; + + username = MHD_digest_auth_get_username(connection); + if (username == NULL) + { + rsp = MHD_create_response_from_buffer(sHtmlAccessDeniedSize, (void*)sHtmlAccessDenied, MHD_RESPMEM_PERSISTENT); + ret = MHD_queue_auth_fail_response(connection, sHttpAuthRelam, sHttpAuthOpaque, rsp, MHD_NO); + MHD_destroy_response(rsp); + return ret; + } + free(username); + ret = MHD_digest_auth_check(connection, sHttpAuthRelam, jconf::inst()->GetHttpUsername(), jconf::inst()->GetHttpPassword(), 300); + if (ret == MHD_INVALID_NONCE || ret == MHD_NO) + { + rsp = MHD_create_response_from_buffer(sHtmlAccessDeniedSize, (void*)sHtmlAccessDenied, MHD_RESPMEM_PERSISTENT); + ret = MHD_queue_auth_fail_response(connection, sHttpAuthRelam, sHttpAuthOpaque, rsp, (ret == MHD_INVALID_NONCE) ? MHD_YES : MHD_NO); + MHD_destroy_response(rsp); + return ret; + } + } + + *ptr = nullptr; std::string str; if(strcasecmp(url, "/style.css") == 0) { diff --git a/xmrstak/http/webdesign.cpp b/xmrstak/http/webdesign.cpp index 3b21ae0..3c33e1f 100644 --- a/xmrstak/http/webdesign.cpp +++ b/xmrstak/http/webdesign.cpp @@ -96,6 +96,17 @@ extern const char sHtmlCssFile [] = size_t sHtmlCssSize = sizeof(sHtmlCssFile) - 1; +extern const char sHttpAuthRelam[] = "XMR-Stak-Miner"; +extern const char sHttpAuthOpaque[] = "6c071f0df539e234cadbcd79164af7a594e23ab42bccb834df796aead6ce96e4"; + +extern const char sHtmlAccessDenied[] = + "<!DOCTYPE html><html>" + "<head><title>Access Denied</title></head>" + "<body><h1>Access Denied</h1><p>You have entered a wrong username or password</p></body>" + "</html>"; + +size_t sHtmlAccessDeniedSize = sizeof(sHtmlAccessDenied) - 1; + extern const char sHtmlCommonHeader [] = "<!DOCTYPE html>" "<html>" diff --git a/xmrstak/http/webdesign.hpp b/xmrstak/http/webdesign.hpp index 92639a0..122b5fb 100644 --- a/xmrstak/http/webdesign.hpp +++ b/xmrstak/http/webdesign.hpp @@ -4,6 +4,12 @@ extern const char sHtmlCssEtag[]; extern const char sHtmlCssFile[]; extern size_t sHtmlCssSize; +extern const char sHtmlAccessDenied[]; +extern size_t sHtmlAccessDeniedSize; + +extern const char sHttpAuthRelam[]; +extern const char sHttpAuthOpaque[]; + extern const char sHtmlCommonHeader[]; extern const char sHtmlHashrateBodyHigh[]; diff --git a/xmrstak/jconf.cpp b/xmrstak/jconf.cpp index ec1233a..0418842 100644 --- a/xmrstak/jconf.cpp +++ b/xmrstak/jconf.cpp @@ -52,7 +52,7 @@ using namespace rapidjson; */ enum configEnum { aPoolList, bTlsSecureAlgo, sCurrency, iCallTimeout, iNetRetry, iGiveUpLimit, iVerboseLevel, iAutohashTime, - bFlushStdout, bDaemonMode, sOutputFile, iHttpdPort, bPreferIpv4, bAesOverride, sUseSlowMem + bFlushStdout, bDaemonMode, sOutputFile, iHttpdPort, sHttpLogin, sHttpPass, bPreferIpv4, bAesOverride, sUseSlowMem }; struct configVal { @@ -76,6 +76,8 @@ configVal oConfigValues[] = { { bDaemonMode, "daemon_mode", kTrueType }, { sOutputFile, "output_file", kStringType }, { iHttpdPort, "httpd_port", kNumberType }, + { sHttpLogin, "http_login", kStringType }, + { sHttpPass, "http_pass", kStringType }, { bPreferIpv4, "prefer_ipv4", kTrueType }, { bAesOverride, "aes_override", kNullType }, { sUseSlowMem, "use_slow_memory", kStringType } @@ -236,6 +238,16 @@ uint16_t jconf::GetHttpdPort() return prv->configValues[iHttpdPort]->GetUint(); } +const char* jconf::GetHttpUsername() +{ + return prv->configValues[sHttpLogin]->GetString(); +} + +const char* jconf::GetHttpPassword() +{ + return prv->configValues[sHttpPass]->GetString(); +} + bool jconf::DaemonMode() { return prv->configValues[bDaemonMode]->GetBool(); diff --git a/xmrstak/jconf.hpp b/xmrstak/jconf.hpp index b68ef38..1bd4d47 100644 --- a/xmrstak/jconf.hpp +++ b/xmrstak/jconf.hpp @@ -60,6 +60,8 @@ public: uint64_t GetGiveUpLimit(); uint16_t GetHttpdPort(); + const char* GetHttpUsername(); + const char* GetHttpPassword(); bool DaemonMode(); diff --git a/xmrstak/misc/executor.cpp b/xmrstak/misc/executor.cpp index 7d3a57d..454d1cf 100644 --- a/xmrstak/misc/executor.cpp +++ b/xmrstak/misc/executor.cpp @@ -29,6 +29,7 @@ #include "xmrstak/backend/miner_work.hpp" #include "xmrstak/backend/globalStates.hpp" #include "xmrstak/backend/backendConnector.hpp" +#include "xmrstak/backend/iBackend.hpp" #include "xmrstak/jconf.hpp" #include "xmrstak/misc/console.hpp" @@ -451,8 +452,26 @@ void executor::on_miner_result(size_t pool_id, job_result& oResult) } } +#ifndef _WIN32 + +#include <signal.h> +void disable_sigpipe() +{ + struct sigaction sa; + sa.sa_handler = SIG_IGN; + sa.sa_flags = 0; + if (sigaction(SIGPIPE, &sa, 0) == -1) + printer::inst()->print_msg(L1, "ERROR: Call to sigaction failed!"); +} + +#else +inline void disable_sigpipe() {} +#endif + void executor::ex_main() { + disable_sigpipe(); + assert(1000 % iTickTime == 0); xmrstak::miner_work oWork = xmrstak::miner_work(); @@ -603,49 +622,64 @@ inline const char* hps_format(double h, char* buf, size_t l) void executor::hashrate_report(std::string& out) { char num[32]; - size_t nthd = pvThreads->size(); - - out.reserve(256 + nthd * 64); - double fTotal[3] = { 0.0, 0.0, 0.0}; - size_t i; - - out.append("HASHRATE REPORT\n"); - out.append("| ID | 10s | 60s | 15m |"); - if(nthd != 1) - out.append(" ID | 10s | 60s | 15m |\n"); - else - out.append(1, '\n'); - for (i = 0; i < nthd; i++) + for( uint32_t b = 0; b < 4u; ++b) { - double fHps[3]; + std::vector<xmrstak::iBackend*> backEnds; + std::copy_if(pvThreads->begin(), pvThreads->end(), std::back_inserter(backEnds), + [&](xmrstak::iBackend* backend) + { + return backend->backendType == b; + } + ); - fHps[0] = telem->calc_telemetry_data(10000, i); - fHps[1] = telem->calc_telemetry_data(60000, i); - fHps[2] = telem->calc_telemetry_data(900000, i); + 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"); + out.append("| ID | 10s | 60s | 15m |"); + if(nthd != 1) + out.append(" ID | 10s | 60s | 15m |\n"); + else + out.append(1, '\n'); - snprintf(num, sizeof(num), "| %2u |", (unsigned int)i); - out.append(num); - out.append(hps_format(fHps[0], num, sizeof(num))).append(" |"); - out.append(hps_format(fHps[1], num, sizeof(num))).append(" |"); - out.append(hps_format(fHps[2], num, sizeof(num))).append(1, ' '); + for (i = 0; i < nthd; i++) + { + double fHps[3]; - fTotal[0] += fHps[0]; - fTotal[1] += fHps[1]; - fTotal[2] += fHps[2]; + uint32_t tid = backEnds[i]->iThreadNo; + fHps[0] = telem->calc_telemetry_data(10000, tid); + fHps[1] = telem->calc_telemetry_data(60000, tid); + fHps[2] = telem->calc_telemetry_data(900000, tid); - if((i & 0x1) == 1) //Odd i's - out.append("|\n"); - } + snprintf(num, sizeof(num), "| %2u |", (unsigned int)i); + out.append(num); + out.append(hps_format(fHps[0], num, sizeof(num))).append(" |"); + out.append(hps_format(fHps[1], num, sizeof(num))).append(" |"); + out.append(hps_format(fHps[2], num, sizeof(num))).append(1, ' '); - if((i & 0x1) == 1) //We had odd number of threads - out.append("|\n"); + fTotal[0] += fHps[0]; + fTotal[1] += fHps[1]; + fTotal[2] += fHps[2]; - if(nthd != 1) - out.append("-----------------------------------------------------\n"); - else - out.append("---------------------------\n"); + if((i & 0x1) == 1) //Odd i's + out.append("|\n"); + } + + if((i & 0x1) == 1) //We had odd number of threads + out.append("|\n"); + + if(nthd != 1) + out.append("-----------------------------------------------------\n"); + else + out.append("---------------------------\n"); + } + } out.append("Totals: "); out.append(hps_format(fTotal[0], num, sizeof(num))); |