Bitcoin Core  0.20.99
P2P Digital Currency
addrdb.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2019 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 
29  {
30  SetNull();
31  }
32 
33  explicit CBanEntry(int64_t nCreateTimeIn)
34  {
35  SetNull();
36  nCreateTime = nCreateTimeIn;
37  }
38 
40  {
41  uint8_t ban_reason = 2;
42  READWRITE(obj.nVersion, obj.nCreateTime, obj.nBanUntil, ban_reason);
43  }
44 
45  void SetNull()
46  {
47  nVersion = CBanEntry::CURRENT_VERSION;
48  nCreateTime = 0;
49  nBanUntil = 0;
50  }
51 };
52 
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 
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 
82 void DumpAnchors(const fs::path& anchors_db_path, const std::vector<CAddress>& anchors);
83 
90 std::vector<CAddress> ReadAnchors(const fs::path& anchors_db_path);
91 
92 #endif // BITCOIN_ADDRDB_H
void SetNull()
Definition: addrdb.h:45
Access to the (IP) address database (peers.dat)
Definition: addrdb.h:54
CBanEntry(int64_t nCreateTimeIn)
Definition: addrdb.h:33
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:202
const fs::path m_ban_list_path
Definition: addrdb.h:69
int nVersion
Definition: addrdb.h:24
int64_t nCreateTime
Definition: addrdb.h:25
CBanEntry()
Definition: addrdb.h:28
Stochastical (IP) address manager.
Definition: addrman.h:171
Access to the banlist database (banlist.dat)
Definition: addrdb.h:66
A CService with information about it as peer.
Definition: protocol.h:360
int64_t nBanUntil
Definition: addrdb.h:26
std::vector< CAddress > ReadAnchors(const fs::path &anchors_db_path)
Read the anchor IP address database (anchors.dat)
Definition: addrdb.cpp:167
void DumpAnchors(const fs::path &anchors_db_path, const std::vector< CAddress > &anchors)
Dump the anchor IP address database (anchors.dat)
Definition: addrdb.cpp:161
fs::path pathAddr
Definition: addrdb.h:57
SERIALIZE_METHODS(CBanEntry, obj)
Definition: addrdb.h:39
std::map< CSubNet, CBanEntry > banmap_t
Definition: net_types.h:13
static const int CURRENT_VERSION
Definition: addrdb.h:23
Definition: addrdb.h:20
#define READWRITE(...)
Definition: serialize.h:175