MCPcopy Create free account
hub / github.com/ElementsProject/elements / ThreadOpenConnections

Method ThreadOpenConnections

src/net.cpp:1919–2187  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1917}
1918
1919void CConnman::ThreadOpenConnections(const std::vector<std::string> connect)
1920{
1921 SetSyscallSandboxPolicy(SyscallSandboxPolicy::NET_OPEN_CONNECTION);
1922 // Connect to specific addresses
1923 if (!connect.empty())
1924 {
1925 for (int64_t nLoop = 0;; nLoop++)
1926 {
1927 ProcessAddrFetch();
1928 for (const std::string& strAddr : connect)
1929 {
1930 CAddress addr(CService(), NODE_NONE);
1931 OpenNetworkConnection(addr, false, nullptr, strAddr.c_str(), ConnectionType::MANUAL);
1932 for (int i = 0; i < 10 && i < nLoop; i++)
1933 {
1934 if (!interruptNet.sleep_for(std::chrono::milliseconds(500)))
1935 return;
1936 }
1937 }
1938 if (!interruptNet.sleep_for(std::chrono::milliseconds(500)))
1939 return;
1940 }
1941 }
1942
1943 // Initiate network connections
1944 auto start = GetTime<std::chrono::microseconds>();
1945
1946 // Minimum time before next feeler connection (in microseconds).
1947 auto next_feeler = GetExponentialRand(start, FEELER_INTERVAL);
1948 auto next_extra_block_relay = GetExponentialRand(start, EXTRA_BLOCK_RELAY_ONLY_PEER_INTERVAL);
1949 const bool dnsseed = gArgs.GetBoolArg("-dnsseed", DEFAULT_DNSSEED);
1950 bool add_fixed_seeds = gArgs.GetBoolArg("-fixedseeds", DEFAULT_FIXEDSEEDS);
1951
1952 if (!add_fixed_seeds) {
1953 LogPrintf("Fixed seeds are disabled\n");
1954 }
1955
1956 while (!interruptNet)
1957 {
1958 ProcessAddrFetch();
1959
1960 if (!interruptNet.sleep_for(std::chrono::milliseconds(500)))
1961 return;
1962
1963 CSemaphoreGrant grant(*semOutbound);
1964 if (interruptNet)
1965 return;
1966
1967 if (add_fixed_seeds && addrman.size() == 0) {
1968 // When the node starts with an empty peers.dat, there are a few other sources of peers before
1969 // we fallback on to fixed seeds: -dnsseed, -seednode, -addnode
1970 // If none of those are available, we fallback on to fixed seeds immediately, else we allow
1971 // 60 seconds for any of those sources to populate addrman.
1972 bool add_fixed_seeds_now = false;
1973 // It is cheapest to check if enough time has passed first.
1974 if (GetTime<std::chrono::seconds>() > start + std::chrono::minutes{1}) {
1975 add_fixed_seeds_now = true;
1976 LogPrintf("Adding fixed seeds as 60 seconds have passed and addrman is empty\n");

Callers

nothing calls this directly

Calls 15

SetSyscallSandboxPolicyFunction · 0.85
GetExponentialRandFunction · 0.85
ConvertSeedsFunction · 0.85
GetAdjustedTimeFunction · 0.85
IsLocalFunction · 0.85
IsReachableFunction · 0.85
MayHaveUsefulAddressDBFunction · 0.85
IsBadPortFunction · 0.85
GetRandIntFunction · 0.85
sleep_forMethod · 0.80
GetBoolArgMethod · 0.80

Tested by

no test coverage detected