diff options
author | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2009-12-04 15:55:05 +0000 |
---|---|---|
committer | Guillaume Desmottes <guillaume.desmottes@collabora.co.uk> | 2009-12-07 10:43:06 +0000 |
commit | 92ff1d7aa5fc47859e8b9d4c4746eede46128e55 (patch) | |
tree | d52794d7c0925761b3ffa751d97eba5306c38c57 /src/bytestream-factory.c | |
parent | 4d2fd71d7f6a15df9d60ea9e20e224fd452d1c6d (diff) | |
download | telepathy-gabble-92ff1d7aa5fc47859e8b9d4c4746eede46128e55.tar.gz |
mark the proxies list has expired after 6 hours
Diffstat (limited to 'src/bytestream-factory.c')
-rw-r--r-- | src/bytestream-factory.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/bytestream-factory.c b/src/bytestream-factory.c index 5fa75e842..132da25fd 100644 --- a/src/bytestream-factory.c +++ b/src/bytestream-factory.c @@ -52,6 +52,10 @@ G_DEFINE_TYPE (GabbleBytestreamFactory, gabble_bytestream_factory, #define SOCKS5_PROXY_TIMEOUT 10 #define TELEPATHY_PROXIES_SERVICE "proxies.telepathy.im" +/* The life time (in seconds) of the proxies list discovered using + * TELEPATHY_PROXIES_SERVICE */ +/* 6 hours */ +#define PROXIES_LIST_TIMER 6 * 60 * 60 /* properties */ enum @@ -173,6 +177,11 @@ struct _GabbleBytestreamFactoryPrivate /* Next proxy on socks5_potential_proxies that we'll query */ GSList *next_query; + guint proxies_list_timer; + /* If TRUE the proxies list received from TELEPATHY_PROXIES_SERVICE has + * expired and so we'll request a new one next time we'll need proxies */ + gboolean proxies_list_expired; + gboolean dispose_has_run; }; @@ -401,6 +410,19 @@ query_proxies (GabbleBytestreamFactory *self, } } +static gboolean +proxies_list_timer_cb (gpointer data) +{ + GabbleBytestreamFactory *self = GABBLE_BYTESTREAM_FACTORY (data); + GabbleBytestreamFactoryPrivate *priv = GABBLE_BYTESTREAM_FACTORY_GET_PRIVATE ( + self); + + DEBUG ("proxies list expired"); + priv->proxies_list_timer = 0; + priv->proxies_list_expired = TRUE; + return FALSE; +} + static void proxies_disco_cb (GabbleDisco *disco, GabbleDiscoRequest *request, @@ -415,6 +437,8 @@ proxies_disco_cb (GabbleDisco *disco, self); NodeIter i; + priv->proxies_list_expired = FALSE; + if (error != NULL) return; @@ -445,6 +469,12 @@ proxies_disco_cb (GabbleDisco *disco, priv->next_query = priv->socks5_potential_proxies; gabble_bytestream_factory_query_socks5_proxies (self); + + if (priv->proxies_list_timer != 0) + g_source_remove (priv->proxies_list_timer); + + priv->proxies_list_timer = g_timeout_add_seconds (PROXIES_LIST_TIMER, + proxies_list_timer_cb, self); } /* Query TELEPATHY_PROXIES_SERVICE to get a list of proxies */ @@ -476,6 +506,12 @@ gabble_bytestream_factory_query_socks5_proxies (GabbleBytestreamFactory *self) return; } + if (priv->proxies_list_expired) + { + DEBUG ("Proxies list has expired; request a new one"); + get_proxies_list (self); + } + nb_proxies_found = g_slist_length (priv->socks5_proxies) + g_slist_length (priv->socks5_fallback_proxies); @@ -663,6 +699,10 @@ gabble_bytestream_factory_dispose (GObject *object) g_slist_free (priv->socks5_potential_proxies); priv->socks5_potential_proxies = NULL; + if (priv->proxies_list_timer != 0) + g_source_remove (priv->proxies_list_timer); + priv->proxies_list_timer = 0; + if (G_OBJECT_CLASS (gabble_bytestream_factory_parent_class)->dispose) G_OBJECT_CLASS (gabble_bytestream_factory_parent_class)->dispose (object); } |