From a4459d6207759fb2b541f4cae09cfe7d4fd510dd Mon Sep 17 00:00:00 2001 From: SChernykh <15806605+SChernykh@users.noreply.github.com> Date: Tue, 17 Dec 2024 11:39:49 +0100 Subject: [PATCH] Added a command line parameter to disable Stratum HTTP --- docs/COMMAND_LINE.MD | 1 + src/main.cpp | 1 + src/params.cpp | 5 +++++ src/params.h | 1 + src/stratum_server.cpp | 7 ++++++- src/stratum_server.h | 2 ++ 6 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/COMMAND_LINE.MD b/docs/COMMAND_LINE.MD index 4e35c7b..f8ea921 100644 --- a/docs/COMMAND_LINE.MD +++ b/docs/COMMAND_LINE.MD @@ -34,6 +34,7 @@ --version Print p2pool's version and build details --tls-cert file Load TLS certificate chain from "file" in the PEM format --tls-cert-key file Load TLS certificate private key from "file" in the PEM format +--no-stratum-http Disable HTTP on Stratum ports ``` ### Example command line diff --git a/src/main.cpp b/src/main.cpp index a04941c..0953fb5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -78,6 +78,7 @@ void p2pool_usage() "--tls-cert file Load TLS certificate chain from \"file\" in the PEM format\n" "--tls-cert-key file Load TLS certificate private key from \"file\" in the PEM format\n" #endif + "--no-stratum-http Disable HTTP on Stratum ports\n" "--help Show this help message\n\n" "Example command line:\n\n" "%s --host 127.0.0.1 --rpc-port 18081 --zmq-port 18083 --wallet YOUR_WALLET_ADDRESS --stratum 0.0.0.0:%d --p2p 0.0.0.0:%d\n\n", diff --git a/src/params.cpp b/src/params.cpp index 6250986..12e2746 100644 --- a/src/params.cpp +++ b/src/params.cpp @@ -213,6 +213,11 @@ Params::Params(int argc, char* const argv[]) } #endif + if (strcmp(argv[i], "--no-stratum-http") == 0) { + m_enableStratumHTTP = false; + ok = true; + } + if (!ok) { fprintf(stderr, "Unknown command line parameter %s\n\n", argv[i]); p2pool_usage(); diff --git a/src/params.h b/src/params.h index 95f7c16..93bc851 100644 --- a/src/params.h +++ b/src/params.h @@ -96,6 +96,7 @@ struct Params std::string m_tlsCert; std::string m_tlsCertKey; #endif + bool m_enableStratumHTTP = true; }; } // namespace p2pool diff --git a/src/stratum_server.cpp b/src/stratum_server.cpp index de7909e..3176a82 100644 --- a/src/stratum_server.cpp +++ b/src/stratum_server.cpp @@ -602,6 +602,11 @@ void StratumServer::reset_share_counters() m_totalFailedShares = 0; } +bool StratumServer::http_enabled() const +{ + return m_pool->params().m_enableStratumHTTP; +} + const char* StratumServer::get_log_category() const { return log_category_prefix; @@ -1204,7 +1209,7 @@ bool StratumServer::StratumClient::on_read(const char* data, uint32_t size) for (char *c = line_start + m_stratumReadBufBytes - size; c < e; ++c) { if (*c == '\n') { // Check if the line starts with "GET " or "HEAD" (an HTTP request) - if (c - line_start >= 4) { + if (static_cast(m_owner)->http_enabled() && (c - line_start >= 4)) { const uint32_t line_start_data = read_unaligned(reinterpret_cast(line_start)); const bool is_http_get = (line_start_data == 0x20544547U); diff --git a/src/stratum_server.h b/src/stratum_server.h index 772fb65..708b782 100644 --- a/src/stratum_server.h +++ b/src/stratum_server.h @@ -102,6 +102,8 @@ public: void reset_share_counters(); + bool http_enabled() const; + private: [[nodiscard]] const char* get_log_category() const override;