Bitcoin ABC  0.26.3
P2P Digital Currency
addrdb.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 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 <optional>
14 #include <string>
15 #include <vector>
16 
17 class ArgsManager;
18 class AddrMan;
19 class CAddress;
20 class CDataStream;
21 class CChainParams;
22 struct bilingual_str;
23 
24 bool DumpPeerAddresses(const CChainParams &chainParams, const ArgsManager &args,
25  const AddrMan &addr);
27 void ReadFromStream(const CChainParams &chainParams, AddrMan &addr,
28  CDataStream &ssPeers);
29 
30 class CBanEntry {
31 public:
32  static const int CURRENT_VERSION = 1;
33  int nVersion;
34  int64_t nCreateTime;
35  int64_t nBanUntil;
36 
37  CBanEntry() { SetNull(); }
38 
39  explicit CBanEntry(int64_t nCreateTimeIn) {
40  SetNull();
41  nCreateTime = nCreateTimeIn;
42  }
43 
46  uint8_t ban_reason = 2;
47  READWRITE(obj.nVersion, obj.nCreateTime, obj.nBanUntil, ban_reason);
48  }
49 
50  void SetNull() {
52  nCreateTime = 0;
53  nBanUntil = 0;
54  }
55 };
56 
58 class CBanDB {
59 private:
62 
63 public:
64  CBanDB(fs::path ban_list_path, const CChainParams &_chainParams);
65  bool Write(const banmap_t &banSet);
66  bool Read(banmap_t &banSet);
67 };
68 
70 std::optional<bilingual_str> LoadAddrman(const CChainParams &chainparams,
71  const std::vector<bool> &asmap,
72  const ArgsManager &args,
73  std::unique_ptr<AddrMan> &addrman);
74 
81 void DumpAnchors(const CChainParams &chainParams,
82  const fs::path &anchors_db_path,
83  const std::vector<CAddress> &anchors);
84 
92 std::vector<CAddress> ReadAnchors(const CChainParams &chainParams,
93  const fs::path &anchors_db_path);
94 
95 #endif // BITCOIN_ADDRDB_H
void ReadFromStream(const CChainParams &chainParams, AddrMan &addr, CDataStream &ssPeers)
Only used by tests.
Definition: addrdb.cpp:155
bool DumpPeerAddresses(const CChainParams &chainParams, const ArgsManager &args, const AddrMan &addr)
Definition: addrdb.cpp:149
std::vector< CAddress > ReadAnchors(const CChainParams &chainParams, const fs::path &anchors_db_path)
Read the anchor IP address database (anchors.dat)
Definition: addrdb.cpp:219
std::optional< bilingual_str > LoadAddrman(const CChainParams &chainparams, const std::vector< bool > &asmap, const ArgsManager &args, std::unique_ptr< AddrMan > &addrman)
Returns an error string on failure.
Definition: addrdb.cpp:160
void DumpAnchors(const CChainParams &chainParams, const fs::path &anchors_db_path, const std::vector< CAddress > &anchors)
Dump the anchor IP address database (anchors.dat)
Definition: addrdb.cpp:210
Stochastic address manager.
Definition: addrman.h:68
A CService with information about it as peer.
Definition: protocol.h:445
Access to the banlist database (banlist.dat)
Definition: addrdb.h:58
bool Write(const banmap_t &banSet)
Definition: addrdb.cpp:129
const fs::path m_ban_list_path
Definition: addrdb.h:60
CBanDB(fs::path ban_list_path, const CChainParams &_chainParams)
Definition: addrdb.cpp:126
bool Read(banmap_t &banSet)
Definition: addrdb.cpp:133
const CChainParams & chainParams
Definition: addrdb.h:61
Definition: addrdb.h:30
static const int CURRENT_VERSION
Definition: addrdb.h:32
int64_t nCreateTime
Definition: addrdb.h:34
CBanEntry()
Definition: addrdb.h:37
CBanEntry(int64_t nCreateTimeIn)
Definition: addrdb.h:39
SERIALIZE_METHODS(CBanEntry, obj)
Definition: addrdb.h:44
void SetNull()
Definition: addrdb.h:50
int nVersion
Definition: addrdb.h:33
int64_t nBanUntil
Definition: addrdb.h:35
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:74
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:197
Path class wrapper to prepare application code for transition from boost::filesystem library to std::...
Definition: fs.h:33
std::map< CSubNet, CBanEntry > banmap_t
Definition: net_types.h:13
#define READWRITE(...)
Definition: serialize.h:180
Bilingual messages:
Definition: translation.h:17