252 handle = adns.lookup(function (reply) |
252 handle = adns.lookup(function (reply) |
253 handle = nil; |
253 handle = nil; |
254 host_session.connecting = nil; |
254 host_session.connecting = nil; |
255 |
255 |
256 -- COMPAT: This is a compromise for all you CNAME-(ab)users :) |
256 -- COMPAT: This is a compromise for all you CNAME-(ab)users :) |
257 if not (reply and reply[1] and reply[1].a) then |
257 if not (reply and reply[#reply] and reply[#reply].a) then |
258 local count = max_dns_depth; |
258 local count = max_dns_depth; |
259 reply = dns.peek(connect_host, "CNAME", "IN"); |
259 reply = dns.peek(connect_host, "CNAME", "IN"); |
260 while count > 0 and reply and reply[1] and not reply[1].a and reply[1].cname do |
260 while count > 0 and reply and reply[#reply] and not reply[#reply].a and reply[#reply].cname do |
261 log("debug", "Looking up %s (DNS depth is %d)", tostring(reply[1].cname), count); |
261 log("debug", "Looking up %s (DNS depth is %d)", tostring(reply[#reply].cname), count); |
262 reply = dns.peek(reply[1].cname, "A", "IN") or dns.peek(reply[1].cname, "CNAME", "IN"); |
262 reply = dns.peek(reply[#reply].cname, "A", "IN") or dns.peek(reply[#reply].cname, "CNAME", "IN"); |
263 count = count - 1; |
263 count = count - 1; |
264 end |
264 end |
265 end |
265 end |
266 -- end of CNAME resolving |
266 -- end of CNAME resolving |
267 |
267 |
268 if reply and reply[1] and reply[1].a then |
268 if reply and reply[#reply] and reply[#reply].a then |
269 log("debug", "DNS reply for %s gives us %s", connect_host, reply[1].a); |
269 log("debug", "DNS reply for %s gives us %s", connect_host, reply[#reply].a); |
270 return make_connect(host_session, reply[1].a, connect_port); |
270 return make_connect(host_session, reply[#reply].a, connect_port); |
271 else |
271 else |
272 log("debug", "DNS lookup failed to get a response for %s", connect_host); |
272 log("debug", "DNS lookup failed to get a response for %s", connect_host); |
273 if not attempt_connection(host_session, "name resolution failed") then -- Retry if we can |
273 if not attempt_connection(host_session, "name resolution failed") then -- Retry if we can |
274 log("debug", "No other records to try for %s - destroying", host_session.to_host); |
274 log("debug", "No other records to try for %s - destroying", host_session.to_host); |
275 destroy_session(host_session); -- End of the line, we can't |
275 destroy_session(host_session); -- End of the line, we can't |