Thu, 16 Mar 2023 11:42:28 +0000
client: Correctly randomize SRV targets (thanks Zash)
client.lua | file | annotate | diff | comparison | revisions |
--- a/client.lua Thu Mar 16 11:41:52 2023 +0000 +++ b/client.lua Thu Mar 16 11:42:28 2023 +0000 @@ -23,8 +23,17 @@ local xmlns_stream = "http://etherx.jabber.org/streams"; -local function compare_srv_priorities(a,b) - return a.priority < b.priority or (a.priority == b.priority and a.weight > b.weight); +local function compare_srv_priorities(a, b) + if a.priority == b.priority then + if not a.weight_r then + a.weight_r = math.random(); + end + if not b.weight_r then + b.weight_r = math.random(); + end + return (1 + a.weight) * a.weight_r > (1 + b.weight) * b.weight_r; + end + return a.priority < b.priority; end local stream_callbacks = {