Changeset View
Changeset View
Standalone View
Standalone View
src/addrdb.h
Show All 11 Lines | |||||
#include <map> | #include <map> | ||||
#include <string> | #include <string> | ||||
class CSubNet; | class CSubNet; | ||||
class CAddrMan; | class CAddrMan; | ||||
class CDataStream; | class CDataStream; | ||||
class CChainParams; | class CChainParams; | ||||
typedef enum BanReason { | |||||
BanReasonUnknown = 0, | |||||
BanReasonNodeMisbehaving = 1, | |||||
BanReasonManuallyAdded = 2 | |||||
} BanReason; | |||||
class CBanEntry { | class CBanEntry { | ||||
public: | public: | ||||
static const int CURRENT_VERSION = 1; | static const int CURRENT_VERSION = 1; | ||||
int nVersion; | int nVersion; | ||||
int64_t nCreateTime; | int64_t nCreateTime; | ||||
int64_t nBanUntil; | int64_t nBanUntil; | ||||
uint8_t banReason; | |||||
CBanEntry() { SetNull(); } | CBanEntry() { SetNull(); } | ||||
explicit CBanEntry(int64_t nCreateTimeIn) { | explicit CBanEntry(int64_t nCreateTimeIn) { | ||||
SetNull(); | SetNull(); | ||||
nCreateTime = nCreateTimeIn; | nCreateTime = nCreateTimeIn; | ||||
} | } | ||||
explicit CBanEntry(int64_t n_create_time_in, BanReason ban_reason_in) | |||||
: CBanEntry(n_create_time_in) { | |||||
banReason = ban_reason_in; | |||||
} | |||||
ADD_SERIALIZE_METHODS; | ADD_SERIALIZE_METHODS; | ||||
template <typename Stream, typename Operation> | template <typename Stream, typename Operation> | ||||
inline void SerializationOp(Stream &s, Operation ser_action) { | inline void SerializationOp(Stream &s, Operation ser_action) { | ||||
//! For backward compatibility | |||||
uint8_t ban_reason = 2; | |||||
READWRITE(this->nVersion); | READWRITE(this->nVersion); | ||||
READWRITE(nCreateTime); | READWRITE(nCreateTime); | ||||
READWRITE(nBanUntil); | READWRITE(nBanUntil); | ||||
READWRITE(banReason); | READWRITE(ban_reason); | ||||
} | } | ||||
void SetNull() { | void SetNull() { | ||||
nVersion = CBanEntry::CURRENT_VERSION; | nVersion = CBanEntry::CURRENT_VERSION; | ||||
nCreateTime = 0; | nCreateTime = 0; | ||||
nBanUntil = 0; | nBanUntil = 0; | ||||
banReason = BanReasonUnknown; | |||||
} | |||||
std::string banReasonToString() const { | |||||
switch (banReason) { | |||||
case BanReasonNodeMisbehaving: | |||||
return "node misbehaving"; | |||||
case BanReasonManuallyAdded: | |||||
return "manually added"; | |||||
default: | |||||
return "unknown"; | |||||
} | |||||
} | } | ||||
}; | }; | ||||
typedef std::map<CSubNet, CBanEntry> banmap_t; | typedef std::map<CSubNet, CBanEntry> banmap_t; | ||||
/** Access to the (IP) address database (peers.dat) */ | /** Access to the (IP) address database (peers.dat) */ | ||||
class CAddrDB { | class CAddrDB { | ||||
private: | private: | ||||
Show All 23 Lines |