Changeset View
Changeset View
Standalone View
Standalone View
src/addrman.cpp
| Show First 20 Lines • Show All 188 Lines • ▼ Show 20 Lines | template <typename Stream> void AddrManImpl::Serialize(Stream &s_) const { | ||||
| * and supports changes to the ADDRMAN_ parameters without breaking the | * and supports changes to the ADDRMAN_ parameters without breaking the | ||||
| * on-disk structure. | * on-disk structure. | ||||
| * | * | ||||
| * We don't use SERIALIZE_METHODS since the serialization and | * We don't use SERIALIZE_METHODS since the serialization and | ||||
| * deserialization code has very little in common. | * deserialization code has very little in common. | ||||
| */ | */ | ||||
| // Always serialize in the latest version (FILE_FORMAT). | // Always serialize in the latest version (FILE_FORMAT). | ||||
| ParamsStream s{CAddress::V2_DISK, s_}; | |||||
| OverrideStream<Stream> s(&s_, s_.GetType(), | |||||
| s_.GetVersion() | ADDRV2_FORMAT); | |||||
| s << static_cast<uint8_t>(FILE_FORMAT); | s << static_cast<uint8_t>(FILE_FORMAT); | ||||
| // Increment `lowest_compatible` iff a newly introduced format is | // Increment `lowest_compatible` iff a newly introduced format is | ||||
| // incompatible with the previous one. | // incompatible with the previous one. | ||||
| static constexpr uint8_t lowest_compatible = Format::V4_MULTIPORT; | static constexpr uint8_t lowest_compatible = Format::V4_MULTIPORT; | ||||
| s << static_cast<uint8_t>(INCOMPATIBILITY_BASE + lowest_compatible); | s << static_cast<uint8_t>(INCOMPATIBILITY_BASE + lowest_compatible); | ||||
| ▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | |||||
| template <typename Stream> void AddrManImpl::Unserialize(Stream &s_) { | template <typename Stream> void AddrManImpl::Unserialize(Stream &s_) { | ||||
| LOCK(cs); | LOCK(cs); | ||||
| assert(vRandom.empty()); | assert(vRandom.empty()); | ||||
| Format format; | Format format; | ||||
| s_ >> Using<CustomUintFormatter<1>>(format); | s_ >> Using<CustomUintFormatter<1>>(format); | ||||
| int stream_version = s_.GetVersion(); | const auto ser_params = | ||||
| if (format >= Format::V3_BIP155) { | (format >= Format::V3_BIP155 ? CAddress::V2_DISK : CAddress::V1_DISK); | ||||
| // Add ADDRV2_FORMAT to the version so that the CNetAddr and | ParamsStream s{ser_params, s_}; | ||||
| // CAddress unserialize methods know that an address in addrv2 | |||||
| // format is coming. | |||||
| stream_version |= ADDRV2_FORMAT; | |||||
| } | |||||
| OverrideStream<Stream> s(&s_, s_.GetType(), stream_version); | |||||
| uint8_t compat; | uint8_t compat; | ||||
| s >> compat; | s >> compat; | ||||
| if (compat < INCOMPATIBILITY_BASE) { | if (compat < INCOMPATIBILITY_BASE) { | ||||
| throw std::ios_base::failure( | throw std::ios_base::failure( | ||||
| strprintf("Corrupted addrman database: The compat value (%u) " | strprintf("Corrupted addrman database: The compat value (%u) " | ||||
| "is lower than the expected minimum value %u.", | "is lower than the expected minimum value %u.", | ||||
| compat, INCOMPATIBILITY_BASE)); | compat, INCOMPATIBILITY_BASE)); | ||||
| ▲ Show 20 Lines • Show All 991 Lines • ▼ Show 20 Lines | template <typename Stream> void AddrMan::Serialize(Stream &s_) const { | ||||
| m_impl->Serialize<Stream>(s_); | m_impl->Serialize<Stream>(s_); | ||||
| } | } | ||||
| template <typename Stream> void AddrMan::Unserialize(Stream &s_) { | template <typename Stream> void AddrMan::Unserialize(Stream &s_) { | ||||
| m_impl->Unserialize<Stream>(s_); | m_impl->Unserialize<Stream>(s_); | ||||
| } | } | ||||
| // explicit instantiation | // explicit instantiation | ||||
| template void AddrMan::Serialize(HashedSourceWriter<CAutoFile> &s) const; | template void AddrMan::Serialize(HashedSourceWriter<AutoFile> &s) const; | ||||
| template void AddrMan::Serialize(CDataStream &s) const; | template void AddrMan::Serialize(DataStream &s) const; | ||||
| template void AddrMan::Unserialize(CAutoFile &s); | template void AddrMan::Unserialize(AutoFile &s); | ||||
| template void AddrMan::Unserialize(CHashVerifier<CAutoFile> &s); | template void AddrMan::Unserialize(HashVerifier<AutoFile> &s); | ||||
| template void AddrMan::Unserialize(CDataStream &s); | template void AddrMan::Unserialize(DataStream &s); | ||||
| template void AddrMan::Unserialize(CHashVerifier<CDataStream> &s); | template void AddrMan::Unserialize(HashVerifier<DataStream> &s); | ||||
| size_t AddrMan::size() const { | size_t AddrMan::size() const { | ||||
| return m_impl->size(); | return m_impl->size(); | ||||
| } | } | ||||
| bool AddrMan::Add(const std::vector<CAddress> &vAddr, const CNetAddr &source, | bool AddrMan::Add(const std::vector<CAddress> &vAddr, const CNetAddr &source, | ||||
| std::chrono::seconds time_penalty) { | std::chrono::seconds time_penalty) { | ||||
| return m_impl->Add(vAddr, source, time_penalty); | return m_impl->Add(vAddr, source, time_penalty); | ||||
| Show All 40 Lines | |||||