/*
- * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+ * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
*
* Squid software is distributed under GPLv2+ license and includes
* contributions from numerous individuals and organizations.
#include "squid.h"
#include "acl/FilledChecklist.h"
#include "anyp/PortCfg.h"
+#include "base/EnumIterator.h"
#include "CacheDigest.h"
#include "CachePeer.h"
#include "comm/Connection.h"
static void neighborCountIgnored(CachePeer *);
static void peerRefreshDNS(void *);
static IPH peerDNSConfigure;
-static bool peerProbeConnect(CachePeer *);
+static void peerProbeConnect(CachePeer *, const bool reprobeIfBusy = false);
static CNCB peerProbeConnectDone;
static void peerCountMcastPeersDone(void *data);
static void peerCountMcastPeersStart(void *data);
}
peer_t
-neighborType(const CachePeer * p, const HttpRequest * request)
+neighborType(const CachePeer * p, const URL &url)
{
const NeighborTypeDomainList *d = NULL;
for (d = p->typelist; d; d = d->next) {
- if (0 == matchDomainName(request->GetHost(), d->domain))
+ if (0 == matchDomainName(url.host(), d->domain))
if (d->type != PEER_NONE)
return d->type;
}
assert(request != NULL);
- if (neighborType(p, request) == PEER_SIBLING) {
+ if (neighborType(p, request->url) == PEER_SIBLING) {
#if PEER_MULTICAST_SIBLINGS
if (p->type == PEER_MULTICAST && p->options.mcast_siblings &&
(request->flags.noCache || request->flags.refresh || request->flags.loopDetected || request->flags.needValidation))
- debugs(15, 2, "peerAllowedToUse(" << p->name << ", " << request->GetHost() << ") : multicast-siblings optimization match");
+ debugs(15, 2, "peerAllowedToUse(" << p->name << ", " << request->url.authority() << ") : multicast-siblings optimization match");
#endif
if (request->flags.noCache)
return false;
// CONNECT requests are proxy requests. Not to be forwarded to origin servers.
// Unless the destination port matches, in which case we MAY perform a 'DIRECT' to this CachePeer.
- if (p->options.originserver && request->method == Http::METHOD_CONNECT && request->port != p->in_addr.port())
+ if (p->options.originserver && request->method == Http::METHOD_CONNECT && request->url.port() != p->http_port)
return false;
if (p->access == NULL)
if (!neighborUp(p))
continue;
- if (neighborType(p, request) != PEER_PARENT)
+ if (neighborType(p, request->url) != PEER_PARENT)
continue;
if (!peerHTTPOkay(p, request))
if (!p->options.roundrobin)
continue;
- if (neighborType(p, request) != PEER_PARENT)
+ if (neighborType(p, request->url) != PEER_PARENT)
continue;
if (!peerHTTPOkay(p, request))
if (!p->options.weighted_roundrobin)
continue;
- if (neighborType(p, request) != PEER_PARENT)
+ if (neighborType(p, request->url) != PEER_PARENT)
continue;
if (!peerHTTPOkay(p, request))
if (!p->options.weighted_roundrobin)
continue;
- if (neighborType(p, request) != PEER_PARENT)
+ if (neighborType(p, request->url) != PEER_PARENT)
continue;
p->rr_count = 0;
CachePeer *p = NULL;
for (p = Config.peers; p; p = p->next) {
- if (neighborType(p, request) != PEER_PARENT)
+ if (neighborType(p, request->url) != PEER_PARENT)
continue;
if (!p->options.default_parent)
} else if (neighborUp(p)) {
/* its alive, expect a reply from it */
- if (neighborType(p, request) == PEER_PARENT) {
+ if (neighborType(p, request->url) == PEER_PARENT) {
++parent_exprep;
parent_timeout += p->stats.rtt;
} else {
assert(p->digest->cd);
/* does digest predict a hit? */
- if (!cacheDigestTest(p->digest->cd, key))
+ if (!p->digest->cd->contains(key))
return LOOKUP_MISS;
debugs(15, 5, "peerDigestLookup: peer " << p->host << " says HIT!");
if (!p->options.mcast_responder)
return 0;
- if (peerHTTPOkay(p, mem->request))
+ if (peerHTTPOkay(p, mem->request.getRaw()))
return 0;
return 1;
debugs(15, 3, "neighborsUdpAck: " << opcode_d << " for '" << storeKeyText(key) << "' from " << (p ? p->host : "source") << " ");
if (p) {
- ntype = neighborType(p, mem->request);
+ ntype = neighborType(p, mem->request->url);
}
if (ignoreMulticastReply(p, mem)) {
neighborUp(const CachePeer * p)
{
if (!p->tcp_up) {
- if (!peerProbeConnect((CachePeer *) p)) {
- debugs(15, 8, "neighborUp: DOWN (probed): " << p->host << " (" << p->in_addr << ")");
- return 0;
- }
+ peerProbeConnect(const_cast<CachePeer*>(p));
+ return 0;
}
/*
#endif
}
+/// \returns the effective connect timeout for this peer
+time_t
+peerConnectTimeout(const CachePeer *peer)
+{
+ return peer->connect_timeout_raw > 0 ?
+ peer->connect_timeout_raw : Config.Timeout.peer_connect;
+}
+
+time_t
+positiveTimeout(const time_t timeout)
+{
+ return max(static_cast<time_t>(1), timeout);
+}
+
static void
peerDNSConfigure(const ipcache_addrs *ia, const Dns::LookupDetails &, void *data)
{
return;
}
- p->tcp_up = p->connect_fail_limit;
-
for (j = 0; j < (int) ia->count && j < PEER_MAX_ADDRESSES; ++j) {
p->addresses[j] = ia->in_addrs[j];
debugs(15, 2, "--> IP address #" << j << ": " << p->addresses[j]);
p->in_addr = p->addresses[0];
p->in_addr.port(p->icp.port);
+ peerProbeConnect(p, true); // detect any died or revived peers ASAP
+
if (p->type == PEER_MULTICAST)
peerCountMcastPeersSchedule(p, 10);
p->tcp_up = p->connect_fail_limit;
}
+/// whether new TCP probes are currently banned
+static bool
+peerProbeIsBusy(const CachePeer *p)
+{
+ if (p->testing_now > 0) {
+ debugs(15, 8, "yes, probing " << p);
+ return true;
+ }
+ if (squid_curtime - p->stats.last_connect_probe == 0) {
+ debugs(15, 8, "yes, just probed " << p);
+ return true;
+ }
+ return false;
+}
/*
* peerProbeConnect will be called on dead peers by neighborUp
*/
-static bool
-peerProbeConnect(CachePeer * p)
+static void
+peerProbeConnect(CachePeer *p, const bool reprobeIfBusy)
{
- time_t ctimeout = p->connect_timeout > 0 ? p->connect_timeout : Config.Timeout.peer_connect;
- bool ret = (squid_curtime - p->stats.last_connect_failure) > (ctimeout * 10);
-
- if (p->testing_now > 0)
- return ret;/* probe already running */
-
- if (squid_curtime - p->stats.last_connect_probe == 0)
- return ret;/* don't probe to often */
+ if (peerProbeIsBusy(p)) {
+ p->reprobe = reprobeIfBusy;
+ return;
+ }
+ p->reprobe = false;
+ const time_t ctimeout = peerConnectTimeout(p);
/* for each IP address of this CachePeer. find one that we can connect to and probe it. */
for (int i = 0; i < p->n_addresses; ++i) {
Comm::ConnectionPointer conn = new Comm::Connection;
}
p->stats.last_connect_probe = squid_curtime;
-
- return ret;
}
static void
-- p->testing_now;
conn->close();
// TODO: log this traffic.
+
+ if (p->reprobe)
+ peerProbeConnect(p);
}
static void
static void
peerCountMcastPeersStart(void *data)
{
+ // XXX: Do not create lots of complex fake objects (while abusing their
+ // APIs) to pass around a few basic data points like start_ping and ping!
CachePeer *p = (CachePeer *)data;
ps_state *psstate;
StoreEntry *fake;
p->in_addr.toUrl(url+7, MAX_URL -8 );
strcat(url, "/");
fake = storeCreateEntry(url, url, RequestFlags(), Http::METHOD_GET);
- HttpRequest *req = HttpRequest::CreateFromUrl(url);
- psstate = new ps_state;
+ const MasterXaction::Pointer mx = new MasterXaction(XactionInitiator::initPeerMcast);
+ HttpRequest *req = HttpRequest::FromUrl(url, mx);
+ psstate = new ps_state(nullptr);
psstate->request = req;
HTTPMSGLOCK(psstate->request);
psstate->entry = fake;
- psstate->callback = NULL;
- psstate->callback_data = cbdataReference(p);
+ psstate->peerCountMcastPeerXXX = cbdataReference(p);
psstate->ping.start = current_time;
mem = fake->mem_obj;
mem->request = psstate->request;
- HTTPMSGLOCK(mem->request);
mem->start_ping = current_time;
mem->ping_reply_callback = peerCountHandleIcpReply;
mem->ircb_data = psstate;
ps_state *psstate = (ps_state *)data;
StoreEntry *fake = psstate->entry;
- if (cbdataReferenceValid(psstate->callback_data)) {
- CachePeer *p = (CachePeer *)psstate->callback_data;
+ if (cbdataReferenceValid(psstate->peerCountMcastPeerXXX)) {
+ CachePeer *p = (CachePeer *)psstate->peerCountMcastPeerXXX;
p->mcast.flags.counting = false;
p->mcast.avg_n_members = Math::doubleAverage(p->mcast.avg_n_members, (double) psstate->ping.n_recv, ++p->mcast.n_times_counted, 10);
debugs(15, DBG_IMPORTANT, "Group " << p->host << ": " << psstate->ping.n_recv <<
p->mcast.n_replies_expected = (int) p->mcast.avg_n_members;
}
- cbdataReferenceDone(psstate->callback_data);
+ cbdataReferenceDone(psstate->peerCountMcastPeerXXX);
fake->abort(); // sets ENTRY_ABORTED and initiates releated cleanup
- HTTPMSGUNLOCK(fake->mem_obj->request);
+ fake->mem_obj->request = nullptr;
fake->unlock("peerCountMcastPeersDone");
delete psstate;
}
if (p->options.htcp) {
storeAppendPrintf(sentry, " htcp");
if (p->options.htcp_oldsquid || p->options.htcp_no_clr || p->options.htcp_no_purge_clr || p->options.htcp_only_clr) {
- int doneopts=0;
- if (p->options.htcp_oldsquid)
- storeAppendPrintf(sentry, "%soldsquid",(doneopts++>0?",":"="));
- if (p->options.htcp_no_clr)
- storeAppendPrintf(sentry, "%sno-clr",(doneopts++>0?",":"="));
- if (p->options.htcp_no_purge_clr)
- storeAppendPrintf(sentry, "%sno-purge-clr",(doneopts++>0?",":"="));
- if (p->options.htcp_only_clr)
- storeAppendPrintf(sentry, "%sonly-clr",(doneopts++>0?",":"="));
+ bool doneopts = false;
+ if (p->options.htcp_oldsquid) {
+ storeAppendPrintf(sentry, "oldsquid");
+ doneopts = true;
+ }
+ if (p->options.htcp_no_clr) {
+ storeAppendPrintf(sentry, "%sno-clr",(doneopts?",":"="));
+ doneopts = true;
+ }
+ if (p->options.htcp_no_purge_clr) {
+ storeAppendPrintf(sentry, "%sno-purge-clr",(doneopts?",":"="));
+ doneopts = true;
+ }
+ if (p->options.htcp_only_clr) {
+ storeAppendPrintf(sentry, "%sonly-clr",(doneopts?",":"="));
+ //doneopts = true; // uncomment if more opts are added
+ }
}
}
#endif
if (p->mcast.ttl > 0)
storeAppendPrintf(sentry, " ttl=%d", p->mcast.ttl);
- if (p->connect_timeout > 0)
- storeAppendPrintf(sentry, " connect-timeout=%d", (int) p->connect_timeout);
+ if (p->connect_timeout_raw > 0)
+ storeAppendPrintf(sentry, " connect-timeout=%d", (int)p->connect_timeout_raw);
if (p->connect_fail_limit != PEER_TCP_MAGIC_COUNT)
storeAppendPrintf(sentry, " connect-fail-limit=%d", p->connect_fail_limit);
else if (p->connection_auth == 2)
storeAppendPrintf(sentry, " connection-auth=auto");
+ p->secure.dumpCfg(sentry,"tls-");
storeAppendPrintf(sentry, "\n");
}
dump_peers(StoreEntry * sentry, CachePeer * peers)
{
char ntoabuf[MAX_IPSTRLEN];
- icp_opcode op;
int i;
if (peers == NULL)
} else {
#endif
- for (op = ICP_INVALID; op < ICP_END; ++op) {
+ for (auto op : WholeEnum<icp_opcode>()) {
if (e->icp.counts[op] == 0)
continue;
}
if (p) {
- ntype = neighborType(p, mem->request);
+ ntype = neighborType(p, mem->request->url);
neighborUpdateRtt(p, mem);
}