mirror of
https://github.com/dashpay/dash.git
synced 2024-12-25 20:12:57 +01:00
merge bitcoin#22915: Remove confusing CAddrDB
This commit is contained in:
parent
3f69606827
commit
5706edad5f
@ -171,22 +171,19 @@ bool CBanDB::Read(banmap_t& banSet)
|
||||
return true;
|
||||
}
|
||||
|
||||
CAddrDB::CAddrDB()
|
||||
{
|
||||
pathAddr = GetDataDir() / "peers.dat";
|
||||
}
|
||||
|
||||
bool CAddrDB::Write(const CAddrMan& addr)
|
||||
bool DumpPeerAddresses(const ArgsManager& args, const CAddrMan& addr)
|
||||
{
|
||||
const auto pathAddr = GetDataDir() / "peers.dat";
|
||||
return SerializeFileDB("peers", pathAddr, addr, CLIENT_VERSION);
|
||||
}
|
||||
|
||||
bool CAddrDB::Read(CAddrMan& addr)
|
||||
bool ReadPeerAddresses(const ArgsManager& args, CAddrMan& addr)
|
||||
{
|
||||
const auto pathAddr = GetDataDir() / "peers.dat";
|
||||
return DeserializeFileDB(pathAddr, addr, CLIENT_VERSION);
|
||||
}
|
||||
|
||||
bool CAddrDB::Read(CAddrMan& addr, CDataStream& ssPeers)
|
||||
bool ReadFromStream(CAddrMan& addr, CDataStream& ssPeers)
|
||||
{
|
||||
return DeserializeDB(ssPeers, addr, false);
|
||||
}
|
||||
|
18
src/addrdb.h
18
src/addrdb.h
@ -12,21 +12,15 @@
|
||||
|
||||
#include <vector>
|
||||
|
||||
class CAddress;
|
||||
class ArgsManager;
|
||||
class CAddrMan;
|
||||
class CAddress;
|
||||
class CDataStream;
|
||||
|
||||
/** Access to the (IP) address database (peers.dat) */
|
||||
class CAddrDB
|
||||
{
|
||||
private:
|
||||
fs::path pathAddr;
|
||||
public:
|
||||
CAddrDB();
|
||||
bool Write(const CAddrMan& addr);
|
||||
bool Read(CAddrMan& addr);
|
||||
static bool Read(CAddrMan& addr, CDataStream& ssPeers);
|
||||
};
|
||||
bool DumpPeerAddresses(const ArgsManager& args, const CAddrMan& addr);
|
||||
bool ReadPeerAddresses(const ArgsManager& args, CAddrMan& addr);
|
||||
/** Only used by tests. */
|
||||
bool ReadFromStream(CAddrMan& addr, CDataStream& ssPeers);
|
||||
|
||||
/** Access to the banlist database (banlist.json) */
|
||||
class CBanDB
|
||||
|
@ -5,10 +5,12 @@
|
||||
|
||||
#include <addrman.h>
|
||||
|
||||
#include <clientversion.h>
|
||||
#include <hash.h>
|
||||
#include <logging.h>
|
||||
#include <netaddress.h>
|
||||
#include <serialize.h>
|
||||
#include <streams.h>
|
||||
|
||||
#include <cmath>
|
||||
#include <optional>
|
||||
|
@ -6,23 +6,16 @@
|
||||
#ifndef BITCOIN_ADDRMAN_H
|
||||
#define BITCOIN_ADDRMAN_H
|
||||
|
||||
#include <clientversion.h>
|
||||
#include <config/bitcoin-config.h>
|
||||
#include <fs.h>
|
||||
#include <hash.h>
|
||||
#include <logging.h>
|
||||
#include <netaddress.h>
|
||||
#include <protocol.h>
|
||||
#include <random.h>
|
||||
#include <streams.h>
|
||||
#include <sync.h>
|
||||
#include <timedata.h>
|
||||
#include <tinyformat.h>
|
||||
#include <util/system.h>
|
||||
|
||||
#include <ios>
|
||||
#include <cstdint>
|
||||
#include <optional>
|
||||
#include <set>
|
||||
#include <stdint.h>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
|
@ -1698,14 +1698,13 @@ bool AppInitMain(const CoreContext& context, NodeContext& node, interfaces::Bloc
|
||||
// Load addresses from peers.dat
|
||||
uiInterface.InitMessage(_("Loading P2P addresses…").translated);
|
||||
int64_t nStart = GetTimeMillis();
|
||||
CAddrDB adb;
|
||||
if (adb.Read(*node.addrman)) {
|
||||
if (ReadPeerAddresses(args, *node.addrman)) {
|
||||
LogPrintf("Loaded %i addresses from peers.dat %dms\n", node.addrman->size(), GetTimeMillis() - nStart);
|
||||
} else {
|
||||
// Addrman can be in an inconsistent state after failure, reset it
|
||||
node.addrman = std::make_unique<CAddrMan>(asmap, /* deterministic */ false, /* consistency_check_ratio */ check_addrman);
|
||||
LogPrintf("Recreating peers.dat\n");
|
||||
adb.Write(*node.addrman);
|
||||
DumpPeerAddresses(args, *node.addrman);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@
|
||||
#include <net.h>
|
||||
#include <netmessagemaker.h>
|
||||
|
||||
#include <addrdb.h>
|
||||
#include <banman.h>
|
||||
#include <clientversion.h>
|
||||
#include <compat.h>
|
||||
@ -26,6 +27,7 @@
|
||||
#include <scheduler.h>
|
||||
#include <util/sock.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/system.h>
|
||||
#include <util/thread.h>
|
||||
#include <util/time.h>
|
||||
#include <util/translation.h>
|
||||
@ -2324,8 +2326,7 @@ void CConnman::DumpAddresses()
|
||||
{
|
||||
int64_t nStart = GetTimeMillis();
|
||||
|
||||
CAddrDB adb;
|
||||
adb.Write(addrman);
|
||||
DumpPeerAddresses(::gArgs, addrman);
|
||||
|
||||
LogPrint(BCLog::NET, "Flushed %d addresses to peers.dat %dms\n",
|
||||
addrman.size(), GetTimeMillis() - nStart);
|
||||
|
@ -6,7 +6,6 @@
|
||||
#ifndef BITCOIN_NET_H
|
||||
#define BITCOIN_NET_H
|
||||
|
||||
#include <addrdb.h>
|
||||
#include <addrman.h>
|
||||
#include <bloom.h>
|
||||
#include <chainparams.h>
|
||||
|
@ -5,6 +5,7 @@
|
||||
#ifndef BITCOIN_QT_BANTABLEMODEL_H
|
||||
#define BITCOIN_QT_BANTABLEMODEL_H
|
||||
|
||||
#include <addrdb.h>
|
||||
#include <net.h>
|
||||
|
||||
#include <memory>
|
||||
|
@ -12,6 +12,7 @@
|
||||
#include <qt/walletcontroller.h>
|
||||
#include <qt/walletmodel.h>
|
||||
#include <qt/walletview.h>
|
||||
#include <util/system.h>
|
||||
|
||||
#include <cassert>
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <addrdb.h>
|
||||
#include <addrman.h>
|
||||
#include <chainparams.h>
|
||||
#include <clientversion.h>
|
||||
#include <hash.h>
|
||||
#include <netbase.h>
|
||||
#include <random.h>
|
||||
@ -1001,8 +1002,7 @@ BOOST_AUTO_TEST_CASE(addrman_evictionworks)
|
||||
BOOST_CHECK(addrman.SelectTriedCollision().ToString() == "[::]:0");
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(caddrdb_read)
|
||||
BOOST_AUTO_TEST_CASE(load_addrman)
|
||||
{
|
||||
CAddrManUncorrupted addrmanUncorrupted;
|
||||
|
||||
@ -1037,17 +1037,17 @@ BOOST_AUTO_TEST_CASE(caddrdb_read)
|
||||
BOOST_CHECK(addrman1.size() == 3);
|
||||
BOOST_CHECK(exceptionThrown == false);
|
||||
|
||||
// Test that CAddrDB::Read creates an addrman with the correct number of addrs.
|
||||
// Test that ReadFromStream creates an addrman with the correct number of addrs.
|
||||
CDataStream ssPeers2 = AddrmanToStream(addrmanUncorrupted);
|
||||
|
||||
CAddrMan addrman2(/* asmap */ std::vector<bool>(), /* deterministic */ false, /* consistency_check_ratio */ 100);
|
||||
BOOST_CHECK(addrman2.size() == 0);
|
||||
BOOST_CHECK(CAddrDB::Read(addrman2, ssPeers2));
|
||||
BOOST_CHECK(ReadFromStream(addrman2, ssPeers2));
|
||||
BOOST_CHECK(addrman2.size() == 3);
|
||||
}
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(caddrdb_read_corrupted)
|
||||
BOOST_AUTO_TEST_CASE(load_addrman_corrupted)
|
||||
{
|
||||
CAddrManCorrupted addrmanCorrupted;
|
||||
|
||||
@ -1063,16 +1063,16 @@ BOOST_AUTO_TEST_CASE(caddrdb_read_corrupted)
|
||||
} catch (const std::exception&) {
|
||||
exceptionThrown = true;
|
||||
}
|
||||
// Even through de-serialization failed addrman is not left in a clean state.
|
||||
// Even though de-serialization failed addrman is not left in a clean state.
|
||||
BOOST_CHECK(addrman1.size() == 1);
|
||||
BOOST_CHECK(exceptionThrown);
|
||||
|
||||
// Test that CAddrDB::Read fails if peers.dat is corrupt
|
||||
// Test that ReadFromStream fails if peers.dat is corrupt
|
||||
CDataStream ssPeers2 = AddrmanToStream(addrmanCorrupted);
|
||||
|
||||
CAddrMan addrman2(/* asmap */ std::vector<bool>(), /* deterministic */ false, /* consistency_check_ratio */ 100);
|
||||
BOOST_CHECK(addrman2.size() == 0);
|
||||
BOOST_CHECK(!CAddrDB::Read(addrman2, ssPeers2));
|
||||
BOOST_CHECK(!ReadFromStream(addrman2, ssPeers2));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
@ -2,6 +2,7 @@
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <addrdb.h>
|
||||
#include <addrman.h>
|
||||
#include <net.h>
|
||||
#include <test/fuzz/FuzzedDataProvider.h>
|
||||
@ -22,5 +23,5 @@ FUZZ_TARGET_INIT(data_stream_addr_man, initialize_data_stream_addr_man)
|
||||
FuzzedDataProvider fuzzed_data_provider{buffer.data(), buffer.size()};
|
||||
CDataStream data_stream = ConsumeDataStream(fuzzed_data_provider);
|
||||
CAddrMan addr_man(/* asmap */ std::vector<bool>(), /* deterministic */ false, /* consistency_check_ratio */ 0);
|
||||
CAddrDB::Read(addr_man, data_stream);
|
||||
ReadFromStream(addr_man, data_stream);
|
||||
}
|
||||
|
@ -25,6 +25,7 @@
|
||||
#include <test/fuzz/fuzz.h>
|
||||
#include <test/fuzz/util.h>
|
||||
#include <uint256.h>
|
||||
#include <univalue.h>
|
||||
#include <util/check.h>
|
||||
#include <util/moneystr.h>
|
||||
#include <util/overflow.h>
|
||||
|
Loading…
Reference in New Issue
Block a user