Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

addrdb.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 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 <serialize.h>
11 
12 #include <string>
13 #include <map>
14 
15 class CSubNet;
16 class CAddrMan;
17 class CDataStream;
18 
19 typedef enum BanReason
20 {
24 } BanReason;
25 
26 class CBanEntry
27 {
28 public:
29  static const int CURRENT_VERSION=1;
30  int nVersion;
31  int64_t nCreateTime;
32  int64_t nBanUntil;
33  uint8_t banReason;
34 
36  {
37  SetNull();
38  }
39 
40  explicit CBanEntry(int64_t nCreateTimeIn)
41  {
42  SetNull();
43  nCreateTime = nCreateTimeIn;
44  }
45 
47 
48  template <typename Stream, typename Operation>
49  inline void SerializationOp(Stream& s, Operation ser_action) {
50  READWRITE(this->nVersion);
54  }
55 
56  void SetNull()
57  {
59  nCreateTime = 0;
60  nBanUntil = 0;
62  }
63 
64  std::string banReasonToString() const
65  {
66  switch (banReason) {
68  return "node misbehaving";
70  return "manually added";
71  default:
72  return "unknown";
73  }
74  }
75 };
76 
77 typedef std::map<CSubNet, CBanEntry> banmap_t;
78 
80 class CAddrDB
81 {
82 private:
83  fs::path pathAddr;
84 public:
85  CAddrDB();
86  bool Write(const CAddrMan& addr);
87  bool Read(CAddrMan& addr);
88  static bool Read(CAddrMan& addr, CDataStream& ssPeers);
89 };
90 
92 class CBanDB
93 {
94 private:
95  fs::path pathBanlist;
96 public:
97  CBanDB();
98  bool Write(const banmap_t& banSet);
99  bool Read(banmap_t& banSet);
100 };
101 
102 #endif // BITCOIN_ADDRDB_H
void SetNull()
Definition: addrdb.h:56
Access to the (IP) address database (peers.dat)
Definition: addrdb.h:80
BanReason
Definition: addrdb.h:19
CBanEntry(int64_t nCreateTimeIn)
Definition: addrdb.h:40
#define READWRITE(obj)
Definition: serialize.h:165
CBanDB()
Definition: addrdb.cpp:107
CAddrDB()
Definition: addrdb.cpp:122
void SerializationOp(Stream &s, Operation ser_action)
Definition: addrdb.h:49
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:103
int nVersion
Definition: addrdb.h:30
std::string banReasonToString() const
Definition: addrdb.h:64
int64_t nCreateTime
Definition: addrdb.h:31
CBanEntry()
Definition: addrdb.h:35
Stochastical (IP) address manager.
Definition: addrman.h:182
Access to the banlist database (banlist.dat)
Definition: addrdb.h:92
std::map< CSubNet, CBanEntry > banmap_t
Definition: addrdb.h:77
bool Write(const CAddrMan &addr)
Definition: addrdb.cpp:127
bool Write(const banmap_t &banSet)
Definition: addrdb.cpp:112
int64_t nBanUntil
Definition: addrdb.h:32
fs::path pathBanlist
Definition: addrdb.h:95
bool Read(banmap_t &banSet)
Definition: addrdb.cpp:117
uint8_t banReason
Definition: addrdb.h:33
fs::path pathAddr
Definition: addrdb.h:83
ADD_SERIALIZE_METHODS
Definition: addrdb.h:46
static const int CURRENT_VERSION
Definition: addrdb.h:29
Definition: addrdb.h:26
bool Read(CAddrMan &addr)
Definition: addrdb.cpp:132
Released under the MIT license