From 37097921189f4aa7fd1cdb0b6c2daf5f5af052fd Mon Sep 17 00:00:00 2001 From: "psyc://psyced.org/~lynX" <@> Date: Tue, 3 May 2011 10:09:38 +0200 Subject: [PATCH] try next srv entries if first one fails --- world/net/circuit.c | 15 ++++++++++++--- world/net/connect.c | 16 ++++++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/world/net/circuit.c b/world/net/circuit.c index 4aba1d2..ff9eded 100644 --- a/world/net/circuit.c +++ b/world/net/circuit.c @@ -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(); } diff --git a/world/net/connect.c b/world/net/connect.c index 34c70e2..d9ab916 100644 --- a/world/net/connect.c +++ b/world/net/connect.c @@ -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; }