Bitcoin ABC  0.24.7
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 <string>
14 #include <vector>
15 
16 class CAddress;
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() {
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 
79 void DumpAnchors(const CChainParams &chainParams,
80  const fs::path &anchors_db_path,
81  const std::vector<CAddress> &anchors);
82 
90 std::vector<CAddress> ReadAnchors(const CChainParams &chainParams,
91  const fs::path &anchors_db_path);
92 
93 #endif // BITCOIN_ADDRDB_H
CBanDB::Read
bool Read(banmap_t &banSet)
Definition: addrdb.cpp:132
CBanEntry::CURRENT_VERSION
static const int CURRENT_VERSION
Definition: addrdb.h:23
fs.h
CBanEntry::SetNull
void SetNull()
Definition: addrdb.h:41
CBanDB::Write
bool Write(const banmap_t &banSet)
Definition: addrdb.cpp:128
CBanEntry::CBanEntry
CBanEntry()
Definition: addrdb.h:28
CChainParams
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:47
CAddrDB::Write
bool Write(const CAddrMan &addr)
Definition: addrdb.cpp:141
CAddrDB
Access to the (IP) address database (peers.dat)
Definition: addrdb.h:49
net_types.h
CBanEntry::nVersion
int nVersion
Definition: addrdb.h:24
CBanEntry::nCreateTime
int64_t nCreateTime
Definition: addrdb.h:25
READWRITE
#define READWRITE(...)
Definition: serialize.h:179
CAddrDB::CAddrDB
CAddrDB(const CChainParams &chainParams)
Definition: addrdb.cpp:136
CBanDB::CBanDB
CBanDB(fs::path ban_list_path, const CChainParams &_chainParams)
Definition: addrdb.cpp:125
CBanDB
Access to the banlist database (banlist.dat)
Definition: addrdb.h:62
CBanEntry::SERIALIZE_METHODS
SERIALIZE_METHODS(CBanEntry, obj)
Definition: addrdb.h:35
CAddrMan
Stochastical (IP) address manager.
Definition: addrman.h:190
CAddress
A CService with information about it as peer.
Definition: protocol.h:421
CBanEntry
Definition: addrdb.h:21
CBanEntry::nBanUntil
int64_t nBanUntil
Definition: addrdb.h:26
CAddrDB::Read
bool Read(CAddrMan &addr)
Definition: addrdb.cpp:145
ReadAnchors
std::vector< CAddress > ReadAnchors(const CChainParams &chainParams, const fs::path &anchors_db_path)
Read the anchor IP address database (anchors.dat)
Definition: addrdb.cpp:167
serialize.h
CDataStream
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:197
CBanDB::m_ban_list_path
const fs::path m_ban_list_path
Definition: addrdb.h:64
banmap_t
std::map< CSubNet, CBanEntry > banmap_t
Definition: net_types.h:13
CBanDB::chainParams
const CChainParams & chainParams
Definition: addrdb.h:65
CBanEntry::CBanEntry
CBanEntry(int64_t nCreateTimeIn)
Definition: addrdb.h:30
CAddrDB::pathAddr
fs::path pathAddr
Definition: addrdb.h:51
DumpAnchors
void DumpAnchors(const CChainParams &chainParams, const fs::path &anchors_db_path, const std::vector< CAddress > &anchors)
Dump the anchor IP address database (anchors.dat)
Definition: addrdb.cpp:158
CAddrDB::chainParams
const CChainParams & chainParams
Definition: addrdb.h:52