Bitcoin Core  0.19.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 <map>
15 
16 class CSubNet;
17 class CAddrMan;
18 class CDataStream;
19 
20 typedef enum BanReason
21 {
25 } BanReason;
26 
27 class CBanEntry
28 {
29 public:
30  static const int CURRENT_VERSION=1;
31  int nVersion;
32  int64_t nCreateTime;
33  int64_t nBanUntil;
34  uint8_t banReason;
35 
37  {
38  SetNull();
39  }
40 
41  explicit CBanEntry(int64_t nCreateTimeIn)
42  {
43  SetNull();
44  nCreateTime = nCreateTimeIn;
45  }
46 
47  explicit CBanEntry(int64_t n_create_time_in, BanReason ban_reason_in) : CBanEntry(n_create_time_in)
48  {
49  banReason = ban_reason_in;
50  }
51 
52  SERIALIZE_METHODS(CBanEntry, obj) { READWRITE(obj.nVersion, obj.nCreateTime, obj.nBanUntil, obj.banReason); }
53 
54  void SetNull()
55  {
56  nVersion = CBanEntry::CURRENT_VERSION;
57  nCreateTime = 0;
58  nBanUntil = 0;
59  banReason = BanReasonUnknown;
60  }
61 
62  std::string banReasonToString() const
63  {
64  switch (banReason) {
66  return "node misbehaving";
68  return "manually added";
69  default:
70  return "unknown";
71  }
72  }
73 };
74 
76 class CAddrDB
77 {
78 private:
79  fs::path pathAddr;
80 public:
81  CAddrDB();
82  bool Write(const CAddrMan& addr);
83  bool Read(CAddrMan& addr);
84  static bool Read(CAddrMan& addr, CDataStream& ssPeers);
85 };
86 
88 class CBanDB
89 {
90 private:
91  const fs::path m_ban_list_path;
92 public:
93  explicit CBanDB(fs::path ban_list_path);
94  bool Write(const banmap_t& banSet);
95  bool Read(banmap_t& banSet);
96 };
97 
98 #endif // BITCOIN_ADDRDB_H
void SetNull()
Definition: addrdb.h:54
Access to the (IP) address database (peers.dat)
Definition: addrdb.h:76
BanReason
Definition: addrdb.h:20
CBanEntry(int64_t nCreateTimeIn)
Definition: addrdb.h:41
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:201
const fs::path m_ban_list_path
Definition: addrdb.h:91
CBanEntry(int64_t n_create_time_in, BanReason ban_reason_in)
Definition: addrdb.h:47
int nVersion
Definition: addrdb.h:31
std::string banReasonToString() const
Definition: addrdb.h:62
int64_t nCreateTime
Definition: addrdb.h:32
CBanEntry()
Definition: addrdb.h:36
Stochastical (IP) address manager.
Definition: addrman.h:176
Access to the banlist database (banlist.dat)
Definition: addrdb.h:88
int64_t nBanUntil
Definition: addrdb.h:33
uint8_t banReason
Definition: addrdb.h:34
fs::path pathAddr
Definition: addrdb.h:79
SERIALIZE_METHODS(CBanEntry, obj)
Definition: addrdb.h:52
std::map< CSubNet, CBanEntry > banmap_t
Definition: net_types.h:13
static const int CURRENT_VERSION
Definition: addrdb.h:30
Definition: addrdb.h:27
#define READWRITE(...)
Definition: serialize.h:191