2016-04-16 06:13:15 +02:00
|
|
|
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
2016-12-31 19:01:21 +01:00
|
|
|
// Copyright (c) 2009-2016 The Bitcoin Core developers
|
2016-04-16 06:13:15 +02: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-03-01 16:54:22 +01:00
|
|
|
#include "fs.h"
|
2016-04-16 06:13:15 +02:00
|
|
|
#include "serialize.h"
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <map>
|
|
|
|
|
|
|
|
class CSubNet;
|
|
|
|
class CAddrMan;
|
2016-04-16 20:47:18 +02:00
|
|
|
class CDataStream;
|
2016-04-16 06:13:15 +02:00
|
|
|
|
|
|
|
typedef enum BanReason
|
|
|
|
{
|
|
|
|
BanReasonUnknown = 0,
|
|
|
|
BanReasonNodeMisbehaving = 1,
|
|
|
|
BanReasonManuallyAdded = 2
|
|
|
|
} BanReason;
|
|
|
|
|
|
|
|
class CBanEntry
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static const int CURRENT_VERSION=1;
|
|
|
|
int nVersion;
|
|
|
|
int64_t nCreateTime;
|
|
|
|
int64_t nBanUntil;
|
|
|
|
uint8_t banReason;
|
|
|
|
|
|
|
|
CBanEntry()
|
|
|
|
{
|
|
|
|
SetNull();
|
|
|
|
}
|
|
|
|
|
2017-08-01 12:22:41 +02:00
|
|
|
explicit CBanEntry(int64_t nCreateTimeIn)
|
2016-04-16 06:13:15 +02:00
|
|
|
{
|
|
|
|
SetNull();
|
|
|
|
nCreateTime = nCreateTimeIn;
|
|
|
|
}
|
|
|
|
|
|
|
|
ADD_SERIALIZE_METHODS;
|
|
|
|
|
|
|
|
template <typename Stream, typename Operation>
|
2016-10-29 01:29:17 +02:00
|
|
|
inline void SerializationOp(Stream& s, Operation ser_action) {
|
2016-04-16 06:13:15 +02:00
|
|
|
READWRITE(this->nVersion);
|
|
|
|
READWRITE(nCreateTime);
|
|
|
|
READWRITE(nBanUntil);
|
|
|
|
READWRITE(banReason);
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetNull()
|
|
|
|
{
|
|
|
|
nVersion = CBanEntry::CURRENT_VERSION;
|
|
|
|
nCreateTime = 0;
|
|
|
|
nBanUntil = 0;
|
|
|
|
banReason = BanReasonUnknown;
|
|
|
|
}
|
|
|
|
|
2017-03-09 13:34:54 +01:00
|
|
|
std::string banReasonToString() const
|
2016-04-16 06:13:15 +02:00
|
|
|
{
|
|
|
|
switch (banReason) {
|
|
|
|
case BanReasonNodeMisbehaving:
|
|
|
|
return "node misbehaving";
|
|
|
|
case BanReasonManuallyAdded:
|
|
|
|
return "manually added";
|
|
|
|
default:
|
|
|
|
return "unknown";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef std::map<CSubNet, CBanEntry> banmap_t;
|
|
|
|
|
|
|
|
/** 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 06:13:15 +02:00
|
|
|
public:
|
|
|
|
CAddrDB();
|
|
|
|
bool Write(const CAddrMan& addr);
|
|
|
|
bool Read(CAddrMan& addr);
|
2017-04-21 13:50:55 +02:00
|
|
|
static bool Read(CAddrMan& addr, CDataStream& ssPeers);
|
2016-04-16 06:13:15 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/** Access to the banlist database (banlist.dat) */
|
|
|
|
class CBanDB
|
|
|
|
{
|
|
|
|
private:
|
2017-03-01 17:05:50 +01:00
|
|
|
fs::path pathBanlist;
|
2016-04-16 06:13:15 +02:00
|
|
|
public:
|
|
|
|
CBanDB();
|
|
|
|
bool Write(const banmap_t& banSet);
|
|
|
|
bool Read(banmap_t& banSet);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // BITCOIN_ADDRDB_H
|