mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-02-27 01:31:08 +01:00
refactor: Use type-safe std::chrono for addrman time
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include <serialize.h>
|
||||
#include <streams.h>
|
||||
#include <uint256.h>
|
||||
#include <util/time.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <limits>
|
||||
@@ -352,7 +353,7 @@ static inline bool MayHaveUsefulAddressDB(ServiceFlags services)
|
||||
/** A CService with information about it as peer */
|
||||
class CAddress : public CService
|
||||
{
|
||||
static constexpr uint32_t TIME_INIT{100000000};
|
||||
static constexpr std::chrono::seconds TIME_INIT{100000000};
|
||||
|
||||
/** Historically, CAddress disk serialization stored the CLIENT_VERSION, optionally OR'ed with
|
||||
* the ADDRV2_FORMAT flag to indicate V2 serialization. The first field has since been
|
||||
@@ -382,7 +383,7 @@ class CAddress : public CService
|
||||
public:
|
||||
CAddress() : CService{} {};
|
||||
CAddress(CService ipIn, ServiceFlags nServicesIn) : CService{ipIn}, nServices{nServicesIn} {};
|
||||
CAddress(CService ipIn, ServiceFlags nServicesIn, uint32_t nTimeIn) : CService{ipIn}, nTime{nTimeIn}, nServices{nServicesIn} {};
|
||||
CAddress(CService ipIn, ServiceFlags nServicesIn, NodeSeconds time) : CService{ipIn}, nTime{time}, nServices{nServicesIn} {};
|
||||
|
||||
SERIALIZE_METHODS(CAddress, obj)
|
||||
{
|
||||
@@ -415,7 +416,7 @@ public:
|
||||
use_v2 = s.GetVersion() & ADDRV2_FORMAT;
|
||||
}
|
||||
|
||||
READWRITE(obj.nTime);
|
||||
READWRITE(Using<LossyChronoFormatter<uint32_t>>(obj.nTime));
|
||||
// nServices is serialized as CompactSize in V2; as uint64_t in V1.
|
||||
if (use_v2) {
|
||||
uint64_t services_tmp;
|
||||
@@ -430,8 +431,8 @@ public:
|
||||
SerReadWriteMany(os, ser_action, ReadWriteAsHelper<CService>(obj));
|
||||
}
|
||||
|
||||
//! Always included in serialization.
|
||||
uint32_t nTime{TIME_INIT};
|
||||
//! Always included in serialization. The behavior is unspecified if the value is not representable as uint32_t.
|
||||
NodeSeconds nTime{TIME_INIT};
|
||||
//! Serialized as uint64_t in V1, and as CompactSize in V2.
|
||||
ServiceFlags nServices{NODE_NONE};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user