From: rousskov <> Date: Wed, 8 Apr 1998 05:44:17 +0000 (+0000) Subject: - added neighborsDigestSelect (under construction) X-Git-Tag: SQUID_3_0_PRE1~3599 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a54d3f8ee5bfd63457c720484031c789d7ef0052;p=thirdparty%2Fsquid.git - added neighborsDigestSelect (under construction) --- diff --git a/src/neighbors.cc b/src/neighbors.cc index e516ee0500..0b2d2845a7 100644 --- a/src/neighbors.cc +++ b/src/neighbors.cc @@ -1,6 +1,6 @@ /* - * $Id: neighbors.cc,v 1.193 1998/04/06 22:24:36 wessels Exp $ + * $Id: neighbors.cc,v 1.194 1998/04/07 23:44:17 rousskov Exp $ * * DEBUG: section 15 Neighbor Routines * AUTHOR: Harvest Derived @@ -547,6 +547,67 @@ neighborsUdpPing(request_t * request, return peers_pinged; } +peer * +neighborsDigestSelect(request_t * request, StoreEntry * entry) +{ + peer *best_p = NULL; +#if SQUID_PEER_DIGEST + const cache_key *key; + int best_rtt = 0; + int choice_count = 0; + int ichoice_count = 0; + peer *p; + int p_rtt; + int i; + + key = storeKeyPublic(storeUrl(entry), request->method); + for (i = 0, p = first_ping; i++ < Config.npeers; p = p->next) { + if (!p) + p = Config.peers; + if (i == 1) + first_ping = p; + debug(15, 5) ("neighborsDigestSelect: considering peer %s\n", p->host); + /* does the peeer have a valid digest? */ + if (EBIT_TEST(p->digest.flags, PD_DISABLED)) { + continue; + } else + if (EBIT_TEST(p->digest.flags, PD_USABLE)) { + ; + } else + if (!EBIT_TEST(p->digest.flags, PD_INITED)) { + peerDigestInit(p); + continue; + } else { + assert(EBIT_TEST(p->digest.flags, PD_REQUESTED)); + continue; + } + choice_count++; + debug(15, 5) ("neighborsDigestSelect: peer %s is a candidate\n", p->host); + assert(p->digest.cd); + /* does digest predict a hit? */ + if (!cacheDigestTest(p->digest.cd, key)) + continue; + p_rtt = netdbHostPeerRtt(request->host, p); + debug(15, 5) ("neighborsDigestSelect: peer %s says hit with rtt %d\n", + p->host, p_rtt); + /* is this peer better than others in terms of rtt ? */ + if (!best_p || (p_rtt && p_rtt < best_rtt)) { + best_p = p; + best_rtt = p_rtt; + if (p_rtt) /* informative choice (aka educated guess) */ + ichoice_count++; + debug(15, 4) ("neighborsDigestSelect: peer %s leads with rtt %d\n", + p->host, best_rtt); + } + } + debug(15, 5) ("neighborsDigestSelect: selected peer %s, rtt: %d\n", + best_p ? best_p->host : "", best_rtt); + request->hier.n_choices = choice_count; + request->hier.n_ichoices = ichoice_count; +#endif + return best_p; +} + static void neighborAlive(peer * p, const MemObject * mem, const icp_common_t * header) {