Remove redundant nullptr checks before deallocation
[bitcoinplatinum.git] / src / addrdb.h
blob6cb36dfac4e60ee8512f8dfdac28101aa6ecc48c
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 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.
6 #ifndef BITCOIN_ADDRDB_H
7 #define BITCOIN_ADDRDB_H
9 #include "fs.h"
10 #include "serialize.h"
12 #include <string>
13 #include <map>
15 class CSubNet;
16 class CAddrMan;
17 class CDataStream;
19 typedef enum BanReason
21 BanReasonUnknown = 0,
22 BanReasonNodeMisbehaving = 1,
23 BanReasonManuallyAdded = 2
24 } BanReason;
26 class CBanEntry
28 public:
29 static const int CURRENT_VERSION=1;
30 int nVersion;
31 int64_t nCreateTime;
32 int64_t nBanUntil;
33 uint8_t banReason;
35 CBanEntry()
37 SetNull();
40 CBanEntry(int64_t nCreateTimeIn)
42 SetNull();
43 nCreateTime = nCreateTimeIn;
46 ADD_SERIALIZE_METHODS;
48 template <typename Stream, typename Operation>
49 inline void SerializationOp(Stream& s, Operation ser_action) {
50 READWRITE(this->nVersion);
51 READWRITE(nCreateTime);
52 READWRITE(nBanUntil);
53 READWRITE(banReason);
56 void SetNull()
58 nVersion = CBanEntry::CURRENT_VERSION;
59 nCreateTime = 0;
60 nBanUntil = 0;
61 banReason = BanReasonUnknown;
64 std::string banReasonToString()
66 switch (banReason) {
67 case BanReasonNodeMisbehaving:
68 return "node misbehaving";
69 case BanReasonManuallyAdded:
70 return "manually added";
71 default:
72 return "unknown";
77 typedef std::map<CSubNet, CBanEntry> banmap_t;
79 /** Access to the (IP) address database (peers.dat) */
80 class CAddrDB
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);
91 /** Access to the banlist database (banlist.dat) */
92 class CBanDB
94 private:
95 fs::path pathBanlist;
96 public:
97 CBanDB();
98 bool Write(const banmap_t& banSet);
99 bool Read(banmap_t& banSet);
102 #endif // BITCOIN_ADDRDB_H