plugins.smacks: Handle failed resumption by trying to bind instead

Sat, 19 Feb 2022 15:43:47 +0100

author
Kim Alvefur <zash@zash.se>
date
Sat, 19 Feb 2022 15:43:47 +0100
changeset 448
6d97b42bb1b4
parent 447
f3ecbf65a81e
child 449
c720f331327c

plugins.smacks: Handle failed resumption by trying to bind instead

plugins/smacks.lua file | annotate | diff | comparison | revisions
--- a/plugins/smacks.lua	Sat Nov 06 18:26:31 2021 +0100
+++ b/plugins/smacks.lua	Sat Feb 19 15:43:47 2022 +0100
@@ -84,6 +84,7 @@
 				stream:warn("Received bad ack for "..new_ack.." when last ack was "..last_ack);
 			end
 		elseif stanza.name == "enabled" then
+			stream.pre_smacks_features = nil;
 
 			if stanza.attr.id then
 				stream.resumption_token = stanza.attr.id;
@@ -91,6 +92,7 @@
 				stream:hook("disconnected", on_disconnect, 100);
 			end
 		elseif stanza.name == "resumed" then
+			stream.pre_smacks_features = nil;
 			local new_ack = tonumber(stanza.attr.h);
 			if new_ack > last_ack then
 				local old_unacked = #outgoing_queue;
@@ -106,6 +108,20 @@
 			outgoing_queue = {};
 			stream:debug("Resumed successfully");
 			stream:event("resumed");
+		elseif stanza.name == "failed" then
+			stream.bound = nil
+			stream.smacks = nil
+			last_ack = 0
+			handled_stanza_count = 0;
+
+			-- TODO ack using final h value from <failed/> if present
+			outgoing_queue = {}; -- TODO fire some delivery failures
+
+			local features = stream.pre_smacks_features;
+			stream.pre_smacks_features = nil;
+
+			-- should trigger a bind and then a new smacks session
+			stream:event("stream-features", features);
 		else
 			stream:warn("Don't know how to handle "..xmlns_sm.."/"..stanza.name);
 		end
@@ -126,6 +142,7 @@
 
 	local function on_features(features)
 		if features:get_child("sm", xmlns_sm) then
+			stream.pre_smacks_features = features;
 			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);

mercurial