Skip to content

Commit

Permalink
Add vConnect to CConnman::Options
Browse files Browse the repository at this point in the history
Split the "-connect" argument parsing out of CConnman and put it into AppInitMain().
  • Loading branch information
Marko Bencun authored and furszy committed Nov 22, 2021
1 parent 987342e commit a13b7c9
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
9 changes: 8 additions & 1 deletion src/init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1960,7 +1960,14 @@ bool AppInitMain()
if (gArgs.IsArgSet("-seednode")) {
connOptions.vSeedNodes = gArgs.GetArgs("-seednode");
}

// Initiate outbound connections unless connect=0
connOptions.m_use_addrman_outgoing = !gArgs.IsArgSet("-connect");
if (!connOptions.m_use_addrman_outgoing) {
const auto connect = gArgs.GetArgs("-connect");
if (connect.size() != 1 || connect[0] != "0") {
connOptions.m_specified_outgoing = connect;
}
}
if (!connman.Start(scheduler, connOptions)) {
return false;
}
Expand Down
21 changes: 15 additions & 6 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1483,13 +1483,13 @@ void CConnman::ProcessOneShot()
}
}

void CConnman::ThreadOpenConnections()
void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
{
// Connect to specific addresses
if (gArgs.IsArgSet("-connect")) {
if (!connect.empty()) {
for (int64_t nLoop = 0;; nLoop++) {
ProcessOneShot();
for (const std::string& strAddr : gArgs.GetArgs("-connect")) {
for (const std::string& strAddr : connect) {
CAddress addr(CService(), NODE_NONE);
OpenNetworkConnection(addr, false, nullptr, strAddr.c_str());
for (int i = 0; i < 10 && i < nLoop; i++) {
Expand Down Expand Up @@ -2076,9 +2076,18 @@ bool CConnman::Start(CScheduler& scheduler, Options connOptions)
// Initiate outbound connections from -addnode
threadOpenAddedConnections = std::thread(&TraceThread<std::function<void()> >, "addcon", std::function<void()>(std::bind(&CConnman::ThreadOpenAddedConnections, this)));

// Initiate outbound connections unless connect=0
if (!gArgs.IsArgSet("-connect") || gArgs.GetArgs("-connect").size() != 1 || gArgs.GetArgs("-connect")[0] != "0")
threadOpenConnections = std::thread(&TraceThread<std::function<void()> >, "opencon", std::function<void()>(std::bind(&CConnman::ThreadOpenConnections, this)));
if (connOptions.m_use_addrman_outgoing && !connOptions.m_specified_outgoing.empty()) {
if (clientInterface) {
clientInterface->ThreadSafeMessageBox(
_("Cannot provide specific connections and have addrman find outgoing connections at the same."),
"", CClientUIInterface::MSG_ERROR);
}
return false;
}
if (connOptions.m_use_addrman_outgoing || !connOptions.m_specified_outgoing.empty()) {
threadOpenConnections = std::thread(&TraceThread<std::function<void()> >, "opencon", std::function<void()>(
std::bind(&CConnman::ThreadOpenConnections, this, connOptions.m_specified_outgoing)));
}

// Process messages
threadMessageHandler = std::thread(&TraceThread<std::function<void()> >, "msghand", std::function<void()>(std::bind(&CConnman::ThreadMessageHandler, this)));
Expand Down
4 changes: 3 additions & 1 deletion src/net.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ class CConnman
std::vector<std::string> vSeedNodes;
std::vector<CSubNet> vWhitelistedRange;
std::vector<CService> vBinds, vWhiteBinds;
bool m_use_addrman_outgoing = true;
std::vector<std::string> m_specified_outgoing;
};
CConnman(uint64_t seed0, uint64_t seed1);
~CConnman();
Expand Down Expand Up @@ -312,7 +314,7 @@ class CConnman
void ThreadOpenAddedConnections();
void AddOneShot(const std::string& strDest);
void ProcessOneShot();
void ThreadOpenConnections();
void ThreadOpenConnections(const std::vector<std::string> connect);
void ThreadMessageHandler();
void AcceptConnection(const ListenSocket& hListenSocket);
void ThreadSocketHandler();
Expand Down

0 comments on commit a13b7c9

Please sign in to comment.