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 #274

Closed
Closed
Changes from 2 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
32 changes: 22 additions & 10 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 peerScheduleDnsRefreshCheck(double);
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,33 @@ peerDNSConfigure(const ipcache_addrs *ia, const Dns::LookupDetails &, void *data
}

static void
peerRefreshDNS(void *data)
peerDnsRefreshStart()
{
if (eventFind(peerRefreshDNS, nullptr))
eventDelete(peerRefreshDNS, nullptr);
for (const auto &p: CurrentCachePeers())
ipcache_nbgethostbyname(p->host, peerDNSConfigure, p.get());

/* Reconfigure the peers every hour */

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's drop this misleading comment. This self-documented code is not reconfiguring cache_peers. The only problem here is that 3600.0 constant lacks "this is an hour" annotation, but that will be fixed when we migrate this code to std::chrono.

Suggested change
/* Reconfigure the peers every hour */

that will be fixed when we migrate this code to std::chrono

I do not think we should migrate in this PR, but we will migrate if others insist.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed.

peerScheduleDnsRefreshCheck(3600.0);
}

static void
peerDnsRefreshCheck(void *data)
{
if (!data && 0 == stat5minClientRequests()) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you are working on removing data from this condition and will come back to this PR after that is done.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

/* no recent client traffic, wait a bit */
eventAddIsh("peerRefreshDNS", peerRefreshDNS, nullptr, 180.0, 1);
peerScheduleDnsRefreshCheck(180.0);
return;
}

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

/* Reconfigure the peers every hour */
eventAddIsh("peerRefreshDNS", peerRefreshDNS, nullptr, 3600.0, 1);
static void
peerScheduleDnsRefreshCheck(const double delayInSeconds)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please try to move this up, where the old eventFind() was, to simplify the diff.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved.

{
if (eventFind(peerDnsRefreshCheck, nullptr))
eventDelete(peerDnsRefreshCheck, nullptr);
eventAddIsh("peerDnsRefreshCheck", peerDnsRefreshCheck, nullptr, delayInSeconds, 1);
}

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