Change functions IsValidIPv4/v6 to use addrinfo instead of custom logic
This commit is contained in:
@@ -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.
|
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:
|
TO TEST:
|
||||||
Implement Horizen's "Reorg Penalty" system to make it harder for the young chain to be attacked by a powerful miner.
|
Implement Horizen's "Reorg Penalty" system to make it harder for the young chain to be attacked by a powerful miner.
|
||||||
|
|
||||||
@@ -31,3 +28,6 @@ a constant inflation rate of 1.5% per year. It's lower than fiat (USD is ~2.8% p
|
|||||||
|
|
||||||
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.
|
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.
|
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.
|
||||||
|
|||||||
+23
-81
@@ -9,6 +9,9 @@
|
|||||||
#include <crypto/crypto.h>
|
#include <crypto/crypto.h>
|
||||||
#include <uint256.h>
|
#include <uint256.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/socket.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint8_t bytes[32];
|
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) {
|
static inline bool IsValidIPv4(const char* ip) {
|
||||||
if (!ip || *ip == '\0') {
|
struct addrinfo hints, *res;
|
||||||
return false;
|
int status;
|
||||||
}
|
|
||||||
|
|
||||||
int octetCount = 0;
|
memset(&hints, 0, sizeof hints);
|
||||||
const char* p = ip;
|
hints.ai_family = AF_INET; // Only IPv4
|
||||||
|
hints.ai_socktype = AI_NUMERICHOST; // Only numeric addresses
|
||||||
|
|
||||||
while (*p != '\0') {
|
status = getaddrinfo(ip, NULL, &hints, &res);
|
||||||
if (octetCount >= 4) {
|
if (status == 0) {
|
||||||
|
freeaddrinfo(res);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline bool IsValidIPv6(const char* ip) {
|
static inline bool IsValidIPv6(const char* ip) {
|
||||||
if (!ip || *ip == '\0') {
|
struct addrinfo hints, *res;
|
||||||
return false;
|
int status;
|
||||||
}
|
|
||||||
|
|
||||||
int colonCount = 0;
|
memset(&hints, 0, sizeof hints);
|
||||||
const char* p = ip;
|
hints.ai_family = AF_INET6; // Only IPv6
|
||||||
|
hints.ai_socktype = AI_NUMERICHOST; // Only numeric addresses
|
||||||
|
|
||||||
while (*p != '\0') {
|
status = getaddrinfo(ip, NULL, &hints, &res);
|
||||||
if (colonCount > 7) {
|
if (status == 0) {
|
||||||
|
freeaddrinfo(res);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
return false;
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void Uint256ToDecimal(const uint256_t* value, char* out, size_t outSize) {
|
static inline void Uint256ToDecimal(const uint256_t* value, char* out, size_t outSize) {
|
||||||
|
|||||||
Reference in New Issue
Block a user