--- /dev/null
+/*
+ * Copyright (C) 1996-2015 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#include "squid.h"
+#include "acl/Gadgets.h"
+#include "CachePeer.h"
+#include "CachePeerDomainList.h"
+#include "defines.h"
+#include "NeighborTypeDomainList.h"
+#include "pconn.h"
+#include "PeerPoolMgr.h"
+
+CBDATA_CLASS_INIT(CachePeer);
+
+CachePeer::CachePeer() :
+ index(0),
+ name(NULL),
+ host(NULL),
+ type(PEER_NONE),
+ http_port(CACHE_HTTP_PORT),
+ peer_domain(NULL),
+ typelist(NULL),
+ access(NULL),
+ weight(1),
+ basetime(0),
+#if USE_CACHE_DIGESTS
+ digest(NULL),
+ digest_url(NULL),
+#endif
+ tcp_up(0),
+ n_addresses(0),
+ rr_count(0),
+ next(NULL),
+ testing_now(false),
+ login(NULL),
+ connect_timeout(0),
+ connect_fail_limit(0),
+ max_conn(0),
+ domain(NULL),
+#if USE_OPENSSL
+ use_ssl(0),
+ sslcert(NULL),
+ sslkey(NULL),
+ sslversion(0),
+ ssloptions(NULL),
+ sslcipher(NULL),
+ sslcafile(NULL),
+ sslcapath(NULL),
+ sslcrlfile(NULL),
+ sslflags(NULL),
+ ssldomain(NULL),
+ sslContext(NULL),
+ sslSession(NULL),
+#endif
+ front_end_https(0),
+ connection_auth(2 /* auto */)
+{
+ memset(&stats, 0, sizeof(stats));
+ stats.logged_state = PEER_ALIVE;
+
+ memset(&icp, 0, sizeof(icp));
+ icp.port = CACHE_ICP_PORT;
+ icp.version = ICP_VERSION_CURRENT;
+
+#if USE_HTCP
+ memset(&htcp, 0, sizeof(htcp));
+#endif
+ memset(&options, 0, sizeof(options));
+ memset(&mcast, 0, sizeof(mcast));
+ memset(&carp, 0, sizeof(carp));
+#if USE_AUTH
+ memset(&userhash, 0, sizeof(userhash));
+#endif
+ memset(&sourcehash, 0, sizeof(sourcehash));
+
+ standby.pool = NULL;
+ standby.limit = 0;
+ standby.waitingForClose = false;
+}
+
+CachePeer::~CachePeer()
+{
+ xfree(name);
+ xfree(host);
+
+ while (CachePeerDomainList *l = peer_domain) {
+ peer_domain = l->next;
+ xfree(l->domain);
+ xfree(l);
+ }
+
+ while (NeighborTypeDomainList *l = typelist) {
+ typelist = l->next;
+ xfree(l->domain);
+ xfree(l);
+ }
+
+ aclDestroyAccessList(&access);
+
+#if USE_CACHE_DIGESTS
+ cbdataReferenceDone(digest);
+ xfree(digest_url);
+#endif
+
+ delete next;
+
+ xfree(login);
+
+ delete standby.pool;
+
+ // the mgr job will notice that its owner is gone and stop
+ PeerPoolMgr::Checkpoint(standby.mgr, "peer gone");
+
+ xfree(domain);
+
+#if USE_OPENSSL
+ xfree(sslcert);
+ xfree(sslkey);
+ xfree(ssloptions);
+ xfree(sslcipher);
+ xfree(sslcafile);
+ xfree(sslcapath);
+ xfree(sslcrlfile);
+ xfree(sslflags);
+ xfree(ssldomain);
+
+ if (sslContext)
+ SSL_CTX_free(sslContext);
+
+ if (sslSession)
+ SSL_SESSION_free(sslSession);
+#endif
+}
class PeerDigest;
class PeerPoolMgr;
-// currently a POD
class CachePeer
{
+ CBDATA_CLASS(CachePeer);
+
public:
+ CachePeer();
+ ~CachePeer();
+
u_int index;
char *name;
char *host;
cache_manager.cc \
NeighborTypeDomainList.h \
CachePeerDomainList.h \
+ CachePeer.cc \
CachePeer.h \
CacheManager.h \
carp.h \
YesNoNone.cc \
RefreshPattern.h \
cache_cf.cc \
+ CachePeer.cc \
+ CachePeer.h \
CacheDigest.h \
tests/stub_CacheDigest.cc \
carp.h \
YesNoNone.cc \
RefreshPattern.h \
cache_cf.cc \
+ CachePeer.cc \
+ CachePeer.h \
cache_manager.cc \
carp.h \
tests/stub_carp.cc \
YesNoNone.cc \
RefreshPattern.h \
cache_cf.cc \
+ CachePeer.cc \
+ CachePeer.h \
carp.h \
tests/stub_carp.cc \
cbdata.cc \
YesNoNone.cc \
RefreshPattern.h \
cache_cf.cc \
+ CachePeer.cc \
+ CachePeer.h \
cache_manager.cc \
CacheDigest.h \
tests/stub_CacheDigest.cc \
debug.cc \
CacheDigest.h \
tests/stub_CacheDigest.cc \
+ CachePeer.cc \
+ CachePeer.h \
carp.h \
tests/stub_carp.cc \
cbdata.cc \
tests/stub_cache_manager.cc \
CacheDigest.h \
tests/stub_CacheDigest.cc \
+ CachePeer.cc \
+ CachePeer.h \
carp.h \
tests/stub_carp.cc \
cbdata.cc \
static peer_t parseNeighborType(const char *s);
-CBDATA_TYPE(CachePeer);
-
static const char *const T_MILLISECOND_STR = "millisecond";
static const char *const T_SECOND_STR = "second";
static const char *const T_MINUTE_STR = "minute";
parse_peer(CachePeer ** head)
{
char *token = NULL;
- CachePeer *p;
- CBDATA_INIT_TYPE_FREECB(CachePeer, peerDestroy);
- p = cbdataAlloc(CachePeer);
- p->http_port = CACHE_HTTP_PORT;
- p->icp.port = CACHE_ICP_PORT;
- p->weight = 1;
- p->basetime = 0;
- p->stats.logged_state = PEER_ALIVE;
+ CachePeer *p = new CachePeer;
if ((token = ConfigParser::NextToken()) == NULL)
self_destruct();
self_destruct();
p->icp.port = GetUdpService();
- p->connection_auth = 2; /* auto */
while ((token = ConfigParser::NextToken())) {
if (!strcmp(token, "proxy-only")) {
if (p->connect_fail_limit < 1)
p->connect_fail_limit = 10;
- p->icp.version = ICP_VERSION_CURRENT;
-
- p->testing_now = false;
-
#if USE_CACHE_DIGESTS
if (!p->options.no_digest) {
static void
free_peer(CachePeer ** P)
{
- CachePeer *p;
-
- while ((p = *P) != NULL) {
- *P = p->next;
-#if USE_CACHE_DIGESTS
-
- cbdataReferenceDone(p->digest);
-#endif
-
- // the mgr job will notice that its owner is gone and stop
- PeerPoolMgr::Checkpoint(p->standby.mgr, "peer gone");
- delete p->standby.pool;
- cbdataFree(p);
- }
-
+ delete *P;
+ *P = NULL;
Config.npeers = 0;
}
if (p) {
*P = p->next;
- cbdataFree(p);
+ p->next = NULL;
+ delete p;
--Config.npeers;
}
}
if (np == NULL) {
- np = (CachePeer *)xcalloc(1, sizeof(CachePeer));
+ np = new CachePeer;
np->in_addr = from;
np->icp.port = from.port();
np->type = PEER_NONE;
return 1;
}
-void
-peerDestroy(void *data)
-{
- CachePeer *p = (CachePeer *)data;
-
- if (p == NULL)
- return;
-
- CachePeerDomainList *nl = NULL;
-
- for (CachePeerDomainList *l = p->peer_domain; l; l = nl) {
- nl = l->next;
- safe_free(l->domain);
- xfree(l);
- }
-
- safe_free(p->host);
- safe_free(p->name);
- safe_free(p->domain);
-#if USE_CACHE_DIGESTS
-
- cbdataReferenceDone(p->digest);
-#endif
-}
-
void
peerNoteDigestGone(CachePeer * p)
{
void peerNoteDigestLookup(HttpRequest * request, CachePeer * p, lookup_t lookup);
void peerNoteDigestGone(CachePeer * p);
int neighborUp(const CachePeer * e);
-CBDUNL peerDestroy;
const char *neighborTypeStr(const CachePeer * e);
peer_t neighborType(const CachePeer *, const HttpRequest *);
void peerConnectFailed(CachePeer *);
#endif
typedef void FREE(void *);
-typedef void CBDUNL(void *);
typedef void FOCB(void *, int fd, int errcode);
typedef void PF(int, void *);