aboutsummaryrefslogtreecommitdiff
path: root/src/protocol.h
diff options
context:
space:
mode:
authorVasil Dimov <vd@FreeBSD.org>2020-05-19 17:39:05 +0200
committerVasil Dimov <vd@FreeBSD.org>2020-10-09 16:42:49 +0200
commit201a4596d92d640d5eb7e76cc8d959228fa09dbb (patch)
tree1f0641dfee1f4d475336a32f3fea930eded9d629 /src/protocol.h
parent1d3ec2a1fda7446323786a52da1fd109c01aa6fb (diff)
net: CAddress & CAddrMan: (un)serialize as ADDRv2
Change the serialization of `CAddrMan` to serialize its addresses in ADDRv2/BIP155 format by default. Introduce a new `CAddrMan` format version (3). Add support for ADDRv2 format in `CAddress` (un)serialization. Co-authored-by: Carl Dong <contact@carldong.me>
Diffstat (limited to 'src/protocol.h')
-rw-r--r--src/protocol.h12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/protocol.h b/src/protocol.h
index 9a44a1626c..e2d3602792 100644
--- a/src/protocol.h
+++ b/src/protocol.h
@@ -351,7 +351,8 @@ class CAddress : public CService
public:
CAddress() : CService{} {};
- explicit CAddress(CService ipIn, ServiceFlags nServicesIn) : CService{ipIn}, nServices{nServicesIn} {};
+ CAddress(CService ipIn, ServiceFlags nServicesIn) : CService{ipIn}, nServices{nServicesIn} {};
+ CAddress(CService ipIn, ServiceFlags nServicesIn, uint32_t nTimeIn) : CService{ipIn}, nTime{nTimeIn}, nServices{nServicesIn} {};
SERIALIZE_METHODS(CAddress, obj)
{
@@ -370,7 +371,14 @@ public:
// nTime.
READWRITE(obj.nTime);
}
- READWRITE(Using<CustomUintFormatter<8>>(obj.nServices));
+ if (nVersion & ADDRV2_FORMAT) {
+ uint64_t services_tmp;
+ SER_WRITE(obj, services_tmp = obj.nServices);
+ READWRITE(Using<CompactSizeFormatter<false>>(services_tmp));
+ SER_READ(obj, obj.nServices = static_cast<ServiceFlags>(services_tmp));
+ } else {
+ READWRITE(Using<CustomUintFormatter<8>>(obj.nServices));
+ }
READWRITEAS(CService, obj);
}