Browse Source

net: move whitelist functions into CConnman

0.14
Cory Fields 9 years ago
parent
commit
6c19d92361
  1. 2
      src/init.cpp
  2. 9
      src/net.cpp
  3. 16
      src/net.h

2
src/init.cpp

@ -1146,7 +1146,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) @@ -1146,7 +1146,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler)
LookupSubNet(net.c_str(), subnet);
if (!subnet.IsValid())
return InitError(strprintf(_("Invalid netmask specified in -whitelist: '%s'"), net));
CNode::AddWhitelistedRange(subnet);
connman.AddWhitelistedRange(subnet);
}
}

9
src/net.cpp

@ -625,10 +625,7 @@ void CConnman::SetBannedSetDirty(bool dirty) @@ -625,10 +625,7 @@ void CConnman::SetBannedSetDirty(bool dirty)
}
std::vector<CSubNet> CNode::vWhitelistedRange;
CCriticalSection CNode::cs_vWhitelistedRange;
bool CNode::IsWhitelistedRange(const CNetAddr &addr) {
bool CConnman::IsWhitelistedRange(const CNetAddr &addr) {
LOCK(cs_vWhitelistedRange);
BOOST_FOREACH(const CSubNet& subnet, vWhitelistedRange) {
if (subnet.Match(addr))
@ -637,7 +634,7 @@ bool CNode::IsWhitelistedRange(const CNetAddr &addr) { @@ -637,7 +634,7 @@ bool CNode::IsWhitelistedRange(const CNetAddr &addr) {
return false;
}
void CNode::AddWhitelistedRange(const CSubNet &subnet) {
void CConnman::AddWhitelistedRange(const CSubNet &subnet) {
LOCK(cs_vWhitelistedRange);
vWhitelistedRange.push_back(subnet);
}
@ -992,7 +989,7 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) { @@ -992,7 +989,7 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
if (!addr.SetSockAddr((const struct sockaddr*)&sockaddr))
LogPrintf("Warning: Unknown socket family\n");
bool whitelisted = hListenSocket.whitelisted || CNode::IsWhitelistedRange(addr);
bool whitelisted = hListenSocket.whitelisted || IsWhitelistedRange(addr);
{
LOCK(cs_vNodes);
BOOST_FOREACH(CNode* pnode, vNodes)

16
src/net.h

@ -169,6 +169,7 @@ public: @@ -169,6 +169,7 @@ public:
bool DisconnectNode(NodeId id);
bool DisconnectSubnet(const CSubNet& subnet);
void AddWhitelistedRange(const CSubNet &subnet);
private:
struct ListenSocket {
SOCKET socket;
@ -192,6 +193,8 @@ private: @@ -192,6 +193,8 @@ private:
bool AttemptToEvictConnection();
CNode* ConnectNode(CAddress addrConnect, const char *pszDest, bool fCountFailure);
bool IsWhitelistedRange(const CNetAddr &addr);
void DeleteNode(CNode* pnode);
//!check is the banlist has unwritten changes
bool BannedSetIsDirty();
@ -203,6 +206,11 @@ private: @@ -203,6 +206,11 @@ private:
void DumpData();
void DumpBanlist();
// Whitelisted ranges. Any node connecting from these is automatically
// whitelisted (as well as those connecting to whitelisted binds).
std::vector<CSubNet> vWhitelistedRange;
CCriticalSection cs_vWhitelistedRange;
std::vector<ListenSocket> vhListenSocket;
banmap_t setBanned;
CCriticalSection cs_setBanned;
@ -432,11 +440,6 @@ public: @@ -432,11 +440,6 @@ public:
const uint64_t nKeyedNetGroup;
protected:
// Whitelisted ranges. Any node connecting from these is automatically
// whitelisted (as well as those connecting to whitelisted binds).
static std::vector<CSubNet> vWhitelistedRange;
static CCriticalSection cs_vWhitelistedRange;
mapMsgCmdSize mapSendBytesPerMsgCmd;
mapMsgCmdSize mapRecvBytesPerMsgCmd;
@ -803,9 +806,6 @@ public: @@ -803,9 +806,6 @@ public:
void copyStats(CNodeStats &stats);
static bool IsWhitelistedRange(const CNetAddr &ip);
static void AddWhitelistedRange(const CSubNet &subnet);
// Network stats
static void RecordBytesRecv(uint64_t bytes);
static void RecordBytesSent(uint64_t bytes);

Loading…
Cancel
Save