Skip to content

Commit c29272a

Browse files
committed
p2p: Add ReadAnchors()
1 parent 567008d commit c29272a

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/addrdb.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,16 @@ void DumpAnchors(const fs::path& anchors_db_path, const std::vector<CAddress>& a
163163
LOG_TIME_SECONDS(strprintf("Flush %d outbound block-relay-only peer addresses to anchors.dat", anchors.size()));
164164
SerializeFileDB("anchors", anchors_db_path, anchors);
165165
}
166+
167+
std::vector<CAddress> ReadAnchors(const fs::path& anchors_db_path)
168+
{
169+
std::vector<CAddress> anchors;
170+
if (DeserializeFileDB(anchors_db_path, anchors)) {
171+
LogPrintf("Loaded %i addresses from %s\n", anchors.size(), anchors_db_path.filename());
172+
} else {
173+
anchors.clear();
174+
}
175+
176+
fs::remove(anchors_db_path);
177+
return anchors;
178+
}

src/addrdb.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,12 @@ class CBanDB
8181
*/
8282
void DumpAnchors(const fs::path& anchors_db_path, const std::vector<CAddress>& anchors);
8383

84+
/**
85+
* Read the anchor IP address database (anchors.dat)
86+
*
87+
* Deleting anchors.dat is intentional as it avoids renewed peering to anchors after
88+
* an unclean shutdown and thus potential exploitation of the anchor peer policy.
89+
*/
90+
std::vector<CAddress> ReadAnchors(const fs::path& anchors_db_path);
91+
8492
#endif // BITCOIN_ADDRDB_H

0 commit comments

Comments
 (0)