Raven Core  3.0.0
P2P Digital Currency
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 // Copyright (c) 2017-2019 The Raven Core developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #ifndef RAVEN_ADDRDB_H
8 #define RAVEN_ADDRDB_H
9 
10 #include "fs.h"
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 
48 
49  template <typename Stream, typename Operation>
50  inline void SerializationOp(Stream& s, Operation ser_action) {
51  READWRITE(this->nVersion);
52  READWRITE(nCreateTime);
53  READWRITE(nBanUntil);
54  READWRITE(banReason);
55  }
56 
57  void SetNull()
58  {
59  nVersion = CBanEntry::CURRENT_VERSION;
60  nCreateTime = 0;
61  nBanUntil = 0;
62  banReason = BanReasonUnknown;
63  }
64 
65  std::string banReasonToString() const
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  fs::path pathAddr;
85 public:
86  CAddrDB();
87  bool Write(const CAddrMan& addr);
88  bool Read(CAddrMan& addr);
89  static bool Read(CAddrMan& addr, CDataStream& ssPeers);
90 };
91 
93 class CBanDB
94 {
95 private:
96  fs::path pathBanlist;
97 public:
98  CBanDB();
99  bool Write(const banmap_t& banSet);
100  bool Read(banmap_t& banSet);
101 };
102 
103 #endif // RAVEN_ADDRDB_H
void SetNull()
Definition: addrdb.h:57
Access to the (IP) address database (peers.dat)
Definition: addrdb.h:81
BanReason
Definition: addrdb.h:20
CBanEntry(int64_t nCreateTimeIn)
Definition: addrdb.h:41
#define READWRITE(obj)
Definition: serialize.h:163
void SerializationOp(Stream &s, Operation ser_action)
Definition: addrdb.h:50
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:147
int nVersion
Definition: addrdb.h:31
std::string banReasonToString() const
Definition: addrdb.h:65
int64_t nCreateTime
Definition: addrdb.h:32
CBanEntry()
Definition: addrdb.h:36
Stochastical (IP) address manager.
Definition: addrman.h:183
Access to the banlist database (banlist.dat)
Definition: addrdb.h:93
std::map< CSubNet, CBanEntry > banmap_t
Definition: addrdb.h:78
int64_t nBanUntil
Definition: addrdb.h:33
fs::path pathBanlist
Definition: addrdb.h:96
uint8_t banReason
Definition: addrdb.h:34
fs::path pathAddr
Definition: addrdb.h:84
ADD_SERIALIZE_METHODS
Definition: addrdb.h:47
static const int CURRENT_VERSION
Definition: addrdb.h:30
Definition: addrdb.h:27