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