Dash Core  0.12.2.1
P2P Digital Currency
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 "serialize.h"
10 
11 #include <string>
12 #include <map>
13 #include <boost/filesystem/path.hpp>
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  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, int nType, int nVersion) {
50  READWRITE(this->nVersion);
51  nVersion = this->nVersion;
52  READWRITE(nCreateTime);
55  }
56 
57  void SetNull()
58  {
60  nCreateTime = 0;
61  nBanUntil = 0;
63  }
64 
65  std::string banReasonToString()
66  {
67  switch (banReason) {
69  return "node misbehaving";
71  return "manually added";
72  default:
73  return "unknown";
74  }
75  }
76 };
77 
78 typedef std::map<CSubNet, CBanEntry> banmap_t;
79 
81 class CAddrDB
82 {
83 private:
84  boost::filesystem::path pathAddr;
85 public:
86  CAddrDB();
87  bool Write(const CAddrMan& addr);
88  bool Read(CAddrMan& addr);
89  bool Read(CAddrMan& addr, CDataStream& ssPeers);
90 };
91 
93 class CBanDB
94 {
95 private:
96  boost::filesystem::path pathBanlist;
97 public:
98  CBanDB();
99  bool Write(const banmap_t& banSet);
100  bool Read(banmap_t& banSet);
101 };
102 
103 #endif // BITCOIN_ADDRDB_H
void SetNull()
Definition: addrdb.h:57
boost::filesystem::path pathAddr
Definition: addrdb.h:84
CBanDB()
Definition: addrdb.cpp:19
BanReason
Definition: addrdb.h:19
#define READWRITE(obj)
Definition: serialize.h:175
int nVersion
Definition: addrdb.h:30
CAddrDB()
Definition: addrdb.cpp:116
Definition: addrdb.h:81
bool Write(const banmap_t &banSet)
Definition: addrdb.cpp:24
ADD_SERIALIZE_METHODS
Definition: addrdb.h:46
std::map< CSubNet, CBanEntry > banmap_t
Definition: addrdb.h:78
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: addrdb.h:49
boost::filesystem::path pathBanlist
Definition: addrdb.h:96
bool Read(banmap_t &banSet)
Definition: addrdb.cpp:62
bool Read(CAddrMan &addr)
Definition: addrdb.cpp:159
static const int CURRENT_VERSION
Definition: addrdb.h:29
std::string banReasonToString()
Definition: addrdb.h:65
Definition: addrdb.h:93
CBanEntry(int64_t nCreateTimeIn)
Definition: addrdb.h:40
int64_t nCreateTime
Definition: addrdb.h:31
bool Write(const CAddrMan &addr)
Definition: addrdb.cpp:121
CBanEntry()
Definition: addrdb.h:35
uint8_t banReason
Definition: addrdb.h:33
int64_t nBanUntil
Definition: addrdb.h:32