diff options
author | MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> | 2023-01-31 18:04:44 +0100 |
---|---|---|
committer | MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> | 2023-09-05 10:13:25 +0200 |
commit | fac81affb527132945773a5315bd27fec61ec52f (patch) | |
tree | 90aa401bd50bf12519a45737f335856256ff614e /src/netaddress.h | |
parent | faec591d64e40ba7ec7656cbfdda1a05953bde13 (diff) |
Use serialization parameters for CAddress serialization
This also cleans up the addrman (de)serialization code paths to only
allow `Disk` serialization. Some unit tests previously forced a
`Network` serialization, which does not make sense, because Bitcoin Core
in production will always `Disk` serialize.
This cleanup idea was suggested by Pieter Wuille and implemented by Anthony
Towns.
Co-authored-by: Pieter Wuille <pieter@wuille.net>
Co-authored-by: Anthony Towns <aj@erisian.com.au>
Diffstat (limited to 'src/netaddress.h')
-rw-r--r-- | src/netaddress.h | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/netaddress.h b/src/netaddress.h index 143cdd4fa3..a0944c886f 100644 --- a/src/netaddress.h +++ b/src/netaddress.h @@ -25,14 +25,6 @@ #include <vector> /** - * A flag that is ORed into the protocol version to designate that addresses - * should be serialized in (unserialized from) v2 format (BIP155). - * Make sure that this does not collide with any of the values in `version.h` - * or with `SERIALIZE_TRANSACTION_NO_WITNESS`. - */ -static constexpr int ADDRV2_FORMAT = 0x20000000; - -/** * A network type. * @note An address may belong to more than one network, for example `10.0.0.1` * belongs to both `NET_UNROUTABLE` and `NET_IPV4`. @@ -220,13 +212,23 @@ public: return IsIPv4() || IsIPv6() || IsTor() || IsI2P() || IsCJDNS(); } + enum class Encoding { + V1, + V2, //!< BIP155 encoding + }; + struct SerParams { + const Encoding enc; + }; + static constexpr SerParams V1{Encoding::V1}; + static constexpr SerParams V2{Encoding::V2}; + /** * Serialize to a stream. */ template <typename Stream> void Serialize(Stream& s) const { - if (s.GetVersion() & ADDRV2_FORMAT) { + if (s.GetParams().enc == Encoding::V2) { SerializeV2Stream(s); } else { SerializeV1Stream(s); @@ -239,7 +241,7 @@ public: template <typename Stream> void Unserialize(Stream& s) { - if (s.GetVersion() & ADDRV2_FORMAT) { + if (s.GetParams().enc == Encoding::V2) { UnserializeV2Stream(s); } else { UnserializeV1Stream(s); |