Skip to content

Commit

Permalink
Added a command line parameter to disable Stratum HTTP
Browse files Browse the repository at this point in the history
  • Loading branch information
SChernykh committed Dec 17, 2024
1 parent 2581b4c commit a4459d6
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/COMMAND_LINE.MD
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
5 changes: 5 additions & 0 deletions src/params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/params.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ struct Params
std::string m_tlsCert;
std::string m_tlsCertKey;
#endif
bool m_enableStratumHTTP = true;
};

} // namespace p2pool
7 changes: 6 additions & 1 deletion src/stratum_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<StratumServer*>(m_owner)->http_enabled() && (c - line_start >= 4)) {
const uint32_t line_start_data = read_unaligned(reinterpret_cast<uint32_t*>(line_start));

const bool is_http_get = (line_start_data == 0x20544547U);
Expand Down
2 changes: 2 additions & 0 deletions src/stratum_server.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ class StratumServer : public TCPServer

void reset_share_counters();

bool http_enabled() const;

private:
[[nodiscard]] const char* get_log_category() const override;

Expand Down

0 comments on commit a4459d6

Please sign in to comment.