Revision: 14865
Author: adrian.chadd
Date: Sat Jul 9 01:39:23 2011
Log: Flip forward.c over to use the new commConnect() API.
This may be reverted later on if I decide it's the wrong way to go.
The big change here is that the FD is now created inside the src/comm2.c
routines and returned if successful. The forward code now doesn't create
FDs itself.
It also means that there aren't sockets hanging around which are waiting
for a DNS resolution pass to happen. That always annoyed me in Squid.
Things that work:
* Combination IPv4/IPv6 destination hosts - it simply tries each
entry in order that it's received in the ipcache struct
Things that don't work:
* setting the outbound address - since this can be v4 or v6,
both have to be passed into the new commConnect() API for now.
I'll worry about tidying that up later.
* Transparency - v4 or v6 transparency won't work
* Allowing the admin to choose whether v4 or v6 hosts are tried
first
* cache peers are still v4 only
http://code.google.com/p/lusca-cache/source/detail?r=14865
Modified:
/playpen/LUSCA_HEAD_ipv6/src/forward.c
/playpen/LUSCA_HEAD_ipv6/src/ftp.c
/playpen/LUSCA_HEAD_ipv6/src/gopher.c
/playpen/LUSCA_HEAD_ipv6/src/http.c
/playpen/LUSCA_HEAD_ipv6/src/whois.c
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/forward.c Sat Jul 2 20:40:06 2011
+++ /playpen/LUSCA_HEAD_ipv6/src/forward.c Sat Jul 9 01:39:23 2011
@@ -179,6 +179,9 @@
return 1;
}
+/*
+ * Called as part of the comm_close callbacks
+ */
static void
fwdServerClosed(int fd, void *data)
{
@@ -328,7 +331,19 @@
FwdServer *fs = fwdState->servers;
ErrorState *err;
request_t *request = fwdState->request;
- assert(fwdState->server_fd == server_fd);
+
+ /* Even if this is -1 - ie, an error */
+ fwdState->server_fd = server_fd;
+
+ /* Hack: add close handlers now if server_fd is valid */
+ if (server_fd != -1) {
+ if (fs->peer) {
+ fs->peer->stats.conn_open++;
+ comm_add_close_handler(server_fd, fwdPeerClosed, fs->peer);
+ }
+ comm_add_close_handler(server_fd, fwdServerClosed, fwdState);
+ }
+
if (Config.onoff.log_ip_on_direct && status != COMM_ERR_DNS &&
fs->code == HIER_DIRECT)
hierarchyNote(&fwdState->request->hier, fs->code,
fd_table[server_fd].ipaddrstr);
if (status == COMM_ERR_DNS) {
@@ -347,7 +362,8 @@
err = errorCon(ERR_DNS_FAIL, HTTP_GATEWAY_TIMEOUT, fwdState->request);
err->dnsserver_msg = xstrdup(dns_error_message);
fwdFail(fwdState, err);
- comm_close(server_fd);
+ assert(server_fd == -1);
+ fwdServerClosed(-1, fwdState);
} else if (status != COMM_OK) {
assert(fs);
err = errorCon(ERR_CONNECT_FAIL, HTTP_GATEWAY_TIMEOUT,
fwdState->request);
@@ -355,7 +371,8 @@
fwdFail(fwdState, err);
if (fs->peer)
peerConnectFailed(fs->peer);
- comm_close(server_fd);
+ assert(server_fd == -1);
+ fwdServerClosed(-1, fwdState);
} else {
debug(17, 3) ("fwdConnectDone: FD %d: '%s'\n", server_fd,
storeUrl(fwdState->entry));
#if USE_SSL
@@ -428,6 +445,11 @@
cbdataFree(idle);
}
+#warning This is v4 only? Tsk!
+
+/*
+ * Open IPv4 idle connections to peers
+ */
static void
openIdleConn(peer * peer, const char *domain, struct in_addr outgoing,
unsigned short tos, int ctimeout)
{
@@ -520,6 +542,7 @@
return r;
}
+#if 0
/*
* Create the outbound socket to the given forward server.
*
@@ -563,6 +586,7 @@
}
return fd;
}
+#endif
static void
fwdConnectStart(void *data)
@@ -570,7 +594,9 @@
FwdState *fwdState = data;
const char *url = storeUrl(fwdState->entry);
int fd = -1;
+#if 0
ErrorState *err;
+#endif
FwdServer *fs = fwdState->servers;
const char *host;
const char *name;
@@ -691,40 +717,34 @@
outgoing = getOutgoingAddr(fwdState->request);
tos = getOutgoingTOS(fwdState->request);
- fd = fwdConnectCreateSocket(fwdState, fs);
- if (fd < 0) {
- debug(50, 4) ("fwdConnectStart: %s\n", xstrerror());
- err = errorCon(ERR_SOCKET_FAILURE, HTTP_INTERNAL_SERVER_ERROR,
fwdState->request);
- err->xerrno = errno;
- fwdFail(fwdState, err);
- fwdStateFree(fwdState);
- return;
- }
- fwdState->server_fd = fd;
- fwdState->n_tries++;
- if (!fs->peer)
- fwdState->origin_tries++;
+ /* Make sure we're not trumping an existing FD */
+ assert(fwdState->server_fd == -1);
+
/*
- * stats.conn_open is used to account for the number of
- * connections that we have open to the peer, so we can limit
- * based on the max-conn option. We need to increment here,
- * even if the connection may fail.
+ * There's no FD at this point; so peer conn tracking
+ * and adding close handlers has to wait.
*/
- if (fs->peer) {
- fs->peer->stats.conn_open++;
- comm_add_close_handler(fd, fwdPeerClosed, fs->peer);
- }
- comm_add_close_handler(fd, fwdServerClosed, fwdState);
+
+ /*
+ * XXX there needs to be a connection timeout included
+ * in the new connection API
+ */
+
+ fwdState->n_tries++;
+#if 0
commSetTimeout(fd,
ctimeout,
fwdConnectTimeout,
fwdState);
+#endif
+
if (fs->peer) {
hierarchyNote(&fwdState->request->hier, fs->code, fs->peer->name);
} else {
hierarchyNote(&fwdState->request->hier, fs->code,
fwdState->request->host);
}
+#if 0
/*
* If we are retrying a transparent connection that is not being sent
to a
* peer, then don't cache, and use the IP that the client's DNS lookup
@@ -738,6 +758,15 @@
} else {
commConnectStart(fd, host, port, fwdConnectDone, fwdState, NULL);
}
+#endif
+
+#warning re-do the transparent stuff soon!
+ /*
+ * There's no outgoing address or local host support just yet, so
+ * there's no transparency support just yet.
+ */
+ commConnectStartNew(host, port, fwdConnectDone, fwdState,
+ NULL, 0, tos, url);
}
static void
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/ftp.c Sun Jul 4 06:56:53 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/ftp.c Sat Jul 9 01:39:23 2011
@@ -859,6 +859,7 @@
request_t *request = fwd->request;
StoreEntry *entry = fwd->entry;
int fd = fwd->server_fd;
+ assert(fd != -1); /* this meant the connect() hadn't finished yet */
LOCAL_ARRAY(char, realm, 8192);
const char *url = storeUrl(entry);
FtpStateData *ftpState;
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/gopher.c Sun Jul 4 06:56:53 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/gopher.c Sat Jul 9 01:39:23 2011
@@ -787,6 +787,7 @@
int fd = fwdState->server_fd;
StoreEntry *entry = fwdState->entry;
GopherStateData *gopherState;
+ assert(fd != -1); /* ie the connect() in forward.c succeeded */
CBDATA_INIT_TYPE(GopherStateData);
gopherState = cbdataAlloc(GopherStateData);
gopherState->buf = memAllocate(MEM_4K_BUF);
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/http.c Mon Sep 6 22:29:42 2010
+++ /playpen/LUSCA_HEAD_ipv6/src/http.c Sat Jul 9 01:39:23 2011
@@ -1767,6 +1767,7 @@
HttpStateData *httpState;
request_t *proxy_req;
request_t *orig_req = fwd->request;
+ assert(fd != -1); /* ie, the fwd connect() hadn't finished */
debug(11, 3) ("httpStart: \"%s %s\"\n",
urlMethodGetConstStr(orig_req->method),
storeUrl(fwd->entry));
CBDATA_INIT_TYPE(HttpStateData);
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/whois.c Fri Jan 9 15:06:08 2009
+++ /playpen/LUSCA_HEAD_ipv6/src/whois.c Sat Jul 9 01:39:23 2011
@@ -58,6 +58,7 @@
int fd = fwd->server_fd;
char *buf;
size_t l;
+ assert(fd != -1); /* ie, the connect() in forward.c succeeded */
CBDATA_INIT_TYPE(WhoisState);
p = cbdataAlloc(WhoisState);
p->request = fwd->request;
--
You received this message because you are subscribed to the Google Groups
"lusca-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/lusca-commit?hl=en.