Skip to content

Commit ce79f32

Browse files
author
Marko Bencun
committed
add WhitelistedRange to CConnman::Options
Part of a series of changes to clean up the instantiation of connman by decoupling the command line arguments.
1 parent c2ab38b commit ce79f32

File tree

3 files changed

+13
-20
lines changed

3 files changed

+13
-20
lines changed

src/init.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,16 +1289,6 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
12891289
}
12901290
}
12911291

1292-
if (gArgs.IsArgSet("-whitelist")) {
1293-
for (const std::string& net : gArgs.GetArgs("-whitelist")) {
1294-
CSubNet subnet;
1295-
LookupSubNet(net.c_str(), subnet);
1296-
if (!subnet.IsValid())
1297-
return InitError(strprintf(_("Invalid netmask specified in -whitelist: '%s'"), net));
1298-
connman.AddWhitelistedRange(subnet);
1299-
}
1300-
}
1301-
13021292
// Check for host lookup allowed before parsing any network related parameters
13031293
fNameLookup = GetBoolArg("-dns", DEFAULT_NAME_LOOKUP);
13041294

@@ -1661,6 +1651,16 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
16611651
connOptions.nMaxOutboundTimeframe = nMaxOutboundTimeframe;
16621652
connOptions.nMaxOutboundLimit = nMaxOutboundLimit;
16631653

1654+
if (gArgs.IsArgSet("-whitelist")) {
1655+
for (const auto& net : gArgs.GetArgs("-whitelist")) {
1656+
CSubNet subnet;
1657+
LookupSubNet(net.c_str(), subnet);
1658+
if (!subnet.IsValid())
1659+
return InitError(strprintf(_("Invalid netmask specified in -whitelist: '%s'"), net));
1660+
connOptions.vWhitelistedRange.push_back(subnet);
1661+
}
1662+
}
1663+
16641664
if (gArgs.IsArgSet("-seednode")) {
16651665
connOptions.vSeedNodes = gArgs.GetArgs("-seednode");
16661666
}

src/net.cpp

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -601,20 +601,13 @@ void CConnman::SetBannedSetDirty(bool dirty)
601601

602602

603603
bool CConnman::IsWhitelistedRange(const CNetAddr &addr) {
604-
LOCK(cs_vWhitelistedRange);
605604
for (const CSubNet& subnet : vWhitelistedRange) {
606605
if (subnet.Match(addr))
607606
return true;
608607
}
609608
return false;
610609
}
611610

612-
void CConnman::AddWhitelistedRange(const CSubNet &subnet) {
613-
LOCK(cs_vWhitelistedRange);
614-
vWhitelistedRange.push_back(subnet);
615-
}
616-
617-
618611
std::string CNode::GetAddrName() const {
619612
LOCK(cs_addrName);
620613
return addrName;
@@ -2248,6 +2241,8 @@ bool CConnman::Start(CScheduler& scheduler, std::string& strNodeError, Options c
22482241

22492242
SetBestHeight(connOptions.nBestHeight);
22502243

2244+
vWhitelistedRange = connOptions.vWhitelistedRange;
2245+
22512246
for (const auto& strDest : connOptions.vSeedNodes) {
22522247
AddOneShot(strDest);
22532248
}

src/net.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ class CConnman
144144
uint64_t nMaxOutboundTimeframe = 0;
145145
uint64_t nMaxOutboundLimit = 0;
146146
std::vector<std::string> vSeedNodes;
147+
std::vector<CSubNet> vWhitelistedRange;
147148
};
148149
CConnman(uint64_t seed0, uint64_t seed1);
149150
~CConnman();
@@ -244,8 +245,6 @@ class CConnman
244245

245246
unsigned int GetSendBufferSize() const;
246247

247-
void AddWhitelistedRange(const CSubNet &subnet);
248-
249248
ServiceFlags GetLocalServices() const;
250249

251250
//!set the max outbound target in bytes
@@ -346,7 +345,6 @@ class CConnman
346345
// Whitelisted ranges. Any node connecting from these is automatically
347346
// whitelisted (as well as those connecting to whitelisted binds).
348347
std::vector<CSubNet> vWhitelistedRange;
349-
CCriticalSection cs_vWhitelistedRange;
350348

351349
unsigned int nSendBufferMaxSize;
352350
unsigned int nReceiveFloodSize;

0 commit comments

Comments
 (0)