Skip to content

Commit 5446070

Browse files
committed
Merge bitcoin/bitcoin#22911: [net] Minor cleanups to asmap
853c4ed [net] Remove asmap argument from CNode::CopyStats() (John Newbery) 9fd5618 [asmap] Make DecodeAsmap() a utility function (John Newbery) bfdf4ef [asmap] Remove SanityCheckASMap() from netaddress (John Newbery) 07a9ecc [net] Remove CConnman::Options.m_asmap (John Newbery) Pull request description: These small cleanups to the asmap code are the first 4 commits from #22910. They're minor improvements that are independently useful whether or not 22910 is merged. ACKs for top commit: naumenkogs: ACK 853c4ed theStack: Concept and code-review ACK 853c4ed 🗺️ fanquake: ACK 853c4ed Tree-SHA512: 64783743182592ac165df6ff8d18870b63861e9204ed722c207fca6938687aac43232a5ac4d8228cf8b92130ab0349de1b410a2467bb5a9d60dd9a7221b3b85b
2 parents b653415 + 853c4ed commit 5446070

File tree

12 files changed

+52
-53
lines changed

12 files changed

+52
-53
lines changed

src/addrman.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,30 +1009,3 @@ CAddrInfo CAddrMan::SelectTriedCollision_()
10091009

10101010
return mapInfo[id_old];
10111011
}
1012-
1013-
std::vector<bool> CAddrMan::DecodeAsmap(fs::path path)
1014-
{
1015-
std::vector<bool> bits;
1016-
FILE *filestr = fsbridge::fopen(path, "rb");
1017-
CAutoFile file(filestr, SER_DISK, CLIENT_VERSION);
1018-
if (file.IsNull()) {
1019-
LogPrintf("Failed to open asmap file from disk\n");
1020-
return bits;
1021-
}
1022-
fseek(filestr, 0, SEEK_END);
1023-
int length = ftell(filestr);
1024-
LogPrintf("Opened asmap file %s (%d bytes) from disk\n", path, length);
1025-
fseek(filestr, 0, SEEK_SET);
1026-
uint8_t cur_byte;
1027-
for (int i = 0; i < length; ++i) {
1028-
file >> cur_byte;
1029-
for (int bit = 0; bit < 8; ++bit) {
1030-
bits.push_back((cur_byte >> bit) & 1);
1031-
}
1032-
}
1033-
if (!SanityCheckASMap(bits)) {
1034-
LogPrintf("Sanity check of asmap file %s failed\n", path);
1035-
return {};
1036-
}
1037-
return bits;
1038-
}

src/addrman.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,6 @@ static constexpr int ADDRMAN_BUCKET_SIZE{1 << ADDRMAN_BUCKET_SIZE_LOG2};
142142
class CAddrMan
143143
{
144144
public:
145-
// Read asmap from provided binary file
146-
static std::vector<bool> DecodeAsmap(fs::path path);
147-
148145
template <typename Stream>
149146
void Serialize(Stream& s_) const EXCLUSIVE_LOCKS_REQUIRED(!cs);
150147

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1189,7 +1189,7 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
11891189
InitError(strprintf(_("Could not find asmap file %s"), asmap_path));
11901190
return false;
11911191
}
1192-
asmap = CAddrMan::DecodeAsmap(asmap_path);
1192+
asmap = DecodeAsmap(asmap_path);
11931193
if (asmap.size() == 0) {
11941194
InitError(strprintf(_("Could not parse asmap file %s"), asmap_path));
11951195
return false;

src/net.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,14 +554,13 @@ Network CNode::ConnectedThroughNetwork() const
554554

555555
#undef X
556556
#define X(name) stats.name = name
557-
void CNode::CopyStats(CNodeStats& stats, const std::vector<bool>& asmap)
557+
void CNode::CopyStats(CNodeStats& stats)
558558
{
559559
stats.nodeid = this->GetId();
560560
X(nServices);
561561
X(addr);
562562
X(addrBind);
563563
stats.m_network = ConnectedThroughNetwork();
564-
stats.m_mapped_as = addr.GetMappedAS(asmap);
565564
if (m_tx_relay != nullptr) {
566565
LOCK(m_tx_relay->cs_filter);
567566
stats.fRelayTxes = m_tx_relay->fRelayTxes;
@@ -2805,7 +2804,8 @@ void CConnman::GetNodeStats(std::vector<CNodeStats>& vstats) const
28052804
vstats.reserve(vNodes.size());
28062805
for (CNode* pnode : vNodes) {
28072806
vstats.emplace_back();
2808-
pnode->CopyStats(vstats.back(), addrman.GetAsmap());
2807+
pnode->CopyStats(vstats.back());
2808+
vstats.back().m_mapped_as = pnode->addr.GetMappedAS(addrman.GetAsmap());
28092809
}
28102810
}
28112811

src/net.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -651,7 +651,7 @@ class CNode
651651

652652
void CloseSocketDisconnect();
653653

654-
void CopyStats(CNodeStats& stats, const std::vector<bool>& asmap);
654+
void CopyStats(CNodeStats& stats);
655655

656656
ServiceFlags GetLocalServices() const
657657
{
@@ -767,7 +767,6 @@ class CConnman
767767
bool m_use_addrman_outgoing = true;
768768
std::vector<std::string> m_specified_outgoing;
769769
std::vector<std::string> m_added_nodes;
770-
std::vector<bool> m_asmap;
771770
bool m_i2p_accept_incoming;
772771
};
773772

src/netaddress.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,8 +1242,3 @@ bool operator<(const CSubNet& a, const CSubNet& b)
12421242
{
12431243
return (a.network < b.network || (a.network == b.network && memcmp(a.netmask, b.netmask, 16) < 0));
12441244
}
1245-
1246-
bool SanityCheckASMap(const std::vector<bool>& asmap)
1247-
{
1248-
return SanityCheckASMap(asmap, 128); // For IP address lookups, the input is 128 bits
1249-
}

src/netaddress.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,4 @@ class CService : public CNetAddr
567567
}
568568
};
569569

570-
bool SanityCheckASMap(const std::vector<bool>& asmap);
571-
572570
#endif // BITCOIN_NETADDRESS_H

src/test/fuzz/addrman.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ class CAddrManDeterministic : public CAddrMan
221221
[[nodiscard]] inline std::vector<bool> ConsumeAsmap(FuzzedDataProvider& fuzzed_data_provider) noexcept
222222
{
223223
std::vector<bool> asmap = ConsumeRandomLengthBitVector(fuzzed_data_provider);
224-
if (!SanityCheckASMap(asmap)) asmap.clear();
224+
if (!SanityCheckASMap(asmap, 128)) asmap.clear();
225225
return asmap;
226226
}
227227

src/test/fuzz/asmap.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include <netaddress.h>
66
#include <test/fuzz/fuzz.h>
7+
#include <util/asmap.h>
78

89
#include <cstdint>
910
#include <vector>
@@ -42,7 +43,7 @@ FUZZ_TARGET(asmap)
4243
asmap.push_back((buffer[1 + i] >> j) & 1);
4344
}
4445
}
45-
if (!SanityCheckASMap(asmap)) return;
46+
if (!SanityCheckASMap(asmap, 128)) return;
4647

4748
const uint8_t* addr_data = buffer.data() + 1 + asmap_size;
4849
CNetAddr net_addr;

src/test/fuzz/net.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <test/fuzz/util.h>
1515
#include <test/util/net.h>
1616
#include <test/util/setup_common.h>
17+
#include <util/asmap.h>
1718

1819
#include <cstdint>
1920
#include <optional>
@@ -38,12 +39,8 @@ FUZZ_TARGET_INIT(net, initialize_net)
3839
node.CloseSocketDisconnect();
3940
},
4041
[&] {
41-
const std::vector<bool> asmap = ConsumeRandomLengthBitVector(fuzzed_data_provider);
42-
if (!SanityCheckASMap(asmap)) {
43-
return;
44-
}
4542
CNodeStats stats;
46-
node.CopyStats(stats, asmap);
43+
node.CopyStats(stats);
4744
},
4845
[&] {
4946
const CNode* add_ref_node = node.AddRef();

0 commit comments

Comments
 (0)