LCOV - code coverage report
Current view: top level - src - addrdb.h (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 20 20 100.0 %
Date: 2020-09-26 01:30:44 Functions: 18 18 100.0 %

          Line data    Source code
       1             : // Copyright (c) 2009-2010 Satoshi Nakamoto
       2             : // Copyright (c) 2009-2019 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 <map>
      15             : 
      16             : class CSubNet;
      17             : class CAddrMan;
      18             : class CDataStream;
      19             : 
      20             : class CBanEntry
      21             : {
      22             : public:
      23             :     static const int CURRENT_VERSION=1;
      24             :     int nVersion;
      25             :     int64_t nCreateTime;
      26             :     int64_t nBanUntil;
      27             : 
      28          38 :     CBanEntry()
      29          19 :     {
      30          19 :         SetNull();
      31          38 :     }
      32             : 
      33          28 :     explicit CBanEntry(int64_t nCreateTimeIn)
      34          14 :     {
      35          14 :         SetNull();
      36          14 :         nCreateTime = nCreateTimeIn;
      37          28 :     }
      38             : 
      39         153 :     SERIALIZE_METHODS(CBanEntry, obj)
      40             :     {
      41          51 :         uint8_t ban_reason = 2; //! For backward compatibility
      42          51 :         READWRITE(obj.nVersion, obj.nCreateTime, obj.nBanUntil, ban_reason);
      43          51 :     }
      44             : 
      45          33 :     void SetNull()
      46             :     {
      47          33 :         nVersion = CBanEntry::CURRENT_VERSION;
      48          33 :         nCreateTime = 0;
      49          33 :         nBanUntil = 0;
      50          33 :     }
      51             : };
      52             : 
      53             : /** Access to the (IP) address database (peers.dat) */
      54        2582 : class CAddrDB
      55             : {
      56             : private:
      57             :     fs::path pathAddr;
      58             : public:
      59             :     CAddrDB();
      60             :     bool Write(const CAddrMan& addr);
      61             :     bool Read(CAddrMan& addr);
      62             :     static bool Read(CAddrMan& addr, CDataStream& ssPeers);
      63             : };
      64             : 
      65             : /** Access to the banlist database (banlist.dat) */
      66        1216 : class CBanDB
      67             : {
      68             : private:
      69             :     const fs::path m_ban_list_path;
      70             : public:
      71             :     explicit CBanDB(fs::path ban_list_path);
      72             :     bool Write(const banmap_t& banSet);
      73             :     bool Read(banmap_t& banSet);
      74             : };
      75             : 
      76             : #endif // BITCOIN_ADDRDB_H

Generated by: LCOV version 1.15