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