From 352d582ba240b825cb834cdde041864bafca0e21 Mon Sep 17 00:00:00 2001 From: Marko Bencun Date: Thu, 15 Jun 2017 09:39:07 +0200 Subject: [PATCH] Add vConnect to CConnman::Options Split the "-connect" argument parsing out of CConnman and put it into AppInitMain(). --- src/init.cpp | 9 ++++++++- src/net.cpp | 19 +++++++++++++------ src/net.h | 4 +++- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index d9b98be739..ceea9aa170 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1651,7 +1651,14 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler) 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; } diff --git a/src/net.cpp b/src/net.cpp index 5bf3af7ea3..c83226efa9 100644 --- a/src/net.cpp +++ b/src/net.cpp @@ -1674,15 +1674,15 @@ void CConnman::ProcessOneShot() } } -void CConnman::ThreadOpenConnections() +void CConnman::ThreadOpenConnections(const std::vector 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, NULL, strAddr.c_str()); @@ -2360,9 +2360,16 @@ bool CConnman::Start(CScheduler& scheduler, Options connOptions) // Initiate outbound connections from -addnode threadOpenAddedConnections = std::thread(&TraceThread >, "addcon", std::function(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 >, "opencon", std::function(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 >, "opencon", std::function(std::bind(&CConnman::ThreadOpenConnections, this, connOptions.m_specified_outgoing))); // Process messages threadMessageHandler = std::thread(&TraceThread >, "msghand", std::function(std::bind(&CConnman::ThreadMessageHandler, this))); diff --git a/src/net.h b/src/net.h index b9a11c62f2..44e0e78fce 100644 --- a/src/net.h +++ b/src/net.h @@ -145,6 +145,8 @@ public: std::vector vSeedNodes; std::vector vWhitelistedRange; std::vector vBinds, vWhiteBinds; + bool m_use_addrman_outgoing = true; + std::vector m_specified_outgoing; }; CConnman(uint64_t seed0, uint64_t seed1); ~CConnman(); @@ -293,7 +295,7 @@ private: void ThreadOpenAddedConnections(); void AddOneShot(const std::string& strDest); void ProcessOneShot(); - void ThreadOpenConnections(); + void ThreadOpenConnections(std::vector connect); void ThreadMessageHandler(); void AcceptConnection(const ListenSocket& hListenSocket); void ThreadSocketHandler();