From ecbb179e48bfc130e17723bfff23722e5740907b Mon Sep 17 00:00:00 2001 From: Herscht Date: Thu, 12 Apr 2018 23:05:18 +0200 Subject: [PATCH 1/5] Panel on plot page + Server/Requesthandler implementation --- resources/public/js/plotfiles.js | 9 ++++ resources/public/plotfiles.html | 72 ++++++++++++++++++++++++-------- src/plots/PlotGenerator.cpp | 5 +++ src/plots/PlotGenerator.hpp | 1 + src/webserver/MinerServer.cpp | 11 +++++ src/webserver/RequestHandler.cpp | 17 ++++++++ src/webserver/RequestHandler.hpp | 14 +++++++ 7 files changed, 111 insertions(+), 18 deletions(-) diff --git a/resources/public/js/plotfiles.js b/resources/public/js/plotfiles.js index 8264f4c..62d3a41 100644 --- a/resources/public/js/plotfiles.js +++ b/resources/public/js/plotfiles.js @@ -77,6 +77,7 @@ function createDirLine(dirElement, index) { activePlotDir = dirElement; colorConfirmedPlotfiles(); current_selected = dirElement; + $("#plot-folder").val(dirElement["path"]) }); return line; @@ -149,6 +150,14 @@ function parsePlots() { }); } +function startPlotting() { + console.log("Plotting nonces " + $("#start-nonce").val() + "-" + (Number($("#start-nonce").val())+Number($("#num-nonces").val())-1).toString() + " for ID "+ $("#account-id").val() + " to folder " + $("#plot-folder").val()); + var plotFolder=$("#plot-folder").val(); + if(plotFolder[1]==":") + plotFolder=plotFolder.replace(/\//g,"\\"); + $.post(encodeURI("/plotter/"+$("#account-id").val()+"/"+$("#start-nonce").val()+"/"+$("#num-nonces").val()+"/"+plotFolder)); +} + function checkPlotFile(account, start_nonce, nonces, staggersize, path) { if(!isChecking && !isCheckingAll) { diff --git a/resources/public/plotfiles.html b/resources/public/plotfiles.html index dcf8beb..2e09707 100644 --- a/resources/public/plotfiles.html +++ b/resources/public/plotfiles.html @@ -53,22 +53,58 @@

Directories

- -
-
-

Files

-
-
-
Account
-
Start nonce
-
Nonces
-
Stagger
-
Size
-
Integrity
-
-
-
    -
-
-
+ +
+
+

Files

+
+
+
Account
+
Start nonce
+
Nonces
+
Stagger
+
Size
+
Integrity
+
+
+
    +
+
+
+
Plotter
+
+
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ +
+
+ +
+
+
+
    +
+
+
\ No newline at end of file diff --git a/src/plots/PlotGenerator.cpp b/src/plots/PlotGenerator.cpp index 1292f26..b2842e7 100644 --- a/src/plots/PlotGenerator.cpp +++ b/src/plots/PlotGenerator.cpp @@ -200,6 +200,11 @@ double Burst::PlotGenerator::checkPlotfileIntegrity(std::string plotPath, Miner& return totalIntegrity / noncesChecked; } +void Burst::PlotGenerator::generatePlotfile(std::string plotPath, Miner& miner, MinerServer& server, std::string account, std::string sNonce, std::string nNonces) +{ + log_success(MinerLogger::general, "Starting to plot %s nonces starting from nonce %s for accountID %s to folder %s", nNonces, sNonce, account, plotPath); +} + std::array, Burst::Shabal256_SSE2::HashSize> Burst::PlotGenerator::generateSse2(const Poco::UInt64 account, const Poco::UInt64 startNonce) { return generate>(account, startNonce); diff --git a/src/plots/PlotGenerator.hpp b/src/plots/PlotGenerator.hpp index 66d3ec3..87c1380 100644 --- a/src/plots/PlotGenerator.hpp +++ b/src/plots/PlotGenerator.hpp @@ -41,6 +41,7 @@ namespace Burst public: static Poco::UInt64 generateAndCheck(Poco::UInt64 account, Poco::UInt64 nonce, const Miner& miner); static double checkPlotfileIntegrity(std::string plotPath, Miner& miner, MinerServer& server); + static void generatePlotfile(std::string plotPath, Miner& miner, MinerServer& server, std::string account, std::string sNonce, std::string nNonces); static std::array, Shabal256_SSE2::HashSize> generateSse2(Poco::UInt64 account, Poco::UInt64 startNonce); static std::array, Shabal256_AVX::HashSize> generateAvx(Poco::UInt64 account, Poco::UInt64 startNonce); diff --git a/src/webserver/MinerServer.cpp b/src/webserver/MinerServer.cpp index 559908d..20701dd 100644 --- a/src/webserver/MinerServer.cpp +++ b/src/webserver/MinerServer.cpp @@ -293,6 +293,17 @@ Poco::Net::HTTPRequestHandler* Burst::MinerServer::RequestFactory::createRequest }); } + // plot new file + if (path_segments.front() == "plotter") + if (path_segments.size() == 5) { + using Poco::replace; + std::string plotPath = ""; + Poco::URI::decode(replace(request.getURI(), "/" + path_segments[0] + "/" + path_segments[1] + "/" + path_segments[2] + "/" + path_segments[3] + "/", plotPath), plotPath, false); + return new LambdaRequestHandler([&, pPath = move(plotPath), account = move(path_segments[1]), sNonce = move(path_segments[2]), nNonces = move(path_segments[3])](req_t& req, res_t& res) + { + RequestHandler::plotNewFile(req, res, *server_->miner_, *server_, pPath, account, sNonce, nNonces); + }); + } // show/change plot files if (path_segments.front() == "plotdir") diff --git a/src/webserver/RequestHandler.cpp b/src/webserver/RequestHandler.cpp index c0903bd..12a9b7a 100644 --- a/src/webserver/RequestHandler.cpp +++ b/src/webserver/RequestHandler.cpp @@ -482,6 +482,23 @@ void Burst::RequestHandler::checkPlotfile(Poco::Net::HTTPServerRequest& request, } +void Burst::RequestHandler::plotNewFile(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response, Miner& miner, MinerServer& server, + std::string plotPath, std::string account, std::string sNonce, std::string nNonces) +{ + // first check the credentials + if (!checkCredentials(request, response)) + return; + + response.setStatus(Poco::Net::HTTPResponse::HTTP_OK); + response.setContentLength(0); + response.send(); + + log_information(MinerLogger::server, "Got request to plot new file..."); + + PlotGenerator::generatePlotfile(plotPath, miner, server, account, sNonce, nNonces); + +} + void Burst::RequestHandler::checkAllPlotfiles(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response, Miner& miner, MinerServer& server) { // first check the credentials diff --git a/src/webserver/RequestHandler.hpp b/src/webserver/RequestHandler.hpp index 186c141..7866c7e 100644 --- a/src/webserver/RequestHandler.hpp +++ b/src/webserver/RequestHandler.hpp @@ -233,6 +233,20 @@ namespace Burst void checkPlotfile(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response, Miner& miner, MinerServer& server, std::string plotPath); + /** + * \brief Checks a plot file for corruption + * \param request The HTTP request. + * \param response The HTTP response. + * \param miner The miner, which will propagate the changed config to his connected users. + * \param plotPath The path to the folder where to plot the new file + * \param account Account for which to plot the file. + * \param sNonce Starting nonce of the plotfile. + * \param nNonces Number of nonces to plot into this file. + * \param server The server instance, that is shut down. + */ + void plotNewFile(Poco::Net::HTTPServerRequest& request, Poco::Net::HTTPServerResponse& response, Miner& miner, + MinerServer& server, std::string plotPath, std::string account, std::string sNonce, std::string nNonces); + /** * \brief Checks all plot files for corruption * \param request The HTTP request. From 2f703526155d118c191b452bfd17430ec9a9033e Mon Sep 17 00:00:00 2001 From: Herscht Date: Fri, 13 Apr 2018 00:20:41 +0200 Subject: [PATCH 2/5] Linux URI fix --- src/webserver/MinerServer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/webserver/MinerServer.cpp b/src/webserver/MinerServer.cpp index 20701dd..eb24373 100644 --- a/src/webserver/MinerServer.cpp +++ b/src/webserver/MinerServer.cpp @@ -295,7 +295,7 @@ Poco::Net::HTTPRequestHandler* Burst::MinerServer::RequestFactory::createRequest // plot new file if (path_segments.front() == "plotter") - if (path_segments.size() == 5) { + if (path_segments.size() > 4) { using Poco::replace; std::string plotPath = ""; Poco::URI::decode(replace(request.getURI(), "/" + path_segments[0] + "/" + path_segments[1] + "/" + path_segments[2] + "/" + path_segments[3] + "/", plotPath), plotPath, false); From 7c76d0ba4cbe61420f1c2e9affbad1971f69f90f Mon Sep 17 00:00:00 2001 From: Herscht Date: Fri, 13 Apr 2018 00:36:44 +0200 Subject: [PATCH 3/5] Some playing around with Poco::File and Path --- src/plots/PlotGenerator.cpp | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/plots/PlotGenerator.cpp b/src/plots/PlotGenerator.cpp index b2842e7..f527d59 100644 --- a/src/plots/PlotGenerator.cpp +++ b/src/plots/PlotGenerator.cpp @@ -30,6 +30,8 @@ #include "webserver/MinerServer.hpp" #include #include +#include "Poco/File.h" +#include "Poco/Path.h" Poco::UInt64 Burst::PlotGenerator::generateAndCheck(Poco::UInt64 account, Poco::UInt64 nonce, const Miner& miner) { @@ -202,7 +204,15 @@ double Burst::PlotGenerator::checkPlotfileIntegrity(std::string plotPath, Miner& void Burst::PlotGenerator::generatePlotfile(std::string plotPath, Miner& miner, MinerServer& server, std::string account, std::string sNonce, std::string nNonces) { - log_success(MinerLogger::general, "Starting to plot %s nonces starting from nonce %s for accountID %s to folder %s", nNonces, sNonce, account, plotPath); + log_success(MinerLogger::general, "Starting to plot %s nonces beginning at nonce %s for accountID %s to folder %s", nNonces, sNonce, account, plotPath); + Poco::Path plotFilePath; + plotFilePath.parse(plotPath, Poco::Path::PATH_NATIVE); + plotFilePath.setFileName(account + "_" + sNonce + "_" + nNonces + "_" + nNonces); + log_success(MinerLogger::general, "Full plot path: %s", plotFilePath.toString()); + Poco::File plotFile(plotFilePath.getFileName()); + plotFile.createFile(); + plotFile.setSize(1024 * 1024); + log_success(MinerLogger::general, "Free Space on this device: %s", std::to_string(plotFile.freeSpace())+" GB"); } std::array, Burst::Shabal256_SSE2::HashSize> Burst::PlotGenerator::generateSse2(const Poco::UInt64 account, const Poco::UInt64 startNonce) From 4e3cbe2f42438cebc2803e0e8ec06e65627e500b Mon Sep 17 00:00:00 2001 From: Herscht Date: Fri, 13 Apr 2018 04:00:12 +0200 Subject: [PATCH 4/5] Correct Size allocation - added plot size calculator - allocate the size needed for the complete plot after creating the file --- resources/public/js/plotfiles.js | 11 +++++++++++ resources/public/plotfiles.html | 9 ++++++--- src/plots/PlotGenerator.cpp | 8 ++++++-- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/resources/public/js/plotfiles.js b/resources/public/js/plotfiles.js index 62d3a41..9440f24 100644 --- a/resources/public/js/plotfiles.js +++ b/resources/public/js/plotfiles.js @@ -158,6 +158,17 @@ function startPlotting() { $.post(encodeURI("/plotter/"+$("#account-id").val()+"/"+$("#start-nonce").val()+"/"+$("#num-nonces").val()+"/"+plotFolder)); } +function calcPlotSize() { + var plotSize = $("#num-nonces").val()*262144; + if (plotSize > 1099511627776) + plotSize = (Math.round(plotSize/1099511627776*1000)/1000).toString()+ " TB"; + else if (plotSize > 1073741824) + plotSize = (Math.round(plotSize/1073741824*1000)/1000).toString()+ " GB"; + else + plotSize = (Math.round(plotSize/1048576*1000)/1000).toString()+ " MB"; + $("#fileSize").val(plotSize); +} + function checkPlotFile(account, start_nonce, nonces, staggersize, path) { if(!isChecking && !isCheckingAll) { diff --git a/resources/public/plotfiles.html b/resources/public/plotfiles.html index 2e09707..b951c1a 100644 --- a/resources/public/plotfiles.html +++ b/resources/public/plotfiles.html @@ -71,7 +71,7 @@

Files

-
Plotter
+

Plotter

@@ -95,8 +95,11 @@

Files

-
- +
+ +
+
+
diff --git a/src/plots/PlotGenerator.cpp b/src/plots/PlotGenerator.cpp index f527d59..ad6884e 100644 --- a/src/plots/PlotGenerator.cpp +++ b/src/plots/PlotGenerator.cpp @@ -32,6 +32,7 @@ #include #include "Poco/File.h" #include "Poco/Path.h" +#include Poco::UInt64 Burst::PlotGenerator::generateAndCheck(Poco::UInt64 account, Poco::UInt64 nonce, const Miner& miner) { @@ -204,14 +205,17 @@ double Burst::PlotGenerator::checkPlotfileIntegrity(std::string plotPath, Miner& void Burst::PlotGenerator::generatePlotfile(std::string plotPath, Miner& miner, MinerServer& server, std::string account, std::string sNonce, std::string nNonces) { + const auto accountId = Poco::NumberParser::parseUnsigned64(account); + const auto startNonce = Poco::NumberParser::parseUnsigned64(sNonce); + const auto nonceCount = Poco::NumberParser::parseUnsigned64(nNonces); log_success(MinerLogger::general, "Starting to plot %s nonces beginning at nonce %s for accountID %s to folder %s", nNonces, sNonce, account, plotPath); Poco::Path plotFilePath; plotFilePath.parse(plotPath, Poco::Path::PATH_NATIVE); plotFilePath.setFileName(account + "_" + sNonce + "_" + nNonces + "_" + nNonces); log_success(MinerLogger::general, "Full plot path: %s", plotFilePath.toString()); - Poco::File plotFile(plotFilePath.getFileName()); + Poco::File plotFile(plotFilePath); plotFile.createFile(); - plotFile.setSize(1024 * 1024); + plotFile.setSize(nonceCount * Settings::PlotSize); log_success(MinerLogger::general, "Free Space on this device: %s", std::to_string(plotFile.freeSpace())+" GB"); } From 9f7df69e18e99f6fc6830606c96faa02b5ef2c47 Mon Sep 17 00:00:00 2001 From: Herscht Date: Sat, 14 Apr 2018 00:20:27 +0200 Subject: [PATCH 5/5] removed windows.h an stuff --- src/plots/PlotGenerator.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/plots/PlotGenerator.cpp b/src/plots/PlotGenerator.cpp index ad6884e..ecf79c1 100644 --- a/src/plots/PlotGenerator.cpp +++ b/src/plots/PlotGenerator.cpp @@ -32,7 +32,6 @@ #include #include "Poco/File.h" #include "Poco/Path.h" -#include Poco::UInt64 Burst::PlotGenerator::generateAndCheck(Poco::UInt64 account, Poco::UInt64 nonce, const Miner& miner) { @@ -214,9 +213,16 @@ void Burst::PlotGenerator::generatePlotfile(std::string plotPath, Miner& miner, plotFilePath.setFileName(account + "_" + sNonce + "_" + nNonces + "_" + nNonces); log_success(MinerLogger::general, "Full plot path: %s", plotFilePath.toString()); Poco::File plotFile(plotFilePath); - plotFile.createFile(); - plotFile.setSize(nonceCount * Settings::PlotSize); - log_success(MinerLogger::general, "Free Space on this device: %s", std::to_string(plotFile.freeSpace())+" GB"); + if (!plotFile.exists()) + { + plotFile.createFile(); + plotFile.setSize(nonceCount * Settings::PlotSize); + } + else + log_system(MinerLogger::general, "File already exists."); + + + //log_success(MinerLogger::general, "Free Space on this device: %s", std::to_string(plotFile.freeSpace())+" GB"); } std::array, Burst::Shabal256_SSE2::HashSize> Burst::PlotGenerator::generateSse2(const Poco::UInt64 account, const Poco::UInt64 startNonce)