/*
- * $Id: main.cc,v 1.110 1996/11/12 22:37:10 wessels Exp $
+ * $Id: main.cc,v 1.111 1996/11/13 06:52:24 wessels Exp $
*
* DEBUG: section 1 Startup and Main Loop
* AUTHOR: Harvest Derived
const char *const appname = "squid";
const char *const localhost = "127.0.0.1";
struct in_addr local_addr;
+struct in_addr no_addr;
+struct in_addr any_addr;
struct in_addr theOutICPAddr;
const char *const dash_str = "-";
const char *const null_string = "";
eventAdd("storePurgeOld", storePurgeOld, NULL, Config.cleanRate);
eventAdd("storeMaintain", storeMaintainSwapSpace, NULL, 1);
eventAdd("storeDirClean", storeDirClean, NULL, 15);
- eventAdd("send_announce", send_announce, NULL, 3600);
+ if (Config.Announce.on)
+ eventAdd("send_announce", send_announce, NULL, 3600);
eventAdd("ipcache_purgelru", (EVH) ipcache_purgelru, NULL, 10);
}
first_time = 0;
memset(&local_addr, '\0', sizeof(struct in_addr));
local_addr.s_addr = inet_addr(localhost);
+ memset(&any_addr, '\0', sizeof(struct in_addr));
+ any_addr.s_addr = inet_addr("0.0.0.0");
+ memset(&no_addr, '\0', sizeof(struct in_addr));
+ no_addr.s_addr = inet_addr("255.255.255.255");
errorInitialize();
/*
- * $Id: neighbors.cc,v 1.85 1996/11/12 22:37:11 wessels Exp $
+ * $Id: neighbors.cc,v 1.86 1996/11/13 06:52:25 wessels Exp $
*
* DEBUG: section 15 Neighbor Routines
* AUTHOR: Harvest Derived
static void neighborAlive _PARAMS((edge *, const MemObject *, const icp_common_t *));
static void neighborCountIgnored _PARAMS((edge * e, icp_opcode op_unused));
static neighbor_t parseNeighborType _PARAMS((const char *s));
-static void neighbors_init _PARAMS((void));
-static neighbors *friends = NULL;
static icp_common_t echo_hdr;
static u_short echo_port;
+static struct {
+ int n;
+ int n_parent;
+ int n_sibling;
+ edge *edges_head;
+ edge *edges_tail;
+ edge *first_ping;
+} friends = {
+
+ 0, 0, 0, NULL, NULL, NULL
+};
+
const char *hier_strings[] =
{
"NONE",
struct in_addr ip = from->sin_addr;
edge *e = NULL;
debug(15, 3, "whichEdge: from %s port %d\n", inet_ntoa(ip), port);
- for (e = friends->edges_head; e; e = e->next) {
+ for (e = friends.edges_head; e; e = e->next) {
for (j = 0; j < e->n_addresses; j++) {
if (ip.s_addr == e->addresses[j].s_addr && port == e->icp_port) {
return e;
edge *e = NULL;
int count = 0;
- if (n == NULL && friends->n_parent < 1)
+ if (n == NULL && friends.n_parent < 1)
return NULL;
- for (e = friends->edges_head; e; e = e->next) {
+ for (e = friends.edges_head; e; e = e->next) {
if (!edgeWouldBePinged(e, request))
continue;
count++;
getFirstUpParent(request_t * request)
{
edge *e = NULL;
- if (friends->n_parent < 1)
+ if (friends.n_parent < 1)
return NULL;
- for (e = friends->edges_head; e; e = e->next) {
+ for (e = friends.edges_head; e; e = e->next) {
if (!e->neighbor_up)
continue;
if (neighborType(e, request) != EDGE_PARENT)
edge *
getFirstEdge(void)
{
- return friends->edges_head;
+ return friends.edges_head;
}
static void
{
edge *e = NULL;
edge **E = NULL;
- e = friends->edges_head;
- E = &friends->edges_head;
+ e = friends.edges_head;
+ E = &friends.edges_head;
while (e) {
if (target == e)
break;
*E = e->next;
safe_free(e->host);
safe_free(e);
- friends->n--;
+ friends.n--;
}
}
debug(15, 3, "neighborsDestroy: called\n");
- for (e = friends->edges_head; e; e = next) {
+ for (e = friends.edges_head; e; e = next) {
next = e->next;
safe_free(e->host);
safe_free(e);
- friends->n--;
+ friends.n--;
}
- safe_free(friends);
- friends = NULL;
+ memset(&friends, '\0', sizeof(friends));
}
void
edge **E = NULL;
struct servent *sep = NULL;
- if (friends == NULL)
- neighbors_init();
memset(&name, '\0', sizeof(struct sockaddr_in));
if (getsockname(fd, (struct sockaddr *) &name, &len) < 0)
debug(15, 1, "getsockname(%d,%p,%p) failed.\n", fd, &name, &len);
/* Prepare neighbor connections, one at a time */
- E = &friends->edges_head;
- next = friends->edges_head;
+ E = &friends.edges_head;
+ next = friends.edges_head;
while ((e = next)) {
getCurrentTime();
next = e->next;
mem->w_rtt = 0;
mem->start_ping = current_time;
- if (friends->edges_head == NULL)
+ if (friends.edges_head == NULL)
return 0;
if (theOutIcpConnection < 0) {
debug(15, 0, "neighborsUdpPing: There is no ICP socket!\n");
debug(15, 0, "Check 'icp_port' in your config file\n");
fatal_dump(NULL);
}
- for (i = 0, e = friends->first_ping; i++ < friends->n; e = e->next) {
+ for (i = 0, e = friends.first_ping; i++ < friends.n; e = e->next) {
if (entry->swap_status != NO_SWAP)
fatal_dump("neighborsUdpPing: bad swap_status");
if (e == (edge *) NULL)
- e = friends->edges_head;
+ e = friends.edges_head;
debug(15, 5, "neighborsUdpPing: Edge %s\n", e->host);
/* skip any cache where we failed to connect() w/in the last 60s */
e->host, e->http_port, e->icp_port);
}
}
- friends->first_ping = e->next;
+ friends.first_ping = e->next;
}
/* only do source_ping if we have neighbors */
- if (friends->n) {
+ if (friends.n) {
if (!proto->source_ping) {
debug(15, 6, "neighborsUdpPing: Source Ping is disabled.\n");
} else if ((ia = ipcache_gethostbyname(host, IP_BLOCKING_LOOKUP))) {
{
edge *e = NULL;
const char *me = getMyHostname();
- if (friends == NULL)
- neighbors_init();
if (!strcmp(host, me) && http_port == Config.Port.http) {
- debug(15, 0, "neighbors_init: skipping cache_host %s %s/%d/%d\n",
+ debug(15, 0, "neighborAdd: skipping cache_host %s %s/%d/%d\n",
type, host, http_port, icp_port);
return;
}
e->icp_version = ICP_VERSION_CURRENT;
e->type = parseNeighborType(type);
if (e->type == EDGE_PARENT)
- friends->n_parent++;
+ friends.n_parent++;
else if (e->type == EDGE_SIBLING)
- friends->n_sibling++;
+ friends.n_sibling++;
/* Append edge */
- if (!friends->edges_head)
- friends->edges_head = e;
- if (friends->edges_tail)
- friends->edges_tail->next = e;
- friends->edges_tail = e;
- friends->n++;
+ if (!friends.edges_head)
+ friends.edges_head = e;
+ if (friends.edges_tail)
+ friends.edges_tail->next = e;
+ friends.edges_tail = e;
+ friends.n++;
}
void
*Tail = L;
}
-static void
-neighbors_init(void)
-{
- debug(15, 1, "neighbors_init: Initializing Neighbors...\n");
- if (friends == NULL)
- friends = xcalloc(1, sizeof(neighbors));
- any_addr.s_addr = inet_addr("0.0.0.0");
-}
-
edge *
neighborFindByName(const char *name)
{
edge *e = NULL;
- for (e = friends->edges_head; e; e = e->next) {
+ for (e = friends.edges_head; e; e = e->next) {
if (!strcasecmp(name, e->host))
break;
}