[telepathy-gabble/master] mark the proxies list has expired after 6 hours
Guillaume Desmottes
guillaume.desmottes at collabora.co.uk
Fri Dec 4 07:55:05 PST 2009
---
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 5fa75e8..132da25 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);
}
--
1.5.6.5
More information about the telepathy-commits
mailing list