MCPcopy Create free account
hub / github.com/bitcoinxt/bitcoinxt / ThreadOpenConnections

Function ThreadOpenConnections

src/net.cpp:1300–1431  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1298}
1299
1300void ThreadOpenConnections()
1301{
1302 // Connect to specific addresses
1303 if (mapArgs.count("-connect") && mapMultiArgs["-connect"].size() > 0)
1304 {
1305 for (int64_t nLoop = 0;; nLoop++)
1306 {
1307 ProcessOneShot();
1308 BOOST_FOREACH(string strAddr, mapMultiArgs["-connect"])
1309 {
1310 CAddress addr;
1311 OpenNetworkConnection(addr, false, NULL, strAddr.c_str());
1312 for (int i = 0; i < 10 && i < nLoop; i++)
1313 {
1314 MilliSleep(500);
1315 }
1316 }
1317 MilliSleep(500);
1318 }
1319 }
1320
1321 // Initiate network connections
1322 int64_t nStart = GetTime();
1323
1324 // Minimum time before next feeler connection (in microseconds).
1325 int64_t nNextFeeler = PoissonNextSend(nStart*1000*1000, FEELER_INTERVAL);
1326 while (true)
1327 {
1328 ProcessOneShot();
1329
1330 MilliSleep(500);
1331
1332 CSemaphoreGrant grant(*semOutbound);
1333 boost::this_thread::interruption_point();
1334
1335 // Add seed nodes if DNS seeds are all down (an infrastructure attack?).
1336 if (addrman.size() == 0 && (GetTime() - nStart > 60)) {
1337 static bool done = false;
1338 if (!done) {
1339 LogPrintf("Adding fixed seed nodes as DNS doesn't seem to be available.\n");
1340 addrman.Add(convertSeed6(Params().FixedSeeds()), CNetAddr("127.0.0.1"));
1341 done = true;
1342 }
1343 }
1344
1345 //
1346 // Choose an address to connect to based on most recently seen
1347 //
1348 CAddress addrConnect;
1349
1350 // Only connect out to one peer per network group (/16 for IPv4).
1351 // Do this here so we don't have to critsect vNodes inside mapAddresses critsect.
1352 int nOutbound = 0;
1353 set<vector<unsigned char> > setConnected;
1354 {
1355 LOCK(cs_vNodes);
1356 BOOST_FOREACH(CNode* pnode, vNodes) {
1357 if (!pnode->fInbound) {

Callers

nothing calls this directly

Calls 15

ProcessOneShotFunction · 0.85
MilliSleepFunction · 0.85
GetTimeFunction · 0.85
PoissonNextSendFunction · 0.85
convertSeed6Function · 0.85
GetTimeMicrosFunction · 0.85
GetAdjustedTimeFunction · 0.85
IsLocalFunction · 0.85
IsLimitedFunction · 0.85
GetRandIntFunction · 0.85
OpenNetworkConnectionFunction · 0.85
countMethod · 0.80

Tested by

no test coverage detected