From dd76b252b9e52312c56e6826fb19a02175232d90 Mon Sep 17 00:00:00 2001 From: Victor Seva Date: Wed, 21 Feb 2018 21:23:58 +0100 Subject: [PATCH] TT#33379 Merge https://github.com/sipwise/prosody/pull/2 commit d207cf102b6c668dfab4ab55e747d11d0e29f760 Author: Victor Seva Date: Wed Feb 21 21:23:58 2018 +0100 [mod_shard_client] detect loop on shard messages Add 'via' attribute to shard stanza in order to detect loops closes #2 Change-Id: I1e5f947a7b6fdcbd0e0d773b790929dc0681fbcd --- plugins/mod_shard_client.lua | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/plugins/mod_shard_client.lua b/plugins/mod_shard_client.lua index 0166f40..bef1383 100644 --- a/plugins/mod_shard_client.lua +++ b/plugins/mod_shard_client.lua @@ -7,13 +7,16 @@ -- module:set_global(); local socket = require "socket" - +local ut = require "util.table"; local logger = require "util.logger"; local st = require "util.stanza"; local new_xmpp_stream = require "util.xmppstream".new; local wrapclient = require "net.server".wrapclient; local log = module._log; - +local shard_name = module:get_option("shard_name", nil); +if not shard_name then + error("shard_name not configured", 0); +end local opt_keepalives = module:get_option_boolean("shard_tcp_keepalives", module:get_option_boolean("tcp_keepalives", true)); local conns = {}; @@ -202,6 +205,20 @@ local function handle_send(event) queue[shard] = {}; end + if stanza.attr.via then + local via = ut.string.explode(';', stanza.attr.via); + module:log("debug", "via:%s", ut.table.tostring(via)); + if ut.table.contains(via, shard_name) then + module:log("error", "loop detected, stanza[%s]", stanza); + return; + end + table.insert(via, shard_name); + stanza.attr.via = ut.table.implode(';', via); + else + stanza.attr.via = shard_name; + end + module:log("debug", "new via:%s", stanza.attr.via); + local session = sessions[conn] if session == nil then table.insert(queue[shard], stanza)