Skip to content

Commit

Permalink
add WhitelistedRange to CConnman::Options
Browse files Browse the repository at this point in the history
  Part of a series of changes to clean up the instantiation of connman by decoupling the command line arguments.

  Coming from btc@ce79f3251851f6177f38009341802e6065cb70af
  • Loading branch information
Marko Bencun authored and furszy committed Nov 5, 2021
1 parent c3b3c99 commit 10efb72
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
16 changes: 8 additions & 8 deletions src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1394,14 +1394,6 @@ bool AppInitMain()
}
}

for (const auto& net : gArgs.GetArgs("-whitelist")) {
CSubNet subnet;
LookupSubNet(net, subnet);
if (!subnet.IsValid())
return UIError(strprintf(_("Invalid netmask specified in %s: '%s'"), "-whitelist", net));
connman.AddWhitelistedRange(subnet);
}

// Check for host lookup allowed before parsing any network related parameters
fNameLookup = gArgs.GetBoolArg("-dns", DEFAULT_NAME_LOOKUP);

Expand Down Expand Up @@ -1994,6 +1986,14 @@ bool AppInitMain()
connOptions.nSendBufferMaxSize = 1000*gArgs.GetArg("-maxsendbuffer", DEFAULT_MAXSENDBUFFER);
connOptions.nReceiveFloodSize = 1000*gArgs.GetArg("-maxreceivebuffer", DEFAULT_MAXRECEIVEBUFFER);

for (const auto& net : gArgs.GetArgs("-whitelist")) {
CSubNet subnet;
LookupSubNet(net, subnet);
if (!subnet.IsValid())
return UIError(strprintf(_("Invalid netmask specified in %s: '%s'"), "-whitelist", net));
connOptions.vWhitelistedRange.emplace_back(subnet);
}

if (!connman.Start(scheduler, strNodeError, connOptions))
return UIError(strNodeError);

Expand Down
10 changes: 2 additions & 8 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,21 +607,13 @@ void CConnman::SetBannedSetDirty(bool dirty)

bool CConnman::IsWhitelistedRange(const CNetAddr& addr)
{
LOCK(cs_vWhitelistedRange);
for (const CSubNet& subnet : vWhitelistedRange) {
if (subnet.Match(addr))
return true;
}
return false;
}

void CConnman::AddWhitelistedRange(const CSubNet& subnet)
{
LOCK(cs_vWhitelistedRange);
vWhitelistedRange.push_back(subnet);
}


std::string CNode::GetAddrName() const {
LOCK(cs_addrName);
return addrName;
Expand Down Expand Up @@ -1958,6 +1950,8 @@ bool CConnman::Start(CScheduler& scheduler, std::string& strNodeError, Options c

SetBestHeight(connOptions.nBestHeight);

vWhitelistedRange = connOptions.vWhitelistedRange;

clientInterface = connOptions.uiInterface;
if (clientInterface)
clientInterface->InitMessage(_("Loading addresses..."));
Expand Down
4 changes: 1 addition & 3 deletions src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class CConnman
unsigned int nSendBufferMaxSize = 0;
unsigned int nReceiveFloodSize = 0;
std::vector<bool> m_asmap;
std::vector<CSubNet> vWhitelistedRange;
};
CConnman(uint64_t seed0, uint64_t seed1);
~CConnman();
Expand Down Expand Up @@ -284,8 +285,6 @@ class CConnman

unsigned int GetSendBufferSize() const;

void AddWhitelistedRange(const CSubNet& subnet);

ServiceFlags GetLocalServices() const;

uint64_t GetTotalBytesRecv();
Expand Down Expand Up @@ -360,7 +359,6 @@ class CConnman
// Whitelisted ranges. Any node connecting from these is automatically
// whitelisted (as well as those connecting to whitelisted binds).
std::vector<CSubNet> vWhitelistedRange;
RecursiveMutex cs_vWhitelistedRange;

unsigned int nSendBufferMaxSize{0};
unsigned int nReceiveFloodSize{0};
Expand Down

0 comments on commit 10efb72

Please sign in to comment.