Comparison

core/s2smanager.lua @ 1791:42d0b68a1efd

s2smanager: Pass A-record lookups through adns module
author Matthew Wild <mwild1@gmail.com>
date Sat, 19 Sep 2009 17:40:19 +0100
parent 1523:841d61be198f
child 1792:407f282f559e
child 1793:1fc6c2822e6b
comparison
equal deleted inserted replaced
1787:c4dff34f3d32 1791:42d0b68a1efd
171 local connect_host, connect_port = idna_to_ascii(to_host), 5269; 171 local connect_host, connect_port = idna_to_ascii(to_host), 5269;
172 172
173 if not err then -- This is our first attempt 173 if not err then -- This is our first attempt
174 log("debug", "First attempt to connect to %s, starting with SRV lookup...", to_host); 174 log("debug", "First attempt to connect to %s, starting with SRV lookup...", to_host);
175 host_session.connecting = true; 175 host_session.connecting = true;
176 local answer, handle; 176 local handle;
177 handle = adns.lookup(function (answer) 177 handle = adns.lookup(function (answer)
178 handle = nil; 178 handle = nil;
179 host_session.connecting = nil; 179 host_session.connecting = nil;
180 if answer then 180 if answer then
181 log("debug", to_host.." has SRV records, handling..."); 181 log("debug", to_host.." has SRV records, handling...");
233 233
234 return try_connect(host_session, connect_host, connect_port); 234 return try_connect(host_session, connect_host, connect_port);
235 end 235 end
236 236
237 function try_connect(host_session, connect_host, connect_port) 237 function try_connect(host_session, connect_host, connect_port)
238 host_session.connecting = true;
239 local handle;
240 handle = adns.lookup(function (reply)
241 handle = nil;
242 host_session.connecting = nil;
243 if reply and reply[1] and reply[1].a then
244 log("debug", "DNS reply for %s gives us %s", connect_host, reply[1].a);
245 return make_connect(host_session, reply[1].a, connect_port);
246 else
247 log("debug", "DNS lookup failed to get a response for %s", connect_host);
248 if not attempt_connection(host_session, "name resolution failed") then -- Retry if we can
249 log("debug", "No other records to try for %s - destroying", host_session.to_host);
250 destroy_session(host_session); -- End of the line, we can't
251 end
252 end
253 end, connect_host, "A", "IN");
254
255 -- Set handler for DNS timeout
256 add_task(dns_timeout, function ()
257 if handle then
258 adns.cancel(handle, true);
259 end
260 end);
261
262 return true;
263 end
264
265 function make_connect(host_session, connect_host, connect_port)
238 host_session.log("info", "Beginning new connection attempt to %s (%s:%d)", host_session.to_host, connect_host, connect_port); 266 host_session.log("info", "Beginning new connection attempt to %s (%s:%d)", host_session.to_host, connect_host, connect_port);
239 -- Ok, we're going to try to connect 267 -- Ok, we're going to try to connect
240 268
241 local from_host, to_host = host_session.from_host, host_session.to_host; 269 local from_host, to_host = host_session.from_host, host_session.to_host;
242 270