[SSSD] [PATCH] Sort SRV replies according to RFC 2782
Stephen Gallagher
sgallagh at redhat.com
Thu Apr 22 12:43:27 UTC 2010
On 04/22/2010 06:45 AM, Jakub Hrozek wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> This functionality is needed for service discovery.
>
> RFC 2782 defines a way to sort replies to a SRV query. In short, the
> algorithm sorts all replies by priority and then does a weight-based
> selection for every priority level.
>
> For details, please see the sections "Usage rules" for overview of the
> algorithm and section "The 'Weight' field" for description on the weight
> selection.
Nack.
While this is clearly not a case where random values need to be highly
random, on some implementations rand() is not uniformly distributed in
the low-order bits. In order to be more portable, we should use
selected = (int)((total + 1) * (rand()/(RAND_MAX + 1.0)))
This will give a random integer from 0 to total (inclusive) using the
high-order bits returned by rand().
Otherwise this looks good.
--
Stephen Gallagher
RHCE 804006346421761
Delivering value year after year.
Red Hat ranks #1 in value among software vendors.
http://www.redhat.com/promo/vendor/
More information about the sssd-devel
mailing list