Bitcoin ABC  0.22.12
P2P Digital Currency
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 // 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 <map>
14 #include <string>
15 
16 class CSubNet;
17 class CAddrMan;
18 class CDataStream;
19 class CChainParams;
20 
21 class CBanEntry {
22 public:
23  static const int CURRENT_VERSION = 1;
24  int nVersion;
25  int64_t nCreateTime;
26  int64_t nBanUntil;
27 
28  CBanEntry() { SetNull(); }
29 
30  explicit CBanEntry(int64_t nCreateTimeIn) {
31  SetNull();
32  nCreateTime = nCreateTimeIn;
33  }
34 
37  uint8_t ban_reason = 2;
38  READWRITE(obj.nVersion, obj.nCreateTime, obj.nBanUntil, ban_reason);
39  }
40 
41  void SetNull() {
42  nVersion = CBanEntry::CURRENT_VERSION;
43  nCreateTime = 0;
44  nBanUntil = 0;
45  }
46 };
47 
49 class CAddrDB {
50 private:
51  fs::path pathAddr;
53 
54 public:
55  explicit CAddrDB(const CChainParams &chainParams);
56  bool Write(const CAddrMan &addr);
57  bool Read(CAddrMan &addr);
58  bool Read(CAddrMan &addr, CDataStream &ssPeers);
59 };
60 
62 class CBanDB {
63 private:
64  const fs::path m_ban_list_path;
66 
67 public:
68  CBanDB(fs::path ban_list_path, const CChainParams &_chainParams);
69  bool Write(const banmap_t &banSet);
70  bool Read(banmap_t &banSet);
71 };
72 
73 #endif // BITCOIN_ADDRDB_H
void SetNull()
Definition: addrdb.h:41
Access to the (IP) address database (peers.dat)
Definition: addrdb.h:49
CBanEntry(int64_t nCreateTimeIn)
Definition: addrdb.h:30
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system...
Definition: chainparams.h:47
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:196
const fs::path m_ban_list_path
Definition: addrdb.h:64
int nVersion
Definition: addrdb.h:24
int64_t nCreateTime
Definition: addrdb.h:25
CBanEntry()
Definition: addrdb.h:28
Stochastical (IP) address manager.
Definition: addrman.h:193
Access to the banlist database (banlist.dat)
Definition: addrdb.h:62
const CChainParams & chainParams
Definition: addrdb.h:65
int64_t nBanUntil
Definition: addrdb.h:26
fs::path pathAddr
Definition: addrdb.h:51
SERIALIZE_METHODS(CBanEntry, obj)
Definition: addrdb.h:35
std::map< CSubNet, CBanEntry > banmap_t
Definition: net_types.h:13
static const int CURRENT_VERSION
Definition: addrdb.h:23
Definition: addrdb.h:21
#define READWRITE(...)
Definition: serialize.h:191
const CChainParams & chainParams
Definition: addrdb.h:52