2016-04-16 00:13:15 -04:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
2019-12-30 22:39:22 +13:00
|
|
|
// Copyright (c) 2009-2019 The Bitcoin Core developers
|
2016-04-16 00:13:15 -04:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#ifndef BITCOIN_ADDRDB_H
|
|
|
|
#define BITCOIN_ADDRDB_H
|
|
|
|
|
2017-11-10 13:57:53 +13:00
|
|
|
#include <fs.h>
|
2019-10-29 10:49:48 +02:00
|
|
|
#include <net_types.h> // For banmap_t
|
2017-11-10 13:57:53 +13:00
|
|
|
#include <serialize.h>
|
2016-04-16 00:13:15 -04:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
class CSubNet;
|
|
|
|
class CAddrMan;
|
2016-04-16 14:47:18 -04:00
|
|
|
class CDataStream;
|
2016-04-16 00:13:15 -04:00
|
|
|
|
|
|
|
class CBanEntry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static const int CURRENT_VERSION=1;
|
|
|
|
int nVersion;
|
|
|
|
int64_t nCreateTime;
|
|
|
|
int64_t nBanUntil;
|
|
|
|
|
|
|
|
CBanEntry()
|
|
|
|
{
|
|
|
|
SetNull();
|
|
|
|
}
|
|
|
|
|
2017-08-01 12:22:41 +02:00
|
|
|
explicit CBanEntry(int64_t nCreateTimeIn)
|
2016-04-16 00:13:15 -04:00
|
|
|
{
|
|
|
|
SetNull();
|
|
|
|
nCreateTime = nCreateTimeIn;
|
|
|
|
}
|
|
|
|
|
2020-06-10 17:11:38 -07:00
|
|
|
SERIALIZE_METHODS(CBanEntry, obj)
|
2019-01-03 21:26:10 +08:00
|
|
|
{
|
2020-06-10 17:11:38 -07:00
|
|
|
uint8_t ban_reason = 2; //! For backward compatibility
|
|
|
|
READWRITE(obj.nVersion, obj.nCreateTime, obj.nBanUntil, ban_reason);
|
2019-01-03 21:26:10 +08:00
|
|
|
}
|
|
|
|
|
2016-04-16 00:13:15 -04:00
|
|
|
void SetNull()
|
|
|
|
{
|
|
|
|
nVersion = CBanEntry::CURRENT_VERSION;
|
|
|
|
nCreateTime = 0;
|
|
|
|
nBanUntil = 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Access to the (IP) address database (peers.dat) */
|
|
|
|
class CAddrDB
|
|
|
|
{
|
|
|
|
private:
|
2017-03-01 17:05:50 +01:00
|
|
|
fs::path pathAddr;
|
2016-04-16 00:13:15 -04:00
|
|
|
public:
|
|
|
|
CAddrDB();
|
|
|
|
bool Write(const CAddrMan& addr);
|
|
|
|
bool Read(CAddrMan& addr);
|
2017-04-21 04:50:55 -07:00
|
|
|
static bool Read(CAddrMan& addr, CDataStream& ssPeers);
|
2016-04-16 00:13:15 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Access to the banlist database (banlist.dat) */
|
|
|
|
class CBanDB
|
|
|
|
{
|
|
|
|
private:
|
2017-10-05 13:35:20 -04:00
|
|
|
const fs::path m_ban_list_path;
|
2016-04-16 00:13:15 -04:00
|
|
|
public:
|
2017-10-05 13:35:20 -04:00
|
|
|
explicit CBanDB(fs::path ban_list_path);
|
2016-04-16 00:13:15 -04:00
|
|
|
bool Write(const banmap_t& banSet);
|
|
|
|
bool Read(banmap_t& banSet);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // BITCOIN_ADDRDB_H
|