diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2009-03-25 14:45:05 +0000 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2009-03-26 17:06:25 +0000 |
commit | feea877a731676ca7fe9fb341d88ad7a57184a59 (patch) | |
tree | 82193996bd07cb8ae9700e865971912e1936f9e3 /src/bytestream-factory.c | |
parent | 8a28548000a2fffe9940d8a06cddbb4558462b26 (diff) | |
download | telepathy-gabble-feea877a731676ca7fe9fb341d88ad7a57184a59.tar.gz |
gabble_bytestream_factory_get_socks5_proxies: randomize fallback proxies list
Diffstat (limited to 'src/bytestream-factory.c')
-rw-r--r-- | src/bytestream-factory.c | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/bytestream-factory.c b/src/bytestream-factory.c index 9fb33ee11..6b6511666 100644 --- a/src/bytestream-factory.c +++ b/src/bytestream-factory.c @@ -1936,9 +1936,33 @@ gabble_bytestream_factory_get_socks5_proxies (GabbleBytestreamFactory *self) { GabbleBytestreamFactoryPrivate *priv = GABBLE_BYTESTREAM_FACTORY_GET_PRIVATE ( self); + guint len; - /* TODO: randomize priv->socks5_fallback_proxies once we can have more than - * one proxy in it */ + len = g_slist_length (priv->socks5_fallback_proxies); + if (len > 1) + { + /* randomize fallback proxies to avoid to use always the same one */ + guint i; + + i = g_random_int_range (0, len); + if (i != 0) + { + GSList *new_head, *new_tail; + + /* Cut the list at the i th position and make it the new head of the + * list */ + new_tail = g_slist_nth (priv->socks5_fallback_proxies, i - 1); + g_assert (new_tail != NULL); + + new_head = new_tail->next; + g_assert (new_head != NULL); + + new_tail->next = NULL; + + priv->socks5_fallback_proxies = g_slist_concat (new_head, + priv->socks5_fallback_proxies); + } + } return g_slist_concat (g_slist_copy (priv->socks5_proxies), g_slist_copy (priv->socks5_fallback_proxies)); |