Browse Source

add WhitelistedRange to CConnman::Options

Part of a series of changes to clean up the instantiation of connman
by decoupling the command line arguments.
0.15
Marko Bencun 7 years ago
parent
commit
ce79f32518
  1. 20
      src/init.cpp
  2. 9
      src/net.cpp
  3. 4
      src/net.h

20
src/init.cpp

@ -1289,16 +1289,6 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
} }
} }
if (gArgs.IsArgSet("-whitelist")) {
for (const std::string& net : gArgs.GetArgs("-whitelist")) {
CSubNet subnet;
LookupSubNet(net.c_str(), subnet);
if (!subnet.IsValid())
return InitError(strprintf(_("Invalid netmask specified in -whitelist: '%s'"), net));
connman.AddWhitelistedRange(subnet);
}
}
// Check for host lookup allowed before parsing any network related parameters // Check for host lookup allowed before parsing any network related parameters
fNameLookup = GetBoolArg("-dns", DEFAULT_NAME_LOOKUP); fNameLookup = GetBoolArg("-dns", DEFAULT_NAME_LOOKUP);
@ -1661,6 +1651,16 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
connOptions.nMaxOutboundTimeframe = nMaxOutboundTimeframe; connOptions.nMaxOutboundTimeframe = nMaxOutboundTimeframe;
connOptions.nMaxOutboundLimit = nMaxOutboundLimit; connOptions.nMaxOutboundLimit = nMaxOutboundLimit;
if (gArgs.IsArgSet("-whitelist")) {
for (const auto& net : gArgs.GetArgs("-whitelist")) {
CSubNet subnet;
LookupSubNet(net.c_str(), subnet);
if (!subnet.IsValid())
return InitError(strprintf(_("Invalid netmask specified in -whitelist: '%s'"), net));
connOptions.vWhitelistedRange.push_back(subnet);
}
}
if (gArgs.IsArgSet("-seednode")) { if (gArgs.IsArgSet("-seednode")) {
connOptions.vSeedNodes = gArgs.GetArgs("-seednode"); connOptions.vSeedNodes = gArgs.GetArgs("-seednode");
} }

9
src/net.cpp

@ -601,7 +601,6 @@ void CConnman::SetBannedSetDirty(bool dirty)
bool CConnman::IsWhitelistedRange(const CNetAddr &addr) { bool CConnman::IsWhitelistedRange(const CNetAddr &addr) {
LOCK(cs_vWhitelistedRange);
for (const CSubNet& subnet : vWhitelistedRange) { for (const CSubNet& subnet : vWhitelistedRange) {
if (subnet.Match(addr)) if (subnet.Match(addr))
return true; return true;
@ -609,12 +608,6 @@ bool CConnman::IsWhitelistedRange(const CNetAddr &addr) {
return false; return false;
} }
void CConnman::AddWhitelistedRange(const CSubNet &subnet) {
LOCK(cs_vWhitelistedRange);
vWhitelistedRange.push_back(subnet);
}
std::string CNode::GetAddrName() const { std::string CNode::GetAddrName() const {
LOCK(cs_addrName); LOCK(cs_addrName);
return addrName; return addrName;
@ -2248,6 +2241,8 @@ bool CConnman::Start(CScheduler& scheduler, std::string& strNodeError, Options c
SetBestHeight(connOptions.nBestHeight); SetBestHeight(connOptions.nBestHeight);
vWhitelistedRange = connOptions.vWhitelistedRange;
for (const auto& strDest : connOptions.vSeedNodes) { for (const auto& strDest : connOptions.vSeedNodes) {
AddOneShot(strDest); AddOneShot(strDest);
} }

4
src/net.h

@ -144,6 +144,7 @@ public:
uint64_t nMaxOutboundTimeframe = 0; uint64_t nMaxOutboundTimeframe = 0;
uint64_t nMaxOutboundLimit = 0; uint64_t nMaxOutboundLimit = 0;
std::vector<std::string> vSeedNodes; std::vector<std::string> vSeedNodes;
std::vector<CSubNet> vWhitelistedRange;
}; };
CConnman(uint64_t seed0, uint64_t seed1); CConnman(uint64_t seed0, uint64_t seed1);
~CConnman(); ~CConnman();
@ -244,8 +245,6 @@ public:
unsigned int GetSendBufferSize() const; unsigned int GetSendBufferSize() const;
void AddWhitelistedRange(const CSubNet &subnet);
ServiceFlags GetLocalServices() const; ServiceFlags GetLocalServices() const;
//!set the max outbound target in bytes //!set the max outbound target in bytes
@ -346,7 +345,6 @@ private:
// Whitelisted ranges. Any node connecting from these is automatically // Whitelisted ranges. Any node connecting from these is automatically
// whitelisted (as well as those connecting to whitelisted binds). // whitelisted (as well as those connecting to whitelisted binds).
std::vector<CSubNet> vWhitelistedRange; std::vector<CSubNet> vWhitelistedRange;
CCriticalSection cs_vWhitelistedRange;
unsigned int nSendBufferMaxSize; unsigned int nSendBufferMaxSize;
unsigned int nReceiveFloodSize; unsigned int nReceiveFloodSize;

Loading…
Cancel
Save