try next srv entries if first one fails

This commit is contained in:
psyc://psyced.org/~lynX 2011-05-03 10:09:38 +02:00
parent cefc6ccad9
commit 3709792118
2 changed files with 24 additions and 7 deletions

View File

@ -74,7 +74,16 @@ srv_choose(mixed *hostlist, string transport) {
return connect_failure("_failure_unavailable_service",
"No service offered by domain " + hostname);
}
return connect(srvhost, srvport, transport);
// we use other srv records for fallback..
// saga thinks we can use quote and pass an array into the lambda,
// but it works this way, too -fippo
string extra = "";
for (int i = 1; i < sizeof(hostlist); i++) {
extra += hostlist[i][DNS_SRV_NAME] +":"+
((string) hostlist[i][DNS_SRV_PORT]) + ";";
}
return connect(srvhost, srvport, transport, 0, extra);
}
#else
# echo Warning: No SRV enabled. Will not be able to talk to jabber.ccc.de etc.
@ -234,7 +243,7 @@ runQ() {
waitforme = CONNECT_RETRY;
}
connect(ho, po, transport, srv) {
connect(ho, po, transport, srv, extra) {
if (interactive()) return -8;
P3(("connect: %O, %O, %O, %O for %O\n", ho, po, transport, srv, ME))
if (time() < time_of_connect_attempt + waitforme) return -2;
@ -256,7 +265,7 @@ connect(ho, po, transport, srv) {
transport == "s" ? "tls" : "tcp", #'srv_choose,
transport);
#endif
if (::connect(host, port, transport) >= 0)
if (::connect(host, port, transport, extra) >= 0)
time_of_connect_attempt = time();
}

View File

@ -17,7 +17,7 @@ virtual inherit NET_PATH "trust";
volatile mixed is_connecting;
connect(host, port, transport);
connect(host, port, transport, srv, extra);
protected int block() { destruct(ME); return 0; }
@ -90,11 +90,19 @@ protected canonical_host(cane, ip, host) {
}
}
private connect2(ip, port, host) {
private connect2(ip, port, host, extra) {
int rc;
P3(("%O connect2(%O, %O, %O) == %O\n", ME, ip, port, host, chost(ip)))
unless (stringp(ip)) {
if (sizeof(extra) && stringp(extra)) {
if (sscanf(extra, "%s:%d;%s", host, port, extra) == 3) {
P3(("fallback: %s:%d, other %O\n", host, port, extra))
is_connecting = 0;
call_out(#'connect, 10, host, port, 1, extra == "" ? 0 : extra);
return;
}
}
connect_failure("_resolve", host+" does not resolve");
return;
}
@ -154,7 +162,7 @@ Driver does not provide net_connect()\n", ME, ip, port, host))
if (ME && !chost(ip)) dns_rresolve(ip, #'canonical_host, ip, host);
}
connect(host, port, transport) {
connect(host, port, transport, extra) {
P4(("%O connect:connect(%O, %O, %O)\n", ME, host,port,transport))
if (interactive() || !host || !port || is_connecting) return -8;
is_connecting = transport || 1;
@ -162,7 +170,7 @@ connect(host, port, transport) {
host,port,transport))
// even on reconnect we don't cache the dns host data as it
// may be a dynamic dns host currently rebooting..
dns_resolve(host, #'connect2, port, host);
dns_resolve(host, #'connect2, port, host, extra);
return 0;
}