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

Function Discover

src/net.cpp:1333–1380  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1331}
1332
1333void static Discover(boost::thread_group& threadGroup) {
1334 if (!fDiscover)
1335 return;
1336
1337#ifdef WIN32
1338 // Get local host IP
1339 char pszHostName[1000] = "";
1340 if (gethostname(pszHostName, sizeof(pszHostName)) != SOCKET_ERROR) {
1341 vector<CNetAddr> vaddr;
1342 if (LookupHost(pszHostName, vaddr)) {
1343 for (const auto& addr : vaddr) {
1344 AddLocal(addr, LOCAL_IF);
1345 }
1346 }
1347 }
1348#else
1349 // Get local host ip
1350 struct ifaddrs* myaddrs;
1351 if (getifaddrs(&myaddrs) == 0) {
1352 for (struct ifaddrs* ifa = myaddrs; ifa != nullptr; ifa = ifa->ifa_next) {
1353 if (ifa->ifa_addr == nullptr)
1354 continue;
1355 if ((ifa->ifa_flags & IFF_UP) == 0)
1356 continue;
1357 if (strcmp(ifa->ifa_name, "lo") == 0)
1358 continue;
1359 if (strcmp(ifa->ifa_name, "lo0") == 0)
1360 continue;
1361 if (ifa->ifa_addr->sa_family == AF_INET) {
1362 struct sockaddr_in* s4 = (struct sockaddr_in*)(ifa->ifa_addr);
1363 CNetAddr addr(s4->sin_addr);
1364 if (AddLocal(addr, LOCAL_IF))
1365 LogPrint(BCLog::INFO, "IPv4 %s: %s\n", ifa->ifa_name, addr.ToString());
1366 } else if (ifa->ifa_addr->sa_family == AF_INET6) {
1367 struct sockaddr_in6* s6 = (struct sockaddr_in6*)(ifa->ifa_addr);
1368 CNetAddr addr(s6->sin6_addr);
1369 if (AddLocal(addr, LOCAL_IF))
1370 LogPrint(BCLog::INFO, "IPv6 %s: %s\n", ifa->ifa_name, addr.ToString());
1371 }
1372 }
1373 freeifaddrs(myaddrs);
1374 }
1375#endif
1376
1377 // Don't use external IPv4 discovery, when -onlynet="IPv6"
1378 if (!IsLimited(NET_IPV4))
1379 threadGroup.create_thread(boost::bind(&TraceThread<void (*)()>, "ext-ip", &ThreadGetMyPublicIP));
1380}
1381
1382void StartNode(boost::thread_group& threadGroup) {
1383 if (semOutbound == nullptr) {

Callers 1

StartNodeFunction · 0.85

Calls 4

LookupHostFunction · 0.85
AddLocalFunction · 0.85
IsLimitedFunction · 0.85
ToStringMethod · 0.45

Tested by

no test coverage detected