Skip to content

Commit 3804c29

Browse files
theuniFuzzbawls
authored andcommitted
net: move whitelist functions into CConnman
1 parent dbde9be commit 3804c29

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1333,7 +1333,7 @@ bool AppInit2()
13331333
LookupSubNet(net.c_str(), subnet);
13341334
if (!subnet.IsValid())
13351335
return UIError(strprintf(_("Invalid netmask specified in -whitelist: '%s'"), net));
1336-
CNode::AddWhitelistedRange(subnet);
1336+
connman.AddWhitelistedRange(subnet);
13371337
}
13381338
}
13391339

src/net.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -665,10 +665,7 @@ void CConnman::SetBannedSetDirty(bool dirty)
665665
}
666666

667667

668-
std::vector<CSubNet> CNode::vWhitelistedRange;
669-
RecursiveMutex CNode::cs_vWhitelistedRange;
670-
671-
bool CNode::IsWhitelistedRange(const CNetAddr& addr)
668+
bool CConnman::IsWhitelistedRange(const CNetAddr& addr)
672669
{
673670
LOCK(cs_vWhitelistedRange);
674671
for (const CSubNet& subnet : vWhitelistedRange) {
@@ -678,7 +675,7 @@ bool CNode::IsWhitelistedRange(const CNetAddr& addr)
678675
return false;
679676
}
680677

681-
void CNode::AddWhitelistedRange(const CSubNet& subnet)
678+
void CConnman::AddWhitelistedRange(const CSubNet& subnet)
682679
{
683680
LOCK(cs_vWhitelistedRange);
684681
vWhitelistedRange.push_back(subnet);
@@ -1012,7 +1009,7 @@ void CConnman::AcceptConnection(const ListenSocket& hListenSocket) {
10121009
if (!addr.SetSockAddr((const struct sockaddr*)&sockaddr))
10131010
LogPrintf("Warning: Unknown socket family\n");
10141011

1015-
bool whitelisted = hListenSocket.whitelisted || CNode::IsWhitelistedRange(addr);
1012+
bool whitelisted = hListenSocket.whitelisted || IsWhitelistedRange(addr);
10161013
{
10171014
LOCK(cs_vNodes);
10181015
for (CNode* pnode : vNodes)

src/net.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ class CConnman
179179
bool DisconnectNode(NodeId id);
180180
bool DisconnectSubnet(const CSubNet& subnet);
181181

182+
void AddWhitelistedRange(const CSubNet& subnet);
182183
private:
183184
struct ListenSocket {
184185
SOCKET socket;
@@ -202,6 +203,8 @@ class CConnman
202203

203204
bool AttemptToEvictConnection(bool fPreferNewConnection);
204205
CNode* ConnectNode(CAddress addrConnect, const char* pszDest, bool fCountFailure);
206+
bool IsWhitelistedRange(const CNetAddr &addr);
207+
205208
void DeleteNode(CNode* pnode);
206209
//!check is the banlist has unwritten changes
207210
bool BannedSetIsDirty();
@@ -213,6 +216,11 @@ class CConnman
213216
void DumpData();
214217
void DumpBanlist();
215218

219+
// Whitelisted ranges. Any node connecting from these is automatically
220+
// whitelisted (as well as those connecting to whitelisted binds).
221+
std::vector<CSubNet> vWhitelistedRange;
222+
RecursiveMutex cs_vWhitelistedRange;
223+
216224
std::vector<ListenSocket> vhListenSocket;
217225
banmap_t setBanned;
218226
RecursiveMutex cs_setBanned;
@@ -440,11 +448,6 @@ class CNode
440448
protected:
441449
std::vector<std::string> vecRequestsFulfilled; //keep track of what client has asked for
442450

443-
// Whitelisted ranges. Any node connecting from these is automatically
444-
// whitelisted (as well as those connecting to whitelisted binds).
445-
static std::vector<CSubNet> vWhitelistedRange;
446-
static RecursiveMutex cs_vWhitelistedRange;
447-
448451
// Basic fuzz-testing
449452
void Fuzz(int nChance); // modifies ssSend
450453

@@ -792,9 +795,6 @@ class CNode
792795

793796
void copyStats(CNodeStats& stats);
794797

795-
static bool IsWhitelistedRange(const CNetAddr& ip);
796-
static void AddWhitelistedRange(const CSubNet& subnet);
797-
798798
// Network stats
799799
static void RecordBytesRecv(uint64_t bytes);
800800
static void RecordBytesSent(uint64_t bytes);

0 commit comments

Comments
 (0)