Comparison

core/s2smanager.lua @ 1075:831c84cbf5fa

s2smanager: Miscellaneous logging improvements, changing levels, improving messages and using session loggers where possible
author Matthew Wild <mwild1@gmail.com>
date Thu, 30 Apr 2009 02:43:12 +0100
parent 1007:c500d4cb7855
child 1199:db2a55fe94f2
comparison
equal deleted inserted replaced
1074:7798735be42b 1075:831c84cbf5fa
46 local function compare_srv_priorities(a,b) return a.priority < b.priority or a.weight < b.weight; end 46 local function compare_srv_priorities(a,b) return a.priority < b.priority or a.weight < b.weight; end
47 47
48 local function bounce_sendq(session) 48 local function bounce_sendq(session)
49 local sendq = session.sendq; 49 local sendq = session.sendq;
50 if sendq then 50 if sendq then
51 session.log("debug", "sending error replies for "..#sendq.." queued stanzas because of failed outgoing connection to "..tostring(session.to_host)); 51 session.log("info", "sending error replies for "..#sendq.." queued stanzas because of failed outgoing connection to "..tostring(session.to_host));
52 local dummy = { 52 local dummy = {
53 type = "s2sin"; 53 type = "s2sin";
54 send = function(s) 54 send = function(s)
55 (session.log or log)("error", "Replying to to an s2s error reply, please report this! Traceback: %s", get_traceback()); 55 (session.log or log)("error", "Replying to to an s2s error reply, please report this! Traceback: %s", get_traceback());
56 end; 56 end;
197 return true; -- Attempt in progress 197 return true; -- Attempt in progress
198 elseif host_session.srv_hosts and #host_session.srv_hosts > host_session.srv_choice then -- Not our first attempt, and we also have SRV 198 elseif host_session.srv_hosts and #host_session.srv_hosts > host_session.srv_choice then -- Not our first attempt, and we also have SRV
199 host_session.srv_choice = host_session.srv_choice + 1; 199 host_session.srv_choice = host_session.srv_choice + 1;
200 local srv_choice = host_session.srv_hosts[host_session.srv_choice]; 200 local srv_choice = host_session.srv_hosts[host_session.srv_choice];
201 connect_host, connect_port = srv_choice.target or to_host, srv_choice.port or connect_port; 201 connect_host, connect_port = srv_choice.target or to_host, srv_choice.port or connect_port;
202 host_session.log("debug", "Connection failed (%s). Attempt #%d: This time to %s:%d", tostring(err), host_session.srv_choice, connect_host, connect_port); 202 host_session.log("info", "Connection failed (%s). Attempt #%d: This time to %s:%d", tostring(err), host_session.srv_choice, connect_host, connect_port);
203 else 203 else
204 host_session.log("debug", "Out of connection options, can't connect to %s", tostring(host_session.to_host)); 204 host_session.log("info", "Out of connection options, can't connect to %s", tostring(host_session.to_host));
205 -- We're out of options 205 -- We're out of options
206 return false; 206 return false;
207 end 207 end
208 208
209 if not (connect_host and connect_port) then 209 if not (connect_host and connect_port) then
214 214
215 return try_connect(host_session, connect_host, connect_port); 215 return try_connect(host_session, connect_host, connect_port);
216 end 216 end
217 217
218 function try_connect(host_session, connect_host, connect_port) 218 function try_connect(host_session, connect_host, connect_port)
219 log("debug", "Beginning new connection attempt to %s (%s:%d)", host_session.to_host, connect_host, connect_port); 219 host_session.log("info", "Beginning new connection attempt to %s (%s:%d)", host_session.to_host, connect_host, connect_port);
220 -- Ok, we're going to try to connect 220 -- Ok, we're going to try to connect
221 221
222 local from_host, to_host = host_session.from_host, host_session.to_host; 222 local from_host, to_host = host_session.from_host, host_session.to_host;
223 223
224 local conn, handler = socket.tcp() 224 local conn, handler = socket.tcp()
336 elseif session.type == "s2sin" and host then 336 elseif session.type == "s2sin" and host then
337 session.hosts[host].authed = true; 337 session.hosts[host].authed = true;
338 else 338 else
339 return false; 339 return false;
340 end 340 end
341 session.log("info", "connection is now authenticated"); 341 session.log("debug", "connection %s->%s is now authenticated", session.from_host or "(unknown)", session.to_host or "(unknown)");
342 342
343 mark_connected(session); 343 mark_connected(session);
344 344
345 return true; 345 return true;
346 end 346 end
348 function mark_connected(session) 348 function mark_connected(session)
349 local sendq, send = session.sendq, session.sends2s; 349 local sendq, send = session.sendq, session.sends2s;
350 350
351 local from, to = session.from_host, session.to_host; 351 local from, to = session.from_host, session.to_host;
352 352
353 session.log("debug", session.direction.." s2s connection "..from.."->"..to.." is now complete"); 353 session.log("info", session.direction.." s2s connection "..from.."->"..to.." complete");
354 354
355 local send_to_host = send_to_host; 355 local send_to_host = send_to_host;
356 function session.send(data) send_to_host(to, from, data); end 356 function session.send(data) send_to_host(to, from, data); end
357 357
358 358