# HG changeset patch # User Matthew Wild # Date 1678966948 0 # Node ID 6c3797c0bb44a56cbfa9add73acd86abb429c7d4 # Parent 73d4eb93657bc9dd2c8cd6dd5f42645c56c84178 client: Correctly randomize SRV targets (thanks Zash) diff -r 73d4eb93657b -r 6c3797c0bb44 client.lua --- 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 = {