Software /
code /
verse
Changeset
450:e72deac76e0e
plugins.smacks: Change to track enabled state per direction
Counting outgoing stanzas should start after <enable> is sent, while
counting incoming stanzas should star after receiving <enabled/>
This should also help with failed resumptions
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 19 Feb 2022 15:57:24 +0100 |
parents | 449:c720f331327c |
children | 451:a0c55329c38d |
files | plugins/smacks.lua |
diffstat | 1 files changed, 12 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/plugins/smacks.lua Sat Feb 19 15:52:10 2022 +0100 +++ b/plugins/smacks.lua Sat Feb 19 15:57:24 2022 +0100 @@ -5,17 +5,17 @@ function verse.plugins.smacks(stream) -- State for outgoing stanzas - local outgoing_queue = {}; - local last_ack = 0; - local last_stanza_time = now(); + local outgoing_queue = nil; + local last_ack = nil; + local last_stanza_time = nil; local timer_active; -- State for incoming stanzas - local handled_stanza_count = 0; + local handled_stanza_count = nil; -- Catch incoming stanzas local function incoming_stanza(stanza) - if stream.smacks and (stanza.attr.xmlns == "jabber:client" or not stanza.attr.xmlns) then + if handled_stanza_count and (stanza.attr.xmlns == "jabber:client" or not stanza.attr.xmlns) then handled_stanza_count = handled_stanza_count + 1; stream:debug("Increasing handled stanzas to %d for %s", handled_stanza_count, stanza:top_tag()); end @@ -24,7 +24,7 @@ -- Catch outgoing stanzas local function outgoing_stanza(stanza) -- NOTE: This will not behave nice if stanzas are serialized before this point - if stream.smacks and (stanza.name and not stanza.attr.xmlns) then + if outgoing_queue and (stanza.name and not stanza.attr.xmlns) then -- serialize stanzas in order to bypass this on resumption outgoing_queue[#outgoing_queue+1] = tostring(stanza); last_stanza_time = now(); @@ -83,6 +83,7 @@ stream:warn("Received bad ack for "..new_ack.." when last ack was "..last_ack); end elseif stanza.name == "enabled" then + handled_stanza_count = 0; stream.pre_smacks_features = nil; if stanza.attr.id then @@ -108,8 +109,8 @@ elseif stanza.name == "failed" then stream.bound = nil stream.smacks = nil - last_ack = 0 - handled_stanza_count = 0; + last_ack = nil + handled_stanza_count = nil -- TODO ack using final h value from <failed/> if present outgoing_queue = {}; -- TODO fire some delivery failures @@ -128,6 +129,9 @@ if stream.stream_management_supported and not stream.smacks then --stream:unhook("bind-success", on_bind_success); stream:debug("smacks: sending enable"); + outgoing_queue = {}; + last_ack = 0; + last_stanza_time = now(); stream:send(verse.stanza("enable", { xmlns = xmlns_sm, resume = "true" })); stream.smacks = true; end