From e0a3add5f2493bb4cf71ac80797462b6a85a56d5 Mon Sep 17 00:00:00 2001 From: SChernykh Date: Fri, 26 May 2023 00:02:15 +0200 Subject: [PATCH] Refactored is_localhost() --- src/common.h | 16 +++++----------- src/util.cpp | 5 +++++ 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/common.h b/src/common.h index c9431d7..c618bf5 100644 --- a/src/common.h +++ b/src/common.h @@ -436,19 +436,13 @@ struct raw_ip FORCEINLINE bool operator!=(const raw_ip& other) const { return !operator==(other); } - FORCEINLINE bool is_localhost() const - { - static constexpr raw_ip localhost_ipv4 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x01 }; - static constexpr raw_ip localhost_ipv6 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }; + FORCEINLINE bool is_localhost() const { return (*this == localhost_ipv4) || (*this == localhost_ipv6); } + FORCEINLINE bool is_ipv4_prefix() const { return memcmp(data, ipv4_prefix, sizeof(ipv4_prefix)) == 0; } - return (*this == localhost_ipv4) || (*this == localhost_ipv6); - } + static const raw_ip localhost_ipv4; + static const raw_ip localhost_ipv6; - FORCEINLINE bool is_ipv4_prefix() const - { - alignas(8) static constexpr uint8_t ipv4_prefix[12] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff }; - return memcmp(data, ipv4_prefix, sizeof(ipv4_prefix)) == 0; - } + alignas(8) static const uint8_t ipv4_prefix[12]; }; static_assert(sizeof(raw_ip) == 16, "struct raw_ip has invalid size"); diff --git a/src/util.cpp b/src/util.cpp index 71e7d81..821a759 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -54,6 +54,11 @@ const char* VERSION = "v" STR2(P2POOL_VERSION_MAJOR) "." STR2(P2POOL_VERSION_MIN #endif " on " __DATE__ ")"; +const raw_ip raw_ip::localhost_ipv4 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x01 }; +const raw_ip raw_ip::localhost_ipv6 = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 }; + +alignas(8) const uint8_t raw_ip::ipv4_prefix[12] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff }; + MinerCallbackHandler::~MinerCallbackHandler() {} void panic_stop(const char* message)