mirror of
https://github.com/SChernykh/p2pool.git
synced 2024-11-16 15:57:39 +00:00
Stratum: fixed response to HTTP GET/HEAD requests
Some checks failed
Sync test (old) / sync-test-windows-debug-asan (push) Has been cancelled
C/C++ CI / build-ubuntu (map[c:gcc-11 cpp:g++-11 flags: os:ubuntu-20.04]) (push) Has been cancelled
C/C++ CI / build-ubuntu (map[c:gcc-12 cpp:g++-12 flags: os:ubuntu-22.04]) (push) Has been cancelled
C/C++ CI / build-ubuntu (map[c:gcc-8 cpp:g++-8 flags: os:ubuntu-20.04]) (push) Has been cancelled
clang-tidy / clang-tidy (push) Has been cancelled
CodeQL / Analyze (cpp) (push) Has been cancelled
C/C++ CI / build-alpine-static (map[arch:aarch64 branch:latest-stable flags:-ffunction-sections -Wno-error=inline -mfix-cortex-a53-835769 -mfix-cortex-a53-843419]) (push) Has been cancelled
C/C++ CI / build-alpine-static (map[arch:riscv64 branch:edge flags:-ffunction-sections -Wno-error=inline]) (push) Has been cancelled
C/C++ CI / build-alpine-static (map[arch:x86_64 branch:latest-stable flags:-ffunction-sections -Wno-error=inline]) (push) Has been cancelled
C/C++ CI / build-ubuntu-static-libs (map[flags:-fuse-linker-plugin -ffunction-sections -Wno-error=inline]) (push) Has been cancelled
C/C++ CI / build-ubuntu-aarch64 (map[flags:-fuse-linker-plugin -ffunction-sections -mfix-cortex-a53-835769 -mfix-cortex-a53-843419 os:ubuntu-20.04]) (push) Has been cancelled
C/C++ CI / build-ubuntu-aarch64 (map[flags:-fuse-linker-plugin -ffunction-sections -mfix-cortex-a53-835769 -mfix-cortex-a53-843419 os:ubuntu-22.04]) (push) Has been cancelled
C/C++ CI / build-windows-msys2 (map[c:clang cxx:clang++ flags:-fuse-ld=lld -Wno-unused-command-line-argument -Wno-nan-infinity-disabled]) (push) Has been cancelled
C/C++ CI / build-windows-msys2 (map[c:gcc cxx:g++ flags:-ffunction-sections -Wno-error=maybe-uninitialized -Wno-error=attributes]) (push) Has been cancelled
C/C++ CI / build-windows-msbuild (map[grpc:OFF os:2019 rx:OFF tls:OFF upnp:OFF vs:Visual Studio 16 2019 vspath:C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise]) (push) Has been cancelled
C/C++ CI / build-windows-msbuild (map[grpc:OFF os:2019 rx:OFF tls:ON upnp:OFF vs:Visual Studio 16 2019 vspath:C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise]) (push) Has been cancelled
C/C++ CI / build-windows-msbuild (map[grpc:OFF os:2019 rx:OFF tls:ON upnp:ON vs:Visual Studio 16 2019 vspath:C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise]) (push) Has been cancelled
C/C++ CI / build-windows-msbuild (map[grpc:OFF os:2019 rx:ON tls:ON upnp:ON vs:Visual Studio 16 2019 vspath:C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise]) (push) Has been cancelled
C/C++ CI / build-windows-msbuild (map[grpc:ON os:2019 rx:ON tls:ON upnp:ON vs:Visual Studio 16 2019 vspath:C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise]) (push) Has been cancelled
C/C++ CI / build-macos (push) Has been cancelled
C/C++ CI / build-windows-msbuild (map[grpc:ON os:2022 rx:ON tls:ON upnp:ON vs:Visual Studio 17 2022 vspath:C:\Program Files\Microsoft Visual Studio\2022\Enterprise]) (push) Has been cancelled
C/C++ CI / build-macos-aarch64 (push) Has been cancelled
Microsoft C++ Code Analysis / Analyze (push) Has been cancelled
source-snapshot / source-snapshot (push) Has been cancelled
Sync test (old) / sync-test-windows-leaks (push) Has been cancelled
Sync test (old) / sync-test-ubuntu-tsan (push) Has been cancelled
Sync test (old) / sync-test-ubuntu-msan (push) Has been cancelled
Sync test (old) / sync-test-ubuntu-ubsan (push) Has been cancelled
Sync test (old) / sync-test-ubuntu-asan (push) Has been cancelled
Sync test (old) / sync-test-macos (map[flags:-Og -ftrapv -target arm64-apple-macos-11 os:macos-14]) (push) Has been cancelled
Sync test (old) / sync-test-macos (map[flags:-Og -ftrapv os:macos-13]) (push) Has been cancelled
Sync test / sync-test-ubuntu-tsan (push) Has been cancelled
Sync test / sync-test-ubuntu-msan (push) Has been cancelled
Sync test / sync-test-ubuntu-ubsan (push) Has been cancelled
Sync test / sync-test-ubuntu-asan (push) Has been cancelled
Sync test / sync-test-macos (map[flags:-Og -ftrapv -target arm64-apple-macos-11 os:macos-14]) (push) Has been cancelled
Sync test / sync-test-macos (map[flags:-Og -ftrapv os:macos-13]) (push) Has been cancelled
Sync test / sync-test-windows-debug-asan (push) Has been cancelled
Sync test / sync-test-windows-leaks (push) Has been cancelled
C/C++ CI / build-freebsd (map[architecture:x86-64 host:ubuntu-latest name:freebsd version:13.3]) (push) Has been cancelled
C/C++ CI / build-openbsd (map[architecture:x86-64 host:ubuntu-latest name:openbsd version:7.4]) (push) Has been cancelled
cppcheck / cppcheck-ubuntu (push) Has been cancelled
cppcheck / cppcheck-windows (push) Has been cancelled
Some checks failed
Sync test (old) / sync-test-windows-debug-asan (push) Has been cancelled
C/C++ CI / build-ubuntu (map[c:gcc-11 cpp:g++-11 flags: os:ubuntu-20.04]) (push) Has been cancelled
C/C++ CI / build-ubuntu (map[c:gcc-12 cpp:g++-12 flags: os:ubuntu-22.04]) (push) Has been cancelled
C/C++ CI / build-ubuntu (map[c:gcc-8 cpp:g++-8 flags: os:ubuntu-20.04]) (push) Has been cancelled
clang-tidy / clang-tidy (push) Has been cancelled
CodeQL / Analyze (cpp) (push) Has been cancelled
C/C++ CI / build-alpine-static (map[arch:aarch64 branch:latest-stable flags:-ffunction-sections -Wno-error=inline -mfix-cortex-a53-835769 -mfix-cortex-a53-843419]) (push) Has been cancelled
C/C++ CI / build-alpine-static (map[arch:riscv64 branch:edge flags:-ffunction-sections -Wno-error=inline]) (push) Has been cancelled
C/C++ CI / build-alpine-static (map[arch:x86_64 branch:latest-stable flags:-ffunction-sections -Wno-error=inline]) (push) Has been cancelled
C/C++ CI / build-ubuntu-static-libs (map[flags:-fuse-linker-plugin -ffunction-sections -Wno-error=inline]) (push) Has been cancelled
C/C++ CI / build-ubuntu-aarch64 (map[flags:-fuse-linker-plugin -ffunction-sections -mfix-cortex-a53-835769 -mfix-cortex-a53-843419 os:ubuntu-20.04]) (push) Has been cancelled
C/C++ CI / build-ubuntu-aarch64 (map[flags:-fuse-linker-plugin -ffunction-sections -mfix-cortex-a53-835769 -mfix-cortex-a53-843419 os:ubuntu-22.04]) (push) Has been cancelled
C/C++ CI / build-windows-msys2 (map[c:clang cxx:clang++ flags:-fuse-ld=lld -Wno-unused-command-line-argument -Wno-nan-infinity-disabled]) (push) Has been cancelled
C/C++ CI / build-windows-msys2 (map[c:gcc cxx:g++ flags:-ffunction-sections -Wno-error=maybe-uninitialized -Wno-error=attributes]) (push) Has been cancelled
C/C++ CI / build-windows-msbuild (map[grpc:OFF os:2019 rx:OFF tls:OFF upnp:OFF vs:Visual Studio 16 2019 vspath:C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise]) (push) Has been cancelled
C/C++ CI / build-windows-msbuild (map[grpc:OFF os:2019 rx:OFF tls:ON upnp:OFF vs:Visual Studio 16 2019 vspath:C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise]) (push) Has been cancelled
C/C++ CI / build-windows-msbuild (map[grpc:OFF os:2019 rx:OFF tls:ON upnp:ON vs:Visual Studio 16 2019 vspath:C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise]) (push) Has been cancelled
C/C++ CI / build-windows-msbuild (map[grpc:OFF os:2019 rx:ON tls:ON upnp:ON vs:Visual Studio 16 2019 vspath:C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise]) (push) Has been cancelled
C/C++ CI / build-windows-msbuild (map[grpc:ON os:2019 rx:ON tls:ON upnp:ON vs:Visual Studio 16 2019 vspath:C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise]) (push) Has been cancelled
C/C++ CI / build-macos (push) Has been cancelled
C/C++ CI / build-windows-msbuild (map[grpc:ON os:2022 rx:ON tls:ON upnp:ON vs:Visual Studio 17 2022 vspath:C:\Program Files\Microsoft Visual Studio\2022\Enterprise]) (push) Has been cancelled
C/C++ CI / build-macos-aarch64 (push) Has been cancelled
Microsoft C++ Code Analysis / Analyze (push) Has been cancelled
source-snapshot / source-snapshot (push) Has been cancelled
Sync test (old) / sync-test-windows-leaks (push) Has been cancelled
Sync test (old) / sync-test-ubuntu-tsan (push) Has been cancelled
Sync test (old) / sync-test-ubuntu-msan (push) Has been cancelled
Sync test (old) / sync-test-ubuntu-ubsan (push) Has been cancelled
Sync test (old) / sync-test-ubuntu-asan (push) Has been cancelled
Sync test (old) / sync-test-macos (map[flags:-Og -ftrapv -target arm64-apple-macos-11 os:macos-14]) (push) Has been cancelled
Sync test (old) / sync-test-macos (map[flags:-Og -ftrapv os:macos-13]) (push) Has been cancelled
Sync test / sync-test-ubuntu-tsan (push) Has been cancelled
Sync test / sync-test-ubuntu-msan (push) Has been cancelled
Sync test / sync-test-ubuntu-ubsan (push) Has been cancelled
Sync test / sync-test-ubuntu-asan (push) Has been cancelled
Sync test / sync-test-macos (map[flags:-Og -ftrapv -target arm64-apple-macos-11 os:macos-14]) (push) Has been cancelled
Sync test / sync-test-macos (map[flags:-Og -ftrapv os:macos-13]) (push) Has been cancelled
Sync test / sync-test-windows-debug-asan (push) Has been cancelled
Sync test / sync-test-windows-leaks (push) Has been cancelled
C/C++ CI / build-freebsd (map[architecture:x86-64 host:ubuntu-latest name:freebsd version:13.3]) (push) Has been cancelled
C/C++ CI / build-openbsd (map[architecture:x86-64 host:ubuntu-latest name:openbsd version:7.4]) (push) Has been cancelled
cppcheck / cppcheck-ubuntu (push) Has been cancelled
cppcheck / cppcheck-windows (push) Has been cancelled
This commit is contained in:
parent
314d306145
commit
93062e4341
2 changed files with 22 additions and 13 deletions
|
@ -1167,13 +1167,20 @@ bool StratumServer::StratumClient::on_read(char* data, uint32_t size)
|
|||
char* line_start = m_stratumReadBuf;
|
||||
for (char *e = line_start + m_stratumReadBufBytes, *c = e - size; c < e; ++c) {
|
||||
if (*c == '\n') {
|
||||
// Check if the line starts with "GET " (an HTTP request)
|
||||
if ((c - line_start >= 4) && (read_unaligned(reinterpret_cast<uint32_t*>(line_start)) == 0x20544547U)) {
|
||||
LOGINFO(5, "client " << log::Gray() << static_cast<const char*>(m_addrString) << log::NoColor() << " sent an HTTP request");
|
||||
send_http_response();
|
||||
// Check if the line starts with "GET " or "HEAD" (an HTTP request)
|
||||
if (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);
|
||||
const bool is_http_head = (line_start_data == 0x44414548U);
|
||||
|
||||
if (is_http_get || is_http_head) {
|
||||
LOGINFO(5, "client " << log::Gray() << static_cast<const char*>(m_addrString) << log::NoColor() << " sent an HTTP " << (is_http_get ? "GET" : "HEAD") << " request");
|
||||
send_http_response(is_http_get);
|
||||
close();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
*c = '\0';
|
||||
if (!process_request(line_start, static_cast<uint32_t>(c - line_start))) {
|
||||
|
@ -1374,22 +1381,24 @@ bool StratumServer::StratumClient::process_submit(rapidjson::Document& doc, uint
|
|||
return static_cast<StratumServer*>(m_owner)->on_submit(this, id, job_id.GetString(), nonce.GetString(), result.GetString());
|
||||
}
|
||||
|
||||
bool StratumServer::StratumClient::send_http_response()
|
||||
bool StratumServer::StratumClient::send_http_response(bool send_content)
|
||||
{
|
||||
return m_owner->send(this, [](uint8_t *buf, size_t buf_size) -> size_t {
|
||||
return m_owner->send(this, [send_content](uint8_t *buf, size_t buf_size) -> size_t {
|
||||
static constexpr uint8_t data[] =
|
||||
"HTTP/1.1 200 OK\r\n"
|
||||
"Content-Length: 21\r\n"
|
||||
"Content-Type: text/html\r\n"
|
||||
"Content-Type: text/plain\r\n"
|
||||
"Connection: Closed\r\n\r\n"
|
||||
"P2Pool Stratum online";
|
||||
|
||||
if (buf_size < sizeof(data)) {
|
||||
const size_t data_size = send_content ? (sizeof(data) - 1) : (sizeof(data) - 1 - 21);
|
||||
|
||||
if (buf_size < data_size) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
memcpy(buf, data, sizeof(data));
|
||||
return sizeof(data);
|
||||
memcpy(buf, data, data_size);
|
||||
return data_size;
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ public:
|
|||
[[nodiscard]] bool process_login(rapidjson::Document& doc, uint32_t id);
|
||||
[[nodiscard]] bool process_submit(rapidjson::Document& doc, uint32_t id);
|
||||
|
||||
bool send_http_response();
|
||||
bool send_http_response(bool send_content);
|
||||
|
||||
alignas(8) char m_rawReadBuf[STRATUM_BUF_SIZE];
|
||||
|
||||
|
|
Loading…
Reference in a new issue