# HG changeset patch # User Matthew Wild # Date 1300484904 0 # Node ID 0f34520f4e26368673a4845f51f357c857ff9755 # Parent 05d1a47512510c88922200b2241b127e5d18d6c9 plugins.smacks: Scatter some logging and comments through the code for good measure diff -r 05d1a4751251 -r 0f34520f4e26 plugins/smacks.lua --- a/plugins/smacks.lua Fri Mar 18 21:46:33 2011 +0000 +++ b/plugins/smacks.lua Fri Mar 18 21:48:24 2011 +0000 @@ -17,8 +17,10 @@ end local function on_disconnect() + stream:debug("smacks: connection lost"); stream.stream_management_supported = nil; if stream.resumption_token then + stream:debug("smacks: have resumption token, reconnecting in 1s..."); stream.authenticated = nil; verse.add_task(1, function () stream:connect(stream.connect_host or stream.host, stream.connect_port or 5222); @@ -29,6 +31,7 @@ local function handle_sm_command(stanza) if stanza.name == "r" then -- Request for acks for stanzas we received + stream:debug("Ack requested... acking %d handled stanzas", handled_stanza_count); stream:send(verse.stanza("a", { xmlns = xmlns_sm, h = tostring(handled_stanza_count) })); elseif stanza.name == "a" then -- Ack for stanzas we sent local new_ack = tonumber(stanza.attr.h); @@ -64,6 +67,8 @@ stream:hook("disconnected", on_disconnect, 100); end elseif stanza.name == "resumed" then + --TODO: Check h of the resumed element, discard any acked stanzas from + -- our queue (to prevent duplicates), then re-send any lost stanzas. stream:debug("Resumed successfully"); stream:event("resumed"); else @@ -74,6 +79,7 @@ local function on_bind_success() if not stream.smacks then --stream:unhook("bind-success", on_bind_success); + stream:debug("smacks: sending enable"); stream:send(verse.stanza("enable", { xmlns = xmlns_sm, resume = "true" })); end end @@ -82,6 +88,7 @@ if features:get_child("sm", xmlns_sm) then stream.stream_management_supported = true; if stream.smacks and stream.bound then -- Already enabled in a previous session - resume + stream:debug("Resuming stream with %d handled stanzas", handled_stanza_count); stream:send(verse.stanza("resume", { xmlns = xmlns_sm, h = handled_stanza_count, previd = stream.resumption_token })); return true;