Skip to content

Commit

Permalink
Refactor peerRefreshDNS() to clarify its (void*)1 logic (#1950)
Browse files Browse the repository at this point in the history
Creating a raw pointer with 1 as an address/value raised red flags, and
it was difficult to interpret tricky peerRefreshDNS() logic correctly.
  • Loading branch information
eduard-bagdasaryan authored and squid-anubis committed Nov 20, 2024
1 parent 22b2a7a commit dd3292c
Showing 1 changed file with 20 additions and 9 deletions.
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

0 comments on commit dd3292c

Please sign in to comment.