[Telepathy-commits] [telepathy-gabble/master] GabbleJingleFactory: when requesting Google relay sessions, make one request per component

Simon McVittie simon.mcvittie at collabora.co.uk
Wed Mar 4 03:14:01 PST 2009


We need a separate relay session for the RTP and the RTCP.

For now, only the hash table for the last request to succeed is returned.
---
 src/jingle-factory.c |   52 ++++++++++++++++++++++++++++++++-----------------
 src/jingle-factory.h |    4 +-
 src/media-channel.c  |    6 +++-
 3 files changed, 40 insertions(+), 22 deletions(-)

diff --git a/src/jingle-factory.c b/src/jingle-factory.c
index 9b88eae..3591cce 100644
--- a/src/jingle-factory.c
+++ b/src/jingle-factory.c
@@ -884,16 +884,19 @@ gabble_jingle_factory_get_stun_server (GabbleJingleFactory *self,
 
 typedef struct
 {
+  guint requests_to_do;
   GabbleJingleFactoryRelaySessionCb callback;
   gpointer user_data;
 } RelaySessionData;
 
 static RelaySessionData *
-relay_session_data_new (GabbleJingleFactoryRelaySessionCb callback,
+relay_session_data_new (guint requests_to_do,
+                        GabbleJingleFactoryRelaySessionCb callback,
                         gpointer user_data)
 {
   RelaySessionData *rsd = g_slice_new0 (RelaySessionData);
 
+  rsd->requests_to_do = requests_to_do;
   rsd->callback = callback;
   rsd->user_data = user_data;
 
@@ -905,6 +908,8 @@ relay_session_data_destroy (gpointer p)
 {
   RelaySessionData *rsd = p;
 
+  g_assert (rsd->requests_to_do == 0);
+
   g_slice_free (RelaySessionData, rsd);
 }
 
@@ -914,22 +919,22 @@ on_http_response (SoupSession *soup,
                   gpointer user_data)
 {
   RelaySessionData *rsd = user_data;
+  GHashTable *map = NULL;
 
   if (msg->status_code != 200)
     {
       DEBUG ("Google session creation failed, relaying not used: %d %s",
           msg->status_code, msg->reason_phrase);
-
-      rsd->callback (NULL, rsd->user_data);
     }
   else
     {
       /* parse a=b lines into GHashTable */
-      GHashTable *map = g_hash_table_new_full (g_str_hash, g_str_equal,
-          g_free, g_free);
       gchar **lines;
       guint i;
 
+      map = g_hash_table_new_full (g_str_hash, g_str_equal,
+          g_free, g_free);
+
       DEBUG ("Response from Google:\n====\n%s\n====",
           msg->response_body->data);
 
@@ -960,25 +965,31 @@ on_http_response (SoupSession *soup,
                   g_strdup (delim + 1));
             }
         }
+      g_strfreev (lines);
+    }
 
+  if ((--rsd->requests_to_do) == 0)
+    {
       rsd->callback (map, rsd->user_data);
-      g_hash_table_unref (map);
-      g_strfreev (lines);
+      relay_session_data_destroy (rsd);
     }
 
-  relay_session_data_destroy (rsd);
+  if (map != NULL)
+    g_hash_table_unref (map);
 }
 
 void
 gabble_jingle_factory_create_google_relay_session (
     GabbleJingleFactory *fac,
+    guint components,
     GabbleJingleFactoryRelaySessionCb callback,
     gpointer user_data)
 {
   GabbleJingleFactoryPrivate *priv =
       GABBLE_JINGLE_FACTORY_GET_PRIVATE (fac);
-  SoupMessage *msg;
   gchar *url;
+  guint i;
+  RelaySessionData *rsd;
 
   g_return_if_fail (callback != NULL);
 
@@ -1012,17 +1023,22 @@ gabble_jingle_factory_create_google_relay_session (
 
   url = g_strdup_printf ("http://%s:%d/create_session",
       fac->priv->relay_server, fac->priv->relay_http_port);
-  msg = soup_message_new ("GET", url);
+  rsd = relay_session_data_new (components, callback, user_data);
+
+  for (i = 0; i < components; i++)
+    {
+      SoupMessage *msg = soup_message_new ("GET", url);
+
+      DEBUG ("Trying to create a new relay session on %s", url);
 
-  DEBUG ("Trying to create a new relay session on %s", url);
+      /* libjingle sets both headers, so shall we */
+      soup_message_headers_append (msg->request_headers,
+          "X-Talk-Google-Relay-Auth", fac->priv->relay_token);
+      soup_message_headers_append (msg->request_headers,
+          "X-Google-Relay-Auth", fac->priv->relay_token);
 
-  /* libjingle sets both headers, so shall we */
-  soup_message_headers_append (msg->request_headers,
-      "X-Talk-Google-Relay-Auth", fac->priv->relay_token);
-  soup_message_headers_append (msg->request_headers,
-      "X-Google-Relay-Auth", fac->priv->relay_token);
+      soup_session_queue_message (priv->soup, msg, on_http_response, rsd);
+    }
 
-  soup_session_queue_message (priv->soup, msg, on_http_response,
-      relay_session_data_new (callback, user_data));
   g_free (url);
 }
diff --git a/src/jingle-factory.h b/src/jingle-factory.h
index fecd44d..906952b 100644
--- a/src/jingle-factory.h
+++ b/src/jingle-factory.h
@@ -145,8 +145,8 @@ GabbleJingleSession *gabble_jingle_factory_create_session (GabbleJingleFactory
 typedef void (*GabbleJingleFactoryRelaySessionCb) (GHashTable *relay,
     gpointer user_data);
 void gabble_jingle_factory_create_google_relay_session (
-    GabbleJingleFactory *self, GabbleJingleFactoryRelaySessionCb callback,
-    gpointer user_data);
+    GabbleJingleFactory *self, guint components,
+    GabbleJingleFactoryRelaySessionCb callback, gpointer user_data);
 
 const gchar *gabble_jingle_factory_get_google_relay_token (
     GabbleJingleFactory *self);
diff --git a/src/media-channel.c b/src/media-channel.c
index a076aff..24f3a36 100644
--- a/src/media-channel.c
+++ b/src/media-channel.c
@@ -2388,10 +2388,12 @@ create_stream_from_content (GabbleMediaChannel *chan,
   if (!tp_strdiff (nat_traversal, "gtalk-p2p"))
     {
       /* See if our server is Google, and if it is, ask them for a relay.
-       * For now, don't wait for the result (we don't actually use it yet). */
+       * For now, don't wait for the result (we don't actually use it yet).
+       * We ask for enough relays for 2 components (RTP and RTCP) since we
+       * don't yet know whether there will be RTCP. */
       DEBUG ("Attempting to create Google relay session");
       gabble_jingle_factory_create_google_relay_session (
-          priv->conn->jingle_factory, google_relay_session_cb, NULL);
+          priv->conn->jingle_factory, 2, google_relay_session_cb, NULL);
     }
 
   stream = gabble_media_stream_new (object_path, c, name, id,
-- 
1.5.6.5




More information about the telepathy-commits mailing list