diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3ba2457..ee1a8db 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -8,6 +8,11 @@ if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
endif()
endif()
+find_library(MHTD NAMES microhttpd)
+if("${MHTD}" STREQUAL "MHTD-NOTFOUND")
+ message(FATAL_ERROR "libmicrohttpd is required")
+endif()
+
#set(CMAKE_VERBOSE_MAKEFILE ON)
set(CMAKE_CONFIGURATION_TYPES "RELEASE;STATIC")
if("${CMAKE_BUILD_TYPE}" STREQUAL "")
@@ -25,6 +30,6 @@ set(EXECUTABLE_OUTPUT_PATH "bin")
file(GLOB SOURCES "crypto/*.c" "*.cpp")
add_executable(xmr-stak-cpu ${SOURCES})
-target_link_libraries(xmr-stak-cpu pthread)
+target_link_libraries(xmr-stak-cpu pthread microhttpd)
diff --git a/cli-miner.cpp b/cli-miner.cpp
index 6014d33..bc7c2d6 100644
--- a/cli-miner.cpp
+++ b/cli-miner.cpp
@@ -70,10 +70,13 @@ int main(int argc, char *argv[])
return 0;
}
- if (!httpd::inst()->start_daemon())
+ if(jconf::inst()->GetHttpdPort() != 0)
{
- win_exit();
- return 0;
+ if (!httpd::inst()->start_daemon())
+ {
+ win_exit();
+ return 0;
+ }
}
printer::inst()->print_str("-------------------------------------------------------------------\n");
diff --git a/config.txt b/config.txt
index dba5723..160ff1f 100644
--- a/config.txt
+++ b/config.txt
@@ -109,6 +109,16 @@
*/
"h_print_time" : 60,
+/*
+ * Built-in web server
+ * I like checking my hashrate on my phone. Don't you?
+ * Keep in mind that you will need to set up port forwarding on your router if you want to access it from
+ * outside of your home network. Ports lower than 1024 on Linux systems will require root.
+ *
+ * httpd_port - Port we should listen on. Default, 0, will switch off the server.
+ */
+"httpd_port" : 0,
+
/*
* 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/httpd.cpp b/httpd.cpp
index 32224f5..339d15f 100644
--- a/httpd.cpp
+++ b/httpd.cpp
@@ -7,6 +7,7 @@
#include "httpd.h"
#include "console.h"
#include "executor.h"
+#include "jconf.h"
#ifdef _WIN32
#include "libmicrohttpd/microhttpd.h"
@@ -81,7 +82,7 @@ int httpd::req_handler(void * cls,
bool httpd::start_daemon()
{
d = MHD_start_daemon(MHD_USE_THREAD_PER_CONNECTION,
- 8100, NULL, NULL,
+ jconf::inst()->GetHttpdPort(), NULL, NULL,
&httpd::req_handler,
NULL, MHD_OPTION_END);
diff --git a/jconf.cpp b/jconf.cpp
index b5ce836..4f9375d 100644
--- a/jconf.cpp
+++ b/jconf.cpp
@@ -34,8 +34,8 @@ using namespace rapidjson;
/*
* This enum needs to match index in oConfigValues, otherwise we will get a runtime error
*/
-enum configEnum { iCpuThreadNum, aCpuThreadsConf, sUseSlowMem, sPoolAddr,
- sWalletAddr, sPoolPwd, iCallTimeout, iNetRetry, iVerboseLevel, iAutohashTime, bPreferIpv4 };
+enum configEnum { iCpuThreadNum, aCpuThreadsConf, sUseSlowMem, sPoolAddr, sWalletAddr,
+ sPoolPwd, iCallTimeout, iNetRetry, iVerboseLevel, iAutohashTime, iHttpdPort, bPreferIpv4 };
struct configVal {
configEnum iName;
@@ -55,6 +55,7 @@ configVal oConfigValues[] = {
{ iNetRetry, "retry_time", kNumberType },
{ iVerboseLevel, "verbose_level", kNumberType },
{ iAutohashTime, "h_print_time", kNumberType },
+ { iHttpdPort, "httpd_port", kNumberType },
{ bPreferIpv4, "prefer_ipv4", kTrueType }
};
@@ -185,6 +186,11 @@ uint64_t jconf::GetAutohashTime()
return prv->configValues[iAutohashTime]->GetUint64();
}
+uint16_t jconf::GetHttpdPort()
+{
+ return prv->configValues[iHttpdPort]->GetUint();
+}
+
bool jconf::parse_config(const char* sFilename)
{
FILE * pFile;
@@ -317,6 +323,13 @@ bool jconf::parse_config(const char* sFilename)
return false;
}
+ if(!prv->configValues[iHttpdPort]->IsUint() || prv->configValues[iHttpdPort]->GetUint() > 0xFFFF)
+ {
+ printer::inst()->print_msg(L0,
+ "Invalid config file. httpd_port has to be in the range 0 to 65535.");
+ return false;
+ }
+
#ifdef _WIN32
if(GetSlowMemSetting() == no_mlck)
{
diff --git a/jconf.h b/jconf.h
index 0a2a7f8..c5ad620 100644
--- a/jconf.h
+++ b/jconf.h
@@ -40,6 +40,9 @@ public:
uint64_t GetCallTimeout();
uint64_t GetNetRetry();
+
+ uint16_t GetHttpdPort();
+
bool PreferIpv4();
private:
diff --git a/xmr-stak-cpu.cbp b/xmr-stak-cpu.cbp
index f362ca3..32a55d6 100644
--- a/xmr-stak-cpu.cbp
+++ b/xmr-stak-cpu.cbp
@@ -21,7 +21,6 @@
-
@@ -41,7 +40,6 @@
-
@@ -67,6 +65,10 @@
+
+
+
+
@@ -104,6 +106,8 @@
+
+