changeset 26293:06693083f668

Make IceUdp candidates know whether the remote side knows about them.
author Mike Ruprecht <maiku@soc.pidgin.im>
date Thu, 19 Mar 2009 07:34:25 +0000
parents 327102f2ce64
children 1ac93927e7f5
files libpurple/protocols/jabber/jingle/iceudp.c libpurple/protocols/jabber/jingle/iceudp.h
diffstat 2 files changed, 30 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/libpurple/protocols/jabber/jingle/iceudp.c	Thu Mar 19 01:48:02 2009 +0000
+++ b/libpurple/protocols/jabber/jingle/iceudp.c	Thu Mar 19 07:34:25 2009 +0000
@@ -119,6 +119,8 @@
 
 	candidate->username = g_strdup(username);
 	candidate->password = g_strdup(password);
+
+	candidate->rem_known = FALSE;
 	return candidate;
 }
 
@@ -324,6 +326,7 @@
 				xmlnode_get_attrib(candidate, "rel-addr"));
 		iceudp_candidate->relport =
 				relport != NULL ? atoi(relport) : 0;
+		iceudp_candidate->rem_known = TRUE;
 		jingle_iceudp_add_remote_candidate(JINGLE_ICEUDP(transport), iceudp_candidate);
 	}
 
@@ -342,22 +345,27 @@
 			action == JINGLE_TRANSPORT_REPLACE) {
 		JingleIceUdpPrivate *priv = JINGLE_ICEUDP_GET_PRIVATE(transport);
 		GList *iter = priv->local_candidates;
-
-		if (iter && iter->data) {
-			JingleIceUdpCandidate *candidate = iter->data;
-			xmlnode_set_attrib(node, "pwd", candidate->password);
-			xmlnode_set_attrib(node, "ufrag", candidate->username);
-		}
+		gboolean used_candidate = FALSE;
 
 		for (; iter; iter = g_list_next(iter)) {
 			JingleIceUdpCandidate *candidate = iter->data;
+			xmlnode *xmltransport;
+			gchar *component, *generation, *network,
+					*port, *priority;
 
-			xmlnode *xmltransport = xmlnode_new_child(node, "candidate");
-			gchar *component = g_strdup_printf("%d", candidate->component);
-			gchar *generation = g_strdup_printf("%d", candidate->generation);
-			gchar *network = g_strdup_printf("%d", candidate->network);
-			gchar *port = g_strdup_printf("%d", candidate->port);
-			gchar *priority = g_strdup_printf("%d", candidate->priority);
+			if (candidate->rem_known == TRUE)
+				continue;
+
+			used_candidate = TRUE;
+			candidate->rem_known = TRUE;
+
+			xmltransport = xmlnode_new_child(node, "candidate");
+			component = g_strdup_printf("%d", candidate->component);
+			generation = g_strdup_printf("%d",
+					candidate->generation);
+			network = g_strdup_printf("%d", candidate->network);
+			port = g_strdup_printf("%d", candidate->port);
+			priority = g_strdup_printf("%d", candidate->priority);
 
 			xmlnode_set_attrib(xmltransport, "component", component);
 			xmlnode_set_attrib(xmltransport, "foundation", candidate->foundation);
@@ -389,6 +397,13 @@
 			g_free(port);
 			g_free(priority);
 		}
+
+		if (used_candidate == TRUE) {
+			JingleIceUdpCandidate *candidate =
+					priv->local_candidates->data;
+			xmlnode_set_attrib(node, "pwd", candidate->password);
+			xmlnode_set_attrib(node, "ufrag", candidate->username);
+		}
 	}
 
 	return node;
--- a/libpurple/protocols/jabber/jingle/iceudp.h	Thu Mar 19 01:48:02 2009 +0000
+++ b/libpurple/protocols/jabber/jingle/iceudp.h	Thu Mar 19 07:34:25 2009 +0000
@@ -78,6 +78,9 @@
 
 	gchar *username;
 	gchar *password;
+
+	gboolean rem_known;	/* TRUE if the remote side knows
+				 * about this candidate */
 };
 
 #ifdef __cplusplus