Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor peerRefreshDNS() to clarify its (void*)1 logic #1950

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions src/neighbors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ static void neighborAlive(CachePeer *, const MemObject *, const icp_common_t *);
static void neighborAliveHtcp(CachePeer *, const MemObject *, const HtcpReplyData *);
#endif
static void neighborCountIgnored(CachePeer *);
static void peerRefreshDNS(void *);
static void peerDnsRefreshCheck(void *);
static void peerDnsRefreshStart();
static IPH peerDNSConfigure;
static void peerProbeConnect(CachePeer *, const bool reprobeIfBusy = false);
static CNCB peerProbeConnectDone;
Expand Down Expand Up @@ -533,7 +534,7 @@ neighbors_init(void)
}
}

peerRefreshDNS((void *) 1);
peerDnsRefreshStart();

sep = getservbyname("echo", "udp");
echo_port = sep ? ntohs((unsigned short) sep->s_port) : 7;
Expand Down Expand Up @@ -1148,22 +1149,32 @@ peerDNSConfigure(const ipcache_addrs *ia, const Dns::LookupDetails &, void *data
}

static void
peerRefreshDNS(void *data)
peerScheduleDnsRefreshCheck(const double delayInSeconds)
{
if (eventFind(peerRefreshDNS, nullptr))
eventDelete(peerRefreshDNS, nullptr);
if (eventFind(peerDnsRefreshCheck, nullptr))
eventDelete(peerDnsRefreshCheck, nullptr);
eventAddIsh("peerDnsRefreshCheck", peerDnsRefreshCheck, nullptr, delayInSeconds, 1);
}

if (!data && 0 == stat5minClientRequests()) {
static void
peerDnsRefreshCheck(void *)
{
if (!stat5minClientRequests()) {
/* no recent client traffic, wait a bit */
eventAddIsh("peerRefreshDNS", peerRefreshDNS, nullptr, 180.0, 1);
peerScheduleDnsRefreshCheck(180.0);
return;
}

peerDnsRefreshStart();
}

static void
peerDnsRefreshStart()
{
for (const auto &p: CurrentCachePeers())
ipcache_nbgethostbyname(p->host, peerDNSConfigure, p.get());

/* Reconfigure the peers every hour */
eventAddIsh("peerRefreshDNS", peerRefreshDNS, nullptr, 3600.0, 1);
peerScheduleDnsRefreshCheck(3600.0);
}

/// whether new TCP probes are currently banned
Expand Down