comparison mod_smacks/mod_smacks.lua @ 2623:a65260300708

mod_smacks: Made module more error resistant
author tmolitor <thilo@eightysoft.de>
date Wed, 15 Mar 2017 16:21:55 +0100
parents 362ca94192ee
children c110b6bfe5d1
comparison
equal deleted inserted replaced
2622:ac3ca6233ded 2623:a65260300708
211 session_registry.set(session.username, session.resumption_token, nil); 211 session_registry.set(session.username, session.resumption_token, nil);
212 old_session_registry.set(session.username, session.resumption_token, nil); 212 old_session_registry.set(session.username, session.resumption_token, nil);
213 session.resumption_token = nil; 213 session.resumption_token = nil;
214 end 214 end
215 -- send out last ack as per revision 1.5.2 of XEP-0198 215 -- send out last ack as per revision 1.5.2 of XEP-0198
216 if session.smacks then 216 if session.smacks and session.conn then
217 (session.sends2s or session.send)(st.stanza("a", { xmlns = session.smacks, h = tostring(session.handled_stanza_count) })); 217 (session.sends2s or session.send)(st.stanza("a", { xmlns = session.smacks, h = tostring(session.handled_stanza_count) }));
218 end 218 end
219 return session_close(...); 219 return session_close(...);
220 end 220 end
221 return session; 221 return session;
407 session.log("debug", "Session resumed before hibernation timeout, all is well") 407 session.log("debug", "Session resumed before hibernation timeout, all is well")
408 end 408 end
409 end); 409 end);
410 return true; -- Postpone destruction for now 410 return true; -- Postpone destruction for now
411 end 411 end
412
413 end 412 end
414 end); 413 end);
415 414
416 local function handle_s2s_destroyed(event) 415 local function handle_s2s_destroyed(event)
417 local session = event.session; 416 local session = event.session;
468 conn:close(); 467 conn:close();
469 end 468 end
470 original_session.ip = session.ip; 469 original_session.ip = session.ip;
471 original_session.conn = session.conn; 470 original_session.conn = session.conn;
472 original_session.send = session.send; 471 original_session.send = session.send;
472 original_session.close = session.close;
473 original_session.filter = session.filter; 473 original_session.filter = session.filter;
474 original_session.filter.session = original_session; 474 original_session.filter.session = original_session;
475 original_session.filters = session.filters; 475 original_session.filters = session.filters;
476 original_session.stream = session.stream; 476 original_session.stream = session.stream;
477 original_session.secure = session.secure; 477 original_session.secure = session.secure;
480 -- Inform xmppstream of the new session (passed to its callbacks) 480 -- Inform xmppstream of the new session (passed to its callbacks)
481 original_session.stream:set_session(original_session); 481 original_session.stream:set_session(original_session);
482 -- Similar for connlisteners 482 -- Similar for connlisteners
483 c2s_sessions[session.conn] = original_session; 483 c2s_sessions[session.conn] = original_session;
484 484
485 session.send(st.stanza("resumed", { xmlns = xmlns_sm, 485 original_session.send(st.stanza("resumed", { xmlns = xmlns_sm,
486 h = original_session.handled_stanza_count, previd = id })); 486 h = original_session.handled_stanza_count, previd = id }));
487 487
488 -- Fake an <a> with the h of the <resume/> from the client 488 -- Fake an <a> with the h of the <resume/> from the client
489 original_session:dispatch_stanza(st.stanza("a", { xmlns = xmlns_sm, 489 original_session:dispatch_stanza(st.stanza("a", { xmlns = xmlns_sm,
490 h = stanza.attr.h })); 490 h = stanza.attr.h }));
491 491
492 -- Ok, we need to re-send any stanzas that the client didn't see 492 -- Ok, we need to re-send any stanzas that the client didn't see
493 -- ...they are what is now left in the outgoing stanza queue 493 -- ...they are what is now left in the outgoing stanza queue
494 local queue = original_session.outgoing_stanza_queue; 494 local queue = original_session.outgoing_stanza_queue;
495 module:fire_event("smacks-hibernation-end", {origin = session, resumed = original_session, queue = queue}); 495 module:fire_event("smacks-hibernation-end", {origin = session, resumed = original_session, queue = queue});
496 session.log("debug", "#queue = %d", #queue); 496 original_session.log("debug", "#queue = %d", #queue);
497 for i=1,#queue do 497 for i=1,#queue do
498 session.send(queue[i]); 498 original_session.send(queue[i]);
499 end 499 end
500 session.log("debug", "#queue = %d -- after send", #queue); 500 original_session.log("debug", "#queue = %d -- after send", #queue);
501 function session.send(stanza)
502 session.log("warn", "Tried to send stanza on old session migrated by smacks resume (maybe there is a bug?): %s", tostring(stanza));
503 return false;
504 end
501 else 505 else
502 module:log("warn", "Client %s@%s[%s] tried to resume stream for %s@%s[%s]", 506 module:log("warn", "Client %s@%s[%s] tried to resume stream for %s@%s[%s]",
503 session.username or "?", session.host or "?", session.type, 507 session.username or "?", session.host or "?", session.type,
504 original_session.username or "?", original_session.host or "?", original_session.type); 508 original_session.username or "?", original_session.host or "?", original_session.type);
505 session.send(st.stanza("failed", { xmlns = xmlns_sm }) 509 session.send(st.stanza("failed", { xmlns = xmlns_sm })