mirror of
https://github.com/dashpay/dash.git
synced 2024-12-28 13:32:47 +01:00
38ee2a7a94
18185b57c32d0a43afeca4c125b9352c692923e9 scripted-diff: batch-recase BanMan variables (Carl Dong) c2e04d37f3841d109c1fe60693f9622e2836cc29 banman: Add, use CBanEntry ctor that takes ban reason (Carl Dong) 1ffa4ce27d4ea6c1067d8984455df97994c7713e banman: reformulate nBanUtil calculation (Carl Dong) daae598feb034f2f56e0b00ecfb4854d693d3641 banman: add thread annotations and mark members const where possible (Cory Fields) 84fc3fbd0304a7d6e660bf783c84bed2dd415141 scripted-diff: batch-rename BanMan members (Cory Fields) af3503d903b1a608cd212e2d74b274103199078c net: move BanMan to its own files (Cory Fields) d0469b2e9386a7a4b268cb9725347e7517acace6 banman: pass in default ban time as a parameter (Cory Fields) 2e56702ecedd83c4b7cb8de9de5c437c8c08e645 banman: pass the banfile path in (Cory Fields) 4c0d961eb0d7825a1e6f8389d7f5545114ee18c6 banman: create and split out banman (Cory Fields) 83c1ea2e5e66b8a83072e3d5ad6a4ced406eb1ba net: split up addresses/ban dumps in preparation for moving them (Cory Fields) 136bd7926c72659dd277a7b795ea17f72e523338 tests: remove member connman/peerLogic in TestingSetup (Cory Fields) 7cc2b9f6786f9bc33853220551eed33ca6b7b7b2 net: Break disconnecting out of Ban() (Cory Fields) Pull request description: **Old English à la Beowulf** ``` Banman wæs bréme --blaéd wíde sprang-- Connmanes eafera Coreum in. aéglaéca léodum forstandan Swá bealdode bearn Connmanes guma gúðum cúð gódum daédum· dréah æfter dóme· nealles druncne slóg ``` **Modern English Translation** ``` Banman was famed --his renown spread wide-- Conman's hier, in Core-land. against the evil creature defend the people Thus he was bold, the son of Connman man famed in war, for good deeds; he led his life for glory, never, having drunk, slew ``` -- With @theuni's blessing, here is Banman, rebased. Original PR: https://github.com/bitcoin/bitcoin/pull/11457 -- Followup PRs: 1. Give `CNode` a `Disconnect` method ([source](https://github.com/bitcoin/bitcoin/pull/14605#discussion_r248065847)) 2. Add a comment to `std::atomic_bool fDisconnect` in `net.h` that setting this to true will cause the node to be disconnected the next time `DisconnectNodes()` runs ([source](https://github.com/bitcoin/bitcoin/pull/14605#discussion_r248384309)) Tree-SHA512: 9c207edbf577415c22c9811113e393322d936a843d4ff265186728152a67c057779ac4d4f27b895de9729f7a53e870f828b9ebc8bcdab757520c2aebe1e9be35
100 lines
2.1 KiB
C++
100 lines
2.1 KiB
C++
// Copyright (c) 2009-2010 Satoshi Nakamoto
|
|
// Copyright (c) 2009-2015 The Bitcoin Core developers
|
|
// 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
|
|
|
|
#include <fs.h>
|
|
#include <serialize.h>
|
|
|
|
#include <string>
|
|
#include <map>
|
|
|
|
class CSubNet;
|
|
class CAddrMan;
|
|
class CDataStream;
|
|
|
|
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();
|
|
}
|
|
|
|
explicit CBanEntry(int64_t nCreateTimeIn)
|
|
{
|
|
SetNull();
|
|
nCreateTime = nCreateTimeIn;
|
|
}
|
|
|
|
explicit CBanEntry(int64_t n_create_time_in, BanReason ban_reason_in) : CBanEntry(n_create_time_in)
|
|
{
|
|
banReason = ban_reason_in;
|
|
}
|
|
|
|
SERIALIZE_METHODS(CBanEntry, obj) { READWRITE(obj.nVersion, obj.nCreateTime, obj.nBanUntil, obj.banReason); }
|
|
|
|
void SetNull()
|
|
{
|
|
nVersion = CBanEntry::CURRENT_VERSION;
|
|
nCreateTime = 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;
|
|
|
|
/** Access to the (IP) address database (peers.dat) */
|
|
class CAddrDB
|
|
{
|
|
private:
|
|
fs::path pathAddr;
|
|
public:
|
|
CAddrDB();
|
|
bool Write(const CAddrMan& addr);
|
|
bool Read(CAddrMan& addr);
|
|
static bool Read(CAddrMan& addr, CDataStream& ssPeers);
|
|
};
|
|
|
|
/** Access to the banlist database (banlist.dat) */
|
|
class CBanDB
|
|
{
|
|
private:
|
|
const fs::path m_ban_list_path;
|
|
public:
|
|
explicit CBanDB(fs::path ban_list_path);
|
|
bool Write(const banmap_t& banSet);
|
|
bool Read(banmap_t& banSet);
|
|
};
|
|
|
|
#endif // BITCOIN_ADDRDB_H
|