Changeset View
Changeset View
Standalone View
Standalone View
src/net.cpp
Show First 20 Lines • Show All 1,743 Lines • ▼ Show 20 Lines | if (grant) { | ||||
true)) { | true)) { | ||||
AddOneShot(strDest); | AddOneShot(strDest); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
void CConnman::ThreadOpenConnections() { | void CConnman::ThreadOpenConnections() { | ||||
// Connect to specific addresses | // Connect to specific addresses | ||||
if (mapMultiArgs.count("-connect") && | if (gArgs.IsArgSet("-connect") && gArgs.GetArgs("-connect").size() > 0) { | ||||
mapMultiArgs.at("-connect").size() > 0) { | |||||
for (int64_t nLoop = 0;; nLoop++) { | for (int64_t nLoop = 0;; nLoop++) { | ||||
ProcessOneShot(); | ProcessOneShot(); | ||||
for (const std::string &strAddr : mapMultiArgs.at("-connect")) { | for (const std::string &strAddr : gArgs.GetArgs("-connect")) { | ||||
CAddress addr(CService(), NODE_NONE); | CAddress addr(CService(), NODE_NONE); | ||||
OpenNetworkConnection(addr, false, nullptr, strAddr.c_str()); | OpenNetworkConnection(addr, false, nullptr, strAddr.c_str()); | ||||
for (int i = 0; i < 10 && i < nLoop; i++) { | for (int i = 0; i < 10 && i < nLoop; i++) { | ||||
if (!interruptNet.sleep_for( | if (!interruptNet.sleep_for( | ||||
std::chrono::milliseconds(500))) { | std::chrono::milliseconds(500))) { | ||||
return; | return; | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 218 Lines • ▼ Show 20 Lines | std::vector<AddedNodeInfo> CConnman::GetAddedNodeInfo() { | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
void CConnman::ThreadOpenAddedConnections() { | void CConnman::ThreadOpenAddedConnections() { | ||||
{ | { | ||||
LOCK(cs_vAddedNodes); | LOCK(cs_vAddedNodes); | ||||
if (mapMultiArgs.count("-addnode")) { | if (gArgs.IsArgSet("-addnode")) { | ||||
vAddedNodes = mapMultiArgs.at("-addnode"); | vAddedNodes = gArgs.GetArgs("-addnode"); | ||||
} | } | ||||
} | } | ||||
while (true) { | while (true) { | ||||
CSemaphoreGrant grant(*semAddnode); | CSemaphoreGrant grant(*semAddnode); | ||||
std::vector<AddedNodeInfo> vInfo = GetAddedNodeInfo(); | std::vector<AddedNodeInfo> vInfo = GetAddedNodeInfo(); | ||||
bool tried = false; | bool tried = false; | ||||
for (const AddedNodeInfo &info : vInfo) { | for (const AddedNodeInfo &info : vInfo) { | ||||
▲ Show 20 Lines • Show All 448 Lines • ▼ Show 20 Lines | bool CConnman::Start(CScheduler &scheduler, std::string &strNodeError, | ||||
// Initiate outbound connections from -addnode | // Initiate outbound connections from -addnode | ||||
threadOpenAddedConnections = | threadOpenAddedConnections = | ||||
std::thread(&TraceThread<std::function<void()>>, "addcon", | std::thread(&TraceThread<std::function<void()>>, "addcon", | ||||
std::function<void()>(std::bind( | std::function<void()>(std::bind( | ||||
&CConnman::ThreadOpenAddedConnections, this))); | &CConnman::ThreadOpenAddedConnections, this))); | ||||
// Initiate outbound connections unless connect=0 | // Initiate outbound connections unless connect=0 | ||||
if (!mapMultiArgs.count("-connect") || | if (!gArgs.IsArgSet("-connect") || gArgs.GetArgs("-connect").size() != 1 || | ||||
mapMultiArgs.at("-connect").size() != 1 || | gArgs.GetArgs("-connect")[0] != "0") { | ||||
mapMultiArgs.at("-connect")[0] != "0") { | |||||
threadOpenConnections = | threadOpenConnections = | ||||
std::thread(&TraceThread<std::function<void()>>, "opencon", | std::thread(&TraceThread<std::function<void()>>, "opencon", | ||||
std::function<void()>( | std::function<void()>( | ||||
std::bind(&CConnman::ThreadOpenConnections, this))); | std::bind(&CConnman::ThreadOpenConnections, this))); | ||||
} | } | ||||
// Process messages | // Process messages | ||||
threadMessageHandler = | threadMessageHandler = | ||||
▲ Show 20 Lines • Show All 554 Lines • ▼ Show 20 Lines | |||||
std::string userAgent(const Config &config) { | std::string userAgent(const Config &config) { | ||||
// format excessive blocksize value | // format excessive blocksize value | ||||
std::string eb = getSubVersionEB(config.GetMaxBlockSize()); | std::string eb = getSubVersionEB(config.GetMaxBlockSize()); | ||||
std::vector<std::string> uacomments; | std::vector<std::string> uacomments; | ||||
uacomments.push_back("EB" + eb); | uacomments.push_back("EB" + eb); | ||||
// sanitize comments per BIP-0014, format user agent and check total size | // sanitize comments per BIP-0014, format user agent and check total size | ||||
if (mapMultiArgs.count("-uacomment")) { | if (gArgs.IsArgSet("-uacomment")) { | ||||
for (const std::string &cmt : mapMultiArgs.at("-uacomment")) { | for (const std::string &cmt : gArgs.GetArgs("-uacomment")) { | ||||
if (cmt != SanitizeString(cmt, SAFE_CHARS_UA_COMMENT)) { | if (cmt != SanitizeString(cmt, SAFE_CHARS_UA_COMMENT)) { | ||||
LogPrintf( | LogPrintf( | ||||
"User Agent comment (%s) contains unsafe characters. " | "User Agent comment (%s) contains unsafe characters. " | ||||
"We are going to use a sanitize version of the comment.\n", | "We are going to use a sanitize version of the comment.\n", | ||||
cmt); | cmt); | ||||
} | } | ||||
uacomments.push_back(cmt); | uacomments.push_back(cmt); | ||||
} | } | ||||
Show All 16 Lines |