diff --git a/TODO.txt b/TODO.txt index 40b8423..95c8607 100644 --- a/TODO.txt +++ b/TODO.txt @@ -14,9 +14,6 @@ Check if Block FullVerify is actually verifying fully (not missing any condition A loophole in the reorg penalty system could potentially exist where someone broadcasts blocks one-at-a-time. Determine a solution to this. -IPv6 support for the P2P node. Come on guys, it's 2026. RFC 2460 was in 1998. It's about time. - Like if someone is behind NAT, fine, workable. CGNAT? Lmao good luck. - TO TEST: Implement Horizen's "Reorg Penalty" system to make it harder for the young chain to be attacked by a powerful miner. @@ -30,4 +27,7 @@ I want to move away from the Monero emission. I want to do something a bit radic a constant inflation rate of 1.5% per year. It's lower than fiat (USD is ~2.8% per year), and it additionally doesn't fluctuate during crisis. It's constant. Move to a GPU algo. RandomX is a good candidate, but CPU mining is not that attractive to anyone but people who actually want to support the project. -Sadly, CPUs won't incentivize people who want to profit, which let's be fair, is the majority of miners. \ No newline at end of file +Sadly, CPUs won't incentivize people who want to profit, which let's be fair, is the majority of miners. + +IPv6 support for the P2P node. Come on guys, it's 2026. RFC 2460 was in 1998. It's about time. + Like if someone is behind NAT, fine, workable. CGNAT? Lmao good luck. diff --git a/include/utils.h b/include/utils.h index efd5498..8c60a7a 100644 --- a/include/utils.h +++ b/include/utils.h @@ -9,6 +9,9 @@ #include #include #include +#include +#include +#include typedef struct { uint8_t bytes[32]; @@ -252,96 +255,35 @@ static inline bool ParseHexAddress32(const char* in, uint8_t outAddress[32]) { } static inline bool IsValidIPv4(const char* ip) { - if (!ip || *ip == '\0') { - return false; + struct addrinfo hints, *res; + int status; + + memset(&hints, 0, sizeof hints); + hints.ai_family = AF_INET; // Only IPv4 + hints.ai_socktype = AI_NUMERICHOST; // Only numeric addresses + + status = getaddrinfo(ip, NULL, &hints, &res); + if (status == 0) { + freeaddrinfo(res); + return true; } - - int octetCount = 0; - const char* p = ip; - - while (*p != '\0') { - if (octetCount >= 4) { - return false; - } - - if (*p < '0' || *p > '9') { - return false; - } - - unsigned int value = 0; - int digits = 0; - while (*p >= '0' && *p <= '9') { - value = (value * 10u) + (unsigned int)(*p - '0'); - if (value > 255u) { - return false; - } - ++digits; - if (digits > 3) { - return false; - } - ++p; - } - - if (digits == 0) { - return false; - } - - ++octetCount; - if (octetCount < 4) { - if (*p != '.') { - return false; - } - ++p; - if (*p == '\0') { - return false; - } - } - } - - return octetCount == 4; + return false; } static inline bool IsValidIPv6(const char* ip) { - if (!ip || *ip == '\0') { - return false; + struct addrinfo hints, *res; + int status; + + memset(&hints, 0, sizeof hints); + hints.ai_family = AF_INET6; // Only IPv6 + hints.ai_socktype = AI_NUMERICHOST; // Only numeric addresses + + status = getaddrinfo(ip, NULL, &hints, &res); + if (status == 0) { + freeaddrinfo(res); + return true; } - - int colonCount = 0; - const char* p = ip; - - while (*p != '\0') { - if (colonCount > 7) { - return false; - } - - int hexDigits = 0; - while ((*p >= '0' && *p <= '9') || - (*p >= 'a' && *p <= 'f') || - (*p >= 'A' && *p <= 'F')) { - ++hexDigits; - if (hexDigits > 4) { - return false; - } - ++p; - } - - if (hexDigits == 0) { - return false; - } - - ++colonCount; - if (colonCount < 8) { - if (*p != ':') { - return false; - } - ++p; - if (*p == '\0') { - return false; - } - } - } - - return colonCount == 8; + return false; } static inline void Uint256ToDecimal(const uint256_t* value, char* out, size_t outSize) {