diff options
author | Jonas Schnelli <jonas.schnelli@include7.ch> | 2015-06-26 21:38:33 +0200 |
---|---|---|
committer | Jonas Schnelli <jonas.schnelli@include7.ch> | 2015-07-02 20:29:36 +0200 |
commit | 409bccfbf52b531b2a9d60ac2308f56223931a2e (patch) | |
tree | fb1f19b73ccad0f597fcd1dc3dc240843a728ccd /src/net.h | |
parent | dfa174c2957f2600f05bf0ee9dd17fe18fb54fd7 (diff) |
use CBanEntry as object container for banned nodes
- added a reason enum for a ban
- added creation time for a ban
Using CBanEntry as container will keep banlist.dat extenable.
Diffstat (limited to 'src/net.h')
-rw-r--r-- | src/net.h | 72 |
1 files changed, 65 insertions, 7 deletions
@@ -228,8 +228,66 @@ public: }; +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(); + } + + CBanEntry(int64_t nCreateTimeIn) + { + SetNull(); + nCreateTime = nCreateTimeIn; + } + ADD_SERIALIZE_METHODS; + + template <typename Stream, typename Operation> + inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) { + READWRITE(this->nVersion); + nVersion = this->nVersion; + READWRITE(nCreateTime); + READWRITE(nBanUntil); + READWRITE(banReason); + } + + void SetNull() + { + nVersion = CBanEntry::CURRENT_VERSION; + nCreateTime = 0; + nBanUntil = 0; + banReason = BanReasonUnknown; + } + + std::string banReasonToString() + { + switch (banReason) { + case BanReasonNodeMisbehaving: + return "node misbehabing"; + case BanReasonManuallyAdded: + return "manually added"; + default: + return "unknown"; + } + } +}; +typedef std::map<CSubNet, CBanEntry> banmap_t; /** Information about a peer */ class CNode @@ -285,7 +343,7 @@ protected: // Denial-of-service detection/prevention // Key is IP address, value is banned-until-time - static std::map<CSubNet, int64_t> setBanned; + static banmap_t setBanned; static CCriticalSection cs_setBanned; static bool setBannedIsDirty; @@ -609,12 +667,12 @@ public: static void ClearBanned(); // needed for unit testing static bool IsBanned(CNetAddr ip); static bool IsBanned(CSubNet subnet); - static void Ban(const CNetAddr &ip, int64_t bantimeoffset = 0, bool sinceUnixEpoch = false); - static void Ban(const CSubNet &subNet, int64_t bantimeoffset = 0, bool sinceUnixEpoch = false); + static void Ban(const CNetAddr &ip, const BanReason &banReason, int64_t bantimeoffset = 0, bool sinceUnixEpoch = false); + static void Ban(const CSubNet &subNet, const BanReason &banReason, int64_t bantimeoffset = 0, bool sinceUnixEpoch = false); static bool Unban(const CNetAddr &ip); static bool Unban(const CSubNet &ip); - static void GetBanned(std::map<CSubNet, int64_t> &banmap); - static void SetBanned(const std::map<CSubNet, int64_t> &banmap); + static void GetBanned(banmap_t &banmap); + static void SetBanned(const banmap_t &banmap); //!check is the banlist has unwritten changes static bool BannedSetIsDirty(); @@ -660,8 +718,8 @@ private: boost::filesystem::path pathBanlist; public: CBanDB(); - bool Write(const std::map<CSubNet, int64_t>& banSet); - bool Read(std::map<CSubNet, int64_t>& banSet); + bool Write(const banmap_t& banSet); + bool Read(banmap_t& banSet); }; void DumpBanlist(); |