MCPcopy Create free account
hub / github.com/LUX-Core/lux / ThreadOpenConnections

Function ThreadOpenConnections

src/net.cpp:1399–1500  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1397}
1398
1399void ThreadOpenConnections() {
1400 // Connect to specific addresses
1401 if (mapArgs.count("-connect") && mapMultiArgs["-connect"].size() > 0) {
1402 for (int64_t nLoop = 0;; nLoop++) {
1403 ProcessOneShot();
1404 for (string strAddr : mapMultiArgs["-connect"]) {
1405 CAddress addr;
1406 OpenNetworkConnection(addr, false, NULL, strAddr.c_str());
1407 for (int i = 0; i < 10 && i < nLoop; i++) {
1408 MilliSleep(500);
1409 }
1410 }
1411 MilliSleep(500);
1412 }
1413 }
1414
1415 // Initiate network connections
1416 int64_t nStart = GetTime();
1417 while (true) {
1418 ProcessOneShot();
1419
1420 MilliSleep(500);
1421
1422 CSemaphoreGrant grant(*semOutbound);
1423 boost::this_thread::interruption_point();
1424
1425 // Add seed nodes if DNS seeds are all down/we get less than 5 nodes (more nodes for a more stable network).
1426 if (addrman.size() < 5 && (GetTime() - nStart > 60)) {
1427 static bool done = false;
1428 if (!done) {
1429 LogPrintf("Adding fixed seed nodes as DNS doesn't seem to be available.\n");
1430 addrman.Add(convertSeed6(Params().FixedSeeds()), CNetAddr("127.0.0.1"));
1431 done = true;
1432 }
1433 }
1434
1435 //
1436 // Choose an address to connect to based on most recently seen
1437 //
1438 CAddress addrConnect;
1439
1440 // Only connect out to one peer per network group (/16 for IPv4).
1441 // Do this here so we don't have to critsect vNodes inside mapAddresses critsect.
1442 int nOutbound = 0;
1443 set<vector<unsigned char> > setConnected;
1444 vector<CNode*> vNodesCopy;
1445 {
1446 LOCK(cs_vNodes);
1447 vNodesCopy = vNodes;
1448 }
1449
1450 for (CNode* pnode : vNodesCopy) {
1451 if (pnode && !pnode->fInbound) {
1452 setConnected.insert(pnode->addr.GetGroup());
1453 nOutbound++;
1454 }
1455 }
1456

Callers

nothing calls this directly

Calls 15

ProcessOneShotFunction · 0.85
OpenNetworkConnectionFunction · 0.85
MilliSleepFunction · 0.85
GetTimeFunction · 0.85
convertSeed6Function · 0.85
GetAdjustedTimeFunction · 0.85
IsLocalFunction · 0.85
IsLimitedFunction · 0.85
GetGroupMethod · 0.80
GetPortMethod · 0.80
GetDefaultPortMethod · 0.80
ParamsClass · 0.70

Tested by

no test coverage detected