Merge #10596: Add vConnect to CConnman::Options

352d582ba Add vConnect to CConnman::Options (Marko Bencun)

Pull request description:

  Split the "-connect" argument parsing out of CConnman and put it into
  AppInitMain().

Tree-SHA512: f2d3efc4e2c5808ff98696ea20dd96df599bc472ed5afc9c3eea305d94c36a6ab50c632aa05396c7c34d1917d91b1e7ccd725656ff2631e2a36d9eac477455dc
This commit is contained in:
Wladimir J. van der Laan 2017-09-06 01:54:31 +02:00 committed by Pasta
parent 742d6e99fa
commit e4fef1fd33
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984
3 changed files with 24 additions and 8 deletions

View File

@ -2196,7 +2196,14 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
if (gArgs.IsArgSet("-seednode")) { if (gArgs.IsArgSet("-seednode")) {
connOptions.vSeedNodes = gArgs.GetArgs("-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)) { if (!connman.Start(scheduler, connOptions)) {
return false; return false;
} }

View File

@ -1844,15 +1844,15 @@ int CConnman::GetExtraOutboundCount()
return std::max(nOutbound - nMaxOutbound, 0); return std::max(nOutbound - nMaxOutbound, 0);
} }
void CConnman::ThreadOpenConnections() void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
{ {
// Connect to specific addresses // Connect to specific addresses
if (gArgs.IsArgSet("-connect")) if (!connect.empty())
{ {
for (int64_t nLoop = 0;; nLoop++) for (int64_t nLoop = 0;; nLoop++)
{ {
ProcessOneShot(); ProcessOneShot();
for (const std::string& strAddr : gArgs.GetArgs("-connect")) for (const std::string& strAddr : connect)
{ {
CAddress addr(CService(), NODE_NONE); CAddress addr(CService(), NODE_NONE);
OpenNetworkConnection(addr, false, nullptr, strAddr.c_str(), false, false, true); OpenNetworkConnection(addr, false, nullptr, strAddr.c_str(), false, false, true);
@ -2621,9 +2621,16 @@ bool CConnman::Start(CScheduler& scheduler, const Options& connOptions)
// Initiate outbound connections from -addnode // Initiate outbound connections from -addnode
threadOpenAddedConnections = std::thread(&TraceThread<std::function<void()> >, "addcon", std::function<void()>(std::bind(&CConnman::ThreadOpenAddedConnections, this))); threadOpenAddedConnections = std::thread(&TraceThread<std::function<void()> >, "addcon", std::function<void()>(std::bind(&CConnman::ThreadOpenAddedConnections, this)));
// Initiate outbound connections unless connect=0 if (connOptions.m_use_addrman_outgoing && !connOptions.m_specified_outgoing.empty()) {
if (!gArgs.IsArgSet("-connect") || gArgs.GetArgs("-connect").size() != 1 || gArgs.GetArgs("-connect")[0] != "0") if (clientInterface) {
threadOpenConnections = std::thread(&TraceThread<std::function<void()> >, "opencon", std::function<void()>(std::bind(&CConnman::ThreadOpenConnections, this))); 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)));
// Initiate masternode connections // Initiate masternode connections
threadOpenMasternodeConnections = std::thread(&TraceThread<std::function<void()> >, "mncon", std::function<void()>(std::bind(&CConnman::ThreadOpenMasternodeConnections, this))); threadOpenMasternodeConnections = std::thread(&TraceThread<std::function<void()> >, "mncon", std::function<void()>(std::bind(&CConnman::ThreadOpenMasternodeConnections, this)));

View File

@ -169,6 +169,8 @@ public:
std::vector<std::string> vSeedNodes; std::vector<std::string> vSeedNodes;
std::vector<CSubNet> vWhitelistedRange; std::vector<CSubNet> vWhitelistedRange;
std::vector<CService> vBinds, vWhiteBinds; std::vector<CService> vBinds, vWhiteBinds;
bool m_use_addrman_outgoing = true;
std::vector<std::string> m_specified_outgoing;
}; };
void Init(const Options& connOptions) { void Init(const Options& connOptions) {
@ -463,7 +465,7 @@ private:
void ThreadOpenAddedConnections(); void ThreadOpenAddedConnections();
void AddOneShot(const std::string& strDest); void AddOneShot(const std::string& strDest);
void ProcessOneShot(); void ProcessOneShot();
void ThreadOpenConnections(); void ThreadOpenConnections(std::vector<std::string> connect);
void ThreadMessageHandler(); void ThreadMessageHandler();
void AcceptConnection(const ListenSocket& hListenSocket); void AcceptConnection(const ListenSocket& hListenSocket);
void ThreadSocketHandler(); void ThreadSocketHandler();