mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 15:09:59 +01:00
Merge #19628: net: change CNetAddr::ip to have flexible size
102867c587net: change CNetAddr::ip to have flexible size (Vasil Dimov)1ea57ad674net: don't accept non-left-contiguous netmasks (Vasil Dimov) Pull request description: (chopped off from #19031 to ease review) Before this change `CNetAddr::ip` was a fixed-size array of 16 bytes, not being able to store larger addresses (e.g. TORv3) and encoded smaller ones as 16-byte IPv6 addresses. Change its type to `prevector`, so that it can hold larger addresses and do not disguise non-IPv6 addresses as IPv6. So the IPv4 address `1.2.3.4` is now encoded as `01020304` instead of `00000000000000000000FFFF01020304`. Rename `CNetAddr::ip` to `CNetAddr::m_addr` because it is not an "IP" or "IP address" (TOR addresses are not IP addresses). In order to preserve backward compatibility with serialization (where e.g. `1.2.3.4` is serialized as `00000000000000000000FFFF01020304`) introduce `CNetAddr` dedicated legacy serialize/unserialize methods. Adjust `CSubNet` accordingly. Still use `CSubNet::netmask[]` of fixed 16 bytes, but use the first 4 for IPv4 (not the last 4). Do not accept invalid netmasks that have 0-bits followed by 1-bits and only allow subnetting for IPv4 and IPv6. Co-authored-by: Carl Dong <contact@carldong.me> ACKs for top commit: sipa: utACK102867c587MarcoFalke: Concept ACK102867c587ryanofsky: Code review ACK102867c587. Just many suggested updates since last review. Thanks for following up on everything! jonatack: re-ACK102867c587diff review, code review, build/tests/running bitcoind with ipv4/ipv6/onion peers kallewoof: ACK102867c587Tree-SHA512: d60bf716cecf8d3e8146d2f90f897ebe956befb16f711a24cfe680024c5afc758fb9e4a0a22066b42f7630d52cf916318bedbcbc069ae07092d5250a11e8f762
This commit is contained in:
@@ -98,6 +98,13 @@ NODISCARD bool ParseInt32(const std::string& str, int32_t *out);
|
||||
*/
|
||||
NODISCARD bool ParseInt64(const std::string& str, int64_t *out);
|
||||
|
||||
/**
|
||||
* Convert decimal string to unsigned 8-bit integer with strict parse error feedback.
|
||||
* @returns true if the entire string could be parsed as valid integer,
|
||||
* false if not the entire string could be parsed or when overflow or underflow occurred.
|
||||
*/
|
||||
NODISCARD bool ParseUInt8(const std::string& str, uint8_t *out);
|
||||
|
||||
/**
|
||||
* Convert decimal string to unsigned 32-bit integer with strict parse error feedback.
|
||||
* @returns true if the entire string could be parsed as valid integer,
|
||||
|
||||
Reference in New Issue
Block a user