Branch data Line data Source code
# 1 : : // Copyright (c) 2009-2010 Satoshi Nakamoto # 2 : : // Copyright (c) 2009-2020 The Bitcoin Core developers # 3 : : // Distributed under the MIT software license, see the accompanying # 4 : : // file COPYING or http://www.opensource.org/licenses/mit-license.php. # 5 : : # 6 : : #ifndef BITCOIN_ADDRDB_H # 7 : : #define BITCOIN_ADDRDB_H # 8 : : # 9 : : #include <fs.h> # 10 : : #include <net_types.h> // For banmap_t # 11 : : #include <serialize.h> # 12 : : # 13 : : #include <string> # 14 : : #include <vector> # 15 : : # 16 : : class CAddress; # 17 : : class CAddrMan; # 18 : : class CDataStream; # 19 : : # 20 : : class CBanEntry # 21 : : { # 22 : : public: # 23 : : static const int CURRENT_VERSION=1; # 24 : : int nVersion; # 25 : : int64_t nCreateTime; # 26 : : int64_t nBanUntil; # 27 : : # 28 : : CBanEntry() # 29 : 27 : { # 30 : 27 : SetNull(); # 31 : 27 : } # 32 : : # 33 : : explicit CBanEntry(int64_t nCreateTimeIn) # 34 : 22 : { # 35 : 22 : SetNull(); # 36 : 22 : nCreateTime = nCreateTimeIn; # 37 : 22 : } # 38 : : # 39 : : SERIALIZE_METHODS(CBanEntry, obj) # 40 : 67 : { # 41 : 67 : uint8_t ban_reason = 2; //! For backward compatibility # 42 : 67 : READWRITE(obj.nVersion, obj.nCreateTime, obj.nBanUntil, ban_reason); # 43 : 67 : } # 44 : : # 45 : : void SetNull() # 46 : 49 : { # 47 : 49 : nVersion = CBanEntry::CURRENT_VERSION; # 48 : 49 : nCreateTime = 0; # 49 : 49 : nBanUntil = 0; # 50 : 49 : } # 51 : : }; # 52 : : # 53 : : /** Access to the (IP) address database (peers.dat) */ # 54 : : class CAddrDB # 55 : : { # 56 : : private: # 57 : : fs::path pathAddr; # 58 : : public: # 59 : : CAddrDB(); # 60 : : bool Write(const CAddrMan& addr); # 61 : : bool Read(CAddrMan& addr); # 62 : : static bool Read(CAddrMan& addr, CDataStream& ssPeers); # 63 : : }; # 64 : : # 65 : : /** Access to the banlist database (banlist.dat) */ # 66 : : class CBanDB # 67 : : { # 68 : : private: # 69 : : const fs::path m_ban_list_path; # 70 : : public: # 71 : : explicit CBanDB(fs::path ban_list_path); # 72 : : bool Write(const banmap_t& banSet); # 73 : : bool Read(banmap_t& banSet); # 74 : : }; # 75 : : # 76 : : /** # 77 : : * Dump the anchor IP address database (anchors.dat) # 78 : : * # 79 : : * Anchors are last known outgoing block-relay-only peers that are # 80 : : * tried to re-connect to on startup. # 81 : : */ # 82 : : void DumpAnchors(const fs::path& anchors_db_path, const std::vector<CAddress>& anchors); # 83 : : # 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 : : # 92 : : #endif // BITCOIN_ADDRDB_H