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

Function ThreadOpenConnections

src/net.cpp:954–1047  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

952}
953
954void ThreadOpenConnections() {
955 // Connect to specific addresses
956 if (SysCfg().IsArgCount("-connect") && SysCfg().GetMultiArgs("-connect").size() > 0) {
957 for (int64_t nLoop = 0;; nLoop++) {
958 ProcessOneShot();
959 vector<string> tmp = SysCfg().GetMultiArgs("-connect");
960 for (auto strAddr : tmp) {
961 CAddress addr;
962 OpenNetworkConnection(addr, nullptr, strAddr.c_str());
963 for (int32_t i = 0; i < 10 && i < nLoop; i++) {
964 MilliSleep(500);
965 }
966 }
967 MilliSleep(500);
968 }
969 }
970
971 // Initiate network connections
972 int64_t nStart = GetTime();
973 while (true) {
974 ProcessOneShot();
975
976 MilliSleep(500);
977
978 CSemaphoreGrant grant(*semOutbound);
979 boost::this_thread::interruption_point();
980
981 // Add seed nodes if DNS seeds are all down (an infrastructure attack?).
982 if (addrman.size() == 0 && (GetTime() - nStart > 60)) {
983 static bool done = false;
984 if (!done) {
985 LogPrint(BCLog::INFO, "Adding fixed seed nodes as DNS doesn't seem to be available.\n");
986 addrman.Add(SysCfg().FixedSeeds(), CNetAddr("127.0.0.1"));
987 done = true;
988 }
989 }
990
991 //
992 // Choose an address to connect to based on most recently seen
993 //
994 CAddress addrConnect;
995
996 // Only connect out to one peer per network group (/16 for IPv4).
997 // Do this here so we don't have to critsect vNodes inside mapAddresses critsect.
998 int32_t nOutbound = 0;
999 set<vector<uint8_t> > setConnected;
1000 {
1001 LOCK(cs_vNodes);
1002 for (auto pNode : vNodes) {
1003 if (!pNode->fInbound) {
1004 setConnected.insert(pNode->addr.GetGroup());
1005 nOutbound++;
1006 }
1007 }
1008 }
1009
1010 int64_t nANow = GetAdjustedTime();
1011

Callers

nothing calls this directly

Calls 15

ProcessOneShotFunction · 0.85
OpenNetworkConnectionFunction · 0.85
MilliSleepFunction · 0.85
GetTimeFunction · 0.85
GetAdjustedTimeFunction · 0.85
IsLocalFunction · 0.85
IsLimitedFunction · 0.85
IsArgCountMethod · 0.80
GetGroupMethod · 0.80
IsInFixedSeedsMethod · 0.80
GetPortMethod · 0.80
CNetAddrClass · 0.70

Tested by

no test coverage detected