aboutsummaryrefslogtreecommitdiff
path: root/src/net.h
diff options
context:
space:
mode:
authorCory Fields <cory-nospam-@coryfields.com>2016-04-16 17:43:11 -0400
committerCory Fields <cory-nospam-@coryfields.com>2016-09-08 12:12:57 -0400
commita0f3d3cdad630103d919a4ec802c413b87fa1f1a (patch)
treeb02339d74322cb6e6243a4b1bba743a374f4f439 /src/net.h
parentaaf018e3b79417ecfd39291a8c100df77969d77a (diff)
downloadbitcoin-a0f3d3cdad630103d919a4ec802c413b87fa1f1a.tar.xz
net: move ban and addrman functions into CConnman
Diffstat (limited to 'src/net.h')
-rw-r--r--src/net.h89
1 files changed, 49 insertions, 40 deletions
diff --git a/src/net.h b/src/net.h
index b9dfaa0f40..65dafb4fd9 100644
--- a/src/net.h
+++ b/src/net.h
@@ -7,6 +7,7 @@
#define BITCOIN_NET_H
#include "addrdb.h"
+#include "addrman.h"
#include "amount.h"
#include "bloom.h"
#include "compat.h"
@@ -87,7 +88,6 @@ unsigned int SendBufferSize();
typedef int NodeId;
void AddOneShot(const std::string& strDest);
-void AddressCurrentlyConnected(const CService& addr);
CNode* FindNode(const CNetAddr& ip);
CNode* FindNode(const CSubNet& subNet);
CNode* FindNode(const std::string& addrName);
@@ -99,11 +99,44 @@ class CConnman
public:
CConnman();
~CConnman();
- bool Start(boost::thread_group& threadGroup, std::string& strNodeError);
+ bool Start(boost::thread_group& threadGroup, CScheduler& scheduler, std::string& strNodeError);
void Stop();
bool BindListenPort(const CService &bindAddr, std::string& strError, bool fWhitelisted = false);
bool OpenNetworkConnection(const CAddress& addrConnect, bool fCountFailure, CSemaphoreGrant *grantOutbound = NULL, const char *strDest = NULL, bool fOneShot = false, bool fFeeler = false);
+ // Addrman functions
+ size_t GetAddressCount() const;
+ void SetServices(const CService &addr, ServiceFlags nServices);
+ void MarkAddressGood(const CAddress& addr);
+ void AddNewAddress(const CAddress& addr, const CAddress& addrFrom, int64_t nTimePenalty = 0);
+ void AddNewAddresses(const std::vector<CAddress>& vAddr, const CAddress& addrFrom, int64_t nTimePenalty = 0);
+ std::vector<CAddress> GetAddresses();
+ void AddressCurrentlyConnected(const CService& addr);
+
+ // Denial-of-service detection/prevention
+ // The idea is to detect peers that are behaving
+ // badly and disconnect/ban them, but do it in a
+ // one-coding-mistake-won't-shatter-the-entire-network
+ // way.
+ // IMPORTANT: There should be nothing I can give a
+ // node that it will forward on that will make that
+ // node's peers drop it. If there is, an attacker
+ // can isolate a node and/or try to split the network.
+ // Dropping a node for sending stuff that is invalid
+ // now but might be valid in a later version is also
+ // dangerous, because it can cause a network split
+ // between nodes running old code and nodes running
+ // new code.
+ void Ban(const CNetAddr& netAddr, const BanReason& reason, int64_t bantimeoffset = 0, bool sinceUnixEpoch = false);
+ void Ban(const CSubNet& subNet, const BanReason& reason, int64_t bantimeoffset = 0, bool sinceUnixEpoch = false);
+ void ClearBanned(); // needed for unit testing
+ bool IsBanned(CNetAddr ip);
+ bool IsBanned(CSubNet subnet);
+ bool Unban(const CNetAddr &ip);
+ bool Unban(const CSubNet &ip);
+ void GetBanned(banmap_t &banmap);
+ void SetBanned(const banmap_t &banmap);
+
private:
struct ListenSocket {
SOCKET socket;
@@ -122,8 +155,22 @@ private:
CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure);
void DeleteNode(CNode* pnode);
+ //!check is the banlist has unwritten changes
+ bool BannedSetIsDirty();
+ //!set the "dirty" flag for the banlist
+ void SetBannedSetDirty(bool dirty=true);
+ //!clean unused entries (if bantime has expired)
+ void SweepBanned();
+ void DumpAddresses();
+ void DumpData();
+ void DumpBanlist();
std::vector<ListenSocket> vhListenSocket;
+ banmap_t setBanned;
+ CCriticalSection cs_setBanned;
+ bool setBannedIsDirty;
+ bool fAddressesInitialized;
+ CAddrMan addrman;
};
extern std::unique_ptr<CConnman> g_connman;
void MapPort(bool fUseUPnP);
@@ -195,7 +242,6 @@ extern ServiceFlags nLocalServices;
extern ServiceFlags nRelevantServices;
extern bool fRelayTxes;
extern uint64_t nLocalHostNonce;
-extern CAddrMan addrman;
/** Maximum number of connections to simultaneously allow (aka connection slots) */
extern int nMaxConnections;
@@ -347,12 +393,6 @@ public:
const uint64_t nKeyedNetGroup;
protected:
- // Denial-of-service detection/prevention
- // Key is IP address, value is banned-until-time
- static banmap_t setBanned;
- static CCriticalSection cs_setBanned;
- static bool setBannedIsDirty;
-
// Whitelisted ranges. Any node connecting from these is automatically
// whitelisted (as well as those connecting to whitelisted binds).
static std::vector<CSubNet> vWhitelistedRange;
@@ -722,37 +762,6 @@ public:
void CloseSocketDisconnect();
- // Denial-of-service detection/prevention
- // The idea is to detect peers that are behaving
- // badly and disconnect/ban them, but do it in a
- // one-coding-mistake-won't-shatter-the-entire-network
- // way.
- // IMPORTANT: There should be nothing I can give a
- // node that it will forward on that will make that
- // node's peers drop it. If there is, an attacker
- // can isolate a node and/or try to split the network.
- // Dropping a node for sending stuff that is invalid
- // now but might be valid in a later version is also
- // dangerous, because it can cause a network split
- // between nodes running old code and nodes running
- // new code.
- static void ClearBanned(); // needed for unit testing
- static bool IsBanned(CNetAddr ip);
- static bool IsBanned(CSubNet subnet);
- 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(banmap_t &banmap);
- static void SetBanned(const banmap_t &banmap);
-
- //!check is the banlist has unwritten changes
- static bool BannedSetIsDirty();
- //!set the "dirty" flag for the banlist
- static void SetBannedSetDirty(bool dirty=true);
- //!clean unused entries (if bantime has expired)
- static void SweepBanned();
-
void copyStats(CNodeStats &stats);
static bool IsWhitelistedRange(const CNetAddr &ip);