Software /
code /
prosody
Comparison
core/s2smanager.lua @ 1006:9166d7a8c3c0
core.s2smanager: Logging improvements
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Mon, 20 Apr 2009 22:13:09 +0100 |
parent | 995:a007d85b4045 |
child | 1007:c500d4cb7855 |
comparison
equal
deleted
inserted
replaced
1005:0eed5db7758d | 1006:9166d7a8c3c0 |
---|---|
103 else | 103 else |
104 log("debug", "opening a new outgoing connection for this stanza"); | 104 log("debug", "opening a new outgoing connection for this stanza"); |
105 local host_session = new_outgoing(from_host, to_host); | 105 local host_session = new_outgoing(from_host, to_host); |
106 -- Store in buffer | 106 -- Store in buffer |
107 host_session.sendq = { {tostring(data), st.reply(data)} }; | 107 host_session.sendq = { {tostring(data), st.reply(data)} }; |
108 if (not host_session.connecting) and (not host_session.conn) then destroy_session(host_session); end | 108 log("debug", "stanza [%s] queued until connection complete", tostring(data.name)); |
109 if (not host_session.connecting) and (not host_session.conn) then | |
110 log("warn", "Connection to %s failed already, destroying session...", to_host); | |
111 destroy_session(host_session); | |
112 end | |
109 end | 113 end |
110 end | 114 end |
111 | 115 |
112 local open_sessions = 0; | 116 local open_sessions = 0; |
113 | 117 |
144 function attempt_connection(host_session, err) | 148 function attempt_connection(host_session, err) |
145 local from_host, to_host = host_session.from_host, host_session.to_host; | 149 local from_host, to_host = host_session.from_host, host_session.to_host; |
146 local connect_host, connect_port = idna_to_ascii(to_host), 5269; | 150 local connect_host, connect_port = idna_to_ascii(to_host), 5269; |
147 | 151 |
148 if not err then -- This is our first attempt | 152 if not err then -- This is our first attempt |
153 log("debug", "First attempt to connect to %s, starting with SRV lookup...", to_host); | |
149 host_session.connecting = true; | 154 host_session.connecting = true; |
150 local answer = | 155 local answer = |
151 adns.lookup(function (answer) | 156 adns.lookup(function (answer) |
152 host_session.connecting = nil; | 157 host_session.connecting = nil; |
153 if answer then | 158 if answer then |
169 log("debug", to_host.." has no SRV records, falling back to A"); | 174 log("debug", to_host.." has no SRV records, falling back to A"); |
170 end | 175 end |
171 -- Try with SRV, or just the plain hostname if no SRV | 176 -- Try with SRV, or just the plain hostname if no SRV |
172 return try_connect(host_session, connect_host, connect_port); | 177 return try_connect(host_session, connect_host, connect_port); |
173 end, "_xmpp-server._tcp."..connect_host..".", "SRV"); | 178 end, "_xmpp-server._tcp."..connect_host..".", "SRV"); |
179 log("debug", "DNS lookup for %s sent, waiting for response before we can connect", to_host); | |
174 return true; -- Attempt in progress | 180 return true; -- Attempt in progress |
175 elseif host_session.srv_hosts and #host_session.srv_hosts > host_session.srv_choice then -- Not our first attempt, and we also have SRV | 181 elseif host_session.srv_hosts and #host_session.srv_hosts > host_session.srv_choice then -- Not our first attempt, and we also have SRV |
176 host_session.srv_choice = host_session.srv_choice + 1; | 182 host_session.srv_choice = host_session.srv_choice + 1; |
177 local srv_choice = host_session.srv_hosts[host_session.srv_choice]; | 183 local srv_choice = host_session.srv_hosts[host_session.srv_choice]; |
178 connect_host, connect_port = srv_choice.target or to_host, srv_choice.port or connect_port; | 184 connect_host, connect_port = srv_choice.target or to_host, srv_choice.port or connect_port; |
183 return false; | 189 return false; |
184 end | 190 end |
185 | 191 |
186 if not (connect_host and connect_port) then | 192 if not (connect_host and connect_port) then |
187 -- Likely we couldn't resolve DNS | 193 -- Likely we couldn't resolve DNS |
194 log("warn", "Hmm, we're without a host (%s) and port (%s) to connect to for %s, giving up :(", tostring(connect_host), tostring(connect_port), tostring(to_host)); | |
188 return false; | 195 return false; |
189 end | 196 end |
190 | 197 |
191 return try_connect(host_session, connect_host, connect_port); | 198 return try_connect(host_session, connect_host, connect_port); |
192 end | 199 end |
265 | 272 |
266 session.notopen = nil; | 273 session.notopen = nil; |
267 end | 274 end |
268 | 275 |
269 function streamclosed(session) | 276 function streamclosed(session) |
277 (session.log or log)("debug", "</stream:stream>"); | |
270 session.sends2s("</stream:stream>"); | 278 session.sends2s("</stream:stream>"); |
271 session.notopen = true; | 279 session.notopen = true; |
272 end | 280 end |
273 | 281 |
274 function initiate_dialback(session) | 282 function initiate_dialback(session) |