p2p: Add ReadAnchors()

This commit is contained in:
Hennadii Stepanov committed 2020-10-09 14:29:04 +03:00
1 parent 567008d2a0
commit c29272a157
2 files changed
+21

No files matched your search

+13
View File
@@ -163,3 +163,16 @@ void DumpAnchors(const fs::path& anchors_db_path, const std::vector<CAddress>& a
LOG_TIME_SECONDS(strprintf("Flush %d outbound block-relay-only peer addresses to anchors.dat", anchors.size()));
SerializeFileDB("anchors", anchors_db_path, anchors);
}
std::vector<CAddress> ReadAnchors(const fs::path& anchors_db_path)
{
std::vector<CAddress> anchors;
if (DeserializeFileDB(anchors_db_path, anchors)) {
LogPrintf("Loaded %i addresses from %s\n", anchors.size(), anchors_db_path.filename());
} else {
anchors.clear();
}
fs::remove(anchors_db_path);
return anchors;
}
+8
View File
@@ -81,4 +81,12 @@ public:
*/
void DumpAnchors(const fs::path& anchors_db_path, const std::vector<CAddress>& anchors);
/**
* Read the anchor IP address database (anchors.dat)
*
* Deleting anchors.dat is intentional as it avoids renewed peering to anchors after
* an unclean shutdown and thus potential exploitation of the anchor peer policy.
*/
std::vector<CAddress> ReadAnchors(const fs::path& anchors_db_path);
#endif // BITCOIN_ADDRDB_H