--YZ5djTAD1cGYuMQK
Content-Type: text/plain; charset=utf-8
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

I=C3=B1aki Baz Castillo:

> I get data (DNS SRV records), which is an array with entries like this:

> #<EventMachine::Udns::RR_SRV:0x00000001ea4970 @domain=3D"domain.org", @pr=
iority=3D1, @weight=3D50, @port=3D5062>

> Each entry is a SRV record. It has a priority (lowest value is the
> best) and weight (higher value means more probability to choose it).

> The client getting such array of SRV records wants to connect to a
> server based on SRV priorities/weight, which works as follows:
> - SRV records with best priority must be used first.
> - If there are various SRV records with same priority, then the
> probability of choosing each one depends on its weight value (random
> with weight).
> - If the chosen SRV record fails to connect (i.e. server down) next
> one (based on same priority/weight rules) must be tryed.

Something to the tune of

srvs.sort { |a, b| (a.priority <=3D> b.priority).nonzero? or (b.weight <=3D=
> a.weight).nonzero? or rand }

should work, then. :)

=E2=80=94 Piotr Szotkowski
--=20
=E2=80=98Driving myself slowly nuts with printing recursive S-expressions s=
anely in Go.=E2=80=99
=E2=80=98Ford Prefect always said that going insane should
be enjoyed, and is not something to be rushed.=E2=80=99
                                             [Eleanor McHugh, Phillip Gawlo=
wski]




--YZ5djTAD1cGYuMQK
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iEYEARECAAYFAk4CA/8ACgkQi/mCfdEo8UpMkACbBAqOOyuGGbi2PX7bCkQQh2Cd
oMoAoIyZdFJ2I+MY6FPU7fn+9wcrRyNB
=oHG9
-----END PGP SIGNATURE-----

--YZ5djTAD1cGYuMQK--

Iaki Baz Castillo:

> I get data (DNS SRV records), which is an array with entries like this:

> #<EventMachine::Udns::RR_SRV:0x00000001ea4970 @domain="domain.org", @priority=1, @weight=50, @port=5062>

> Each entry is a SRV record. It has a priority (lowest value is the
> best) and weight (higher value means more probability to choose it).

> The client getting such array of SRV records wants to connect to a
> server based on SRV priorities/weight, which works as follows:
> - SRV records with best priority must be used first.
> - If there are various SRV records with same priority, then the
> probability of choosing each one depends on its weight value (random
> with weight).
> - If the chosen SRV record fails to connect (i.e. server down) next
> one (based on same priority/weight rules) must be tryed.

Something to the tune of

srvs.sort { |a, b| (a.priority <=> b.priority).nonzero? or (b.weight <=> a.weight).nonzero? or rand }

should work, then. :)

°Ĺ Piotr Szotkowski
-- 
°∆Driving myself slowly nuts with printing recursive S-expressions sanely in Go.°«
°∆Ford Prefect always said that going insane should
be enjoyed, and is not something to be rushed.°«
                                             [Eleanor McHugh, Phillip Gawlowski]



-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iEYEARECAAYFAk4CA/8ACgkQi/mCfdEo8UpMkACbBAqOOyuGGbi2PX7bCkQQh2Cd
oMoAoIyZdFJ2I+MY6FPU7fn+9wcrRyNB
=oHG9
-----END PGP SIGNATURE-----