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", |