Mercurial > pidgin
changeset 26461:43cfca2eab64
A better random number for the rid in the range [0, 2**52).
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Sat, 04 Apr 2009 21:49:34 +0000 |
parents | 680b54e417c1 |
children | e0218e4ec785 |
files | libpurple/protocols/jabber/bosh.c |
diffstat | 1 files changed, 9 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/protocols/jabber/bosh.c Sat Apr 04 20:59:15 2009 +0000 +++ b/libpurple/protocols/jabber/bosh.c Sat Apr 04 21:49:34 2009 +0000 @@ -176,8 +176,15 @@ g_free(passwd); conn->js = js; - /* FIXME: This doesn't seem very random */ - conn->rid = rand() % 100000 + 1728679472; + + /* + * Random 64-bit integer masked off by 2^52 - 1. + * + * This should produce a random integer in the range [0, 2^52). It's + * unlikely we'll send enough packets in one session to overflow the rid. + */ + conn->rid = ((guint64)g_random_int() << 32) | g_random_int(); + conn->rid &= 0xFFFFFFFFFFFFF; conn->pending = purple_circ_buffer_new(0 /* default grow size */);