Software / code / verse
Comparison
client.lua @ 458:6c3797c0bb44
client: Correctly randomize SRV targets (thanks Zash)
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Thu, 16 Mar 2023 11:42:28 +0000 |
| parent | 457:73d4eb93657b |
| child | 459:6be4182cfb31 |
comparison
equal
deleted
inserted
replaced
| 457:73d4eb93657b | 458:6c3797c0bb44 |
|---|---|
| 21 | 21 |
| 22 local new_xmpp_stream = require "util.xmppstream".new; | 22 local new_xmpp_stream = require "util.xmppstream".new; |
| 23 | 23 |
| 24 local xmlns_stream = "http://etherx.jabber.org/streams"; | 24 local xmlns_stream = "http://etherx.jabber.org/streams"; |
| 25 | 25 |
| 26 local function compare_srv_priorities(a,b) | 26 local function compare_srv_priorities(a, b) |
| 27 return a.priority < b.priority or (a.priority == b.priority and a.weight > b.weight); | 27 if a.priority == b.priority then |
| 28 if not a.weight_r then | |
| 29 a.weight_r = math.random(); | |
| 30 end | |
| 31 if not b.weight_r then | |
| 32 b.weight_r = math.random(); | |
| 33 end | |
| 34 return (1 + a.weight) * a.weight_r > (1 + b.weight) * b.weight_r; | |
| 35 end | |
| 36 return a.priority < b.priority; | |
| 28 end | 37 end |
| 29 | 38 |
| 30 local stream_callbacks = { | 39 local stream_callbacks = { |
| 31 stream_ns = xmlns_stream, | 40 stream_ns = xmlns_stream, |
| 32 stream_tag = "stream", | 41 stream_tag = "stream", |