XMPP: Remove STUN lookups

Fri, 17 Feb 2023 04:54:38 -0600

author
Gary Kramlich <grim@reaperworld.com>
date
Fri, 17 Feb 2023 04:54:38 -0600
changeset 42091
594a2d0e1d52
parent 42090
f72f1db0f42b
child 42092
e6dcbf0db616

XMPP: Remove STUN lookups

While this worked in some regard, it was only refreshed when an account
connected which will lead to caching issues over time.

Also as we're trying to migrate all of the NAT traversal stuff to traversity,
this code was a blocker for removing the STUN code from libpurple itself.

Testing Done:
Connected an XMPP account without issue.

Reviewed at https://reviews.imfreedom.org/r/2173/

libpurple/protocols/jabber/disco.c file | annotate | diff | comparison | revisions
libpurple/protocols/jabber/jabber.c file | annotate | diff | comparison | revisions
libpurple/protocols/jabber/jabber.h file | annotate | diff | comparison | revisions
libpurple/protocols/jabber/jingle/jingle.c file | annotate | diff | comparison | revisions
--- a/libpurple/protocols/jabber/disco.c	Fri Feb 17 04:54:01 2023 -0600
+++ b/libpurple/protocols/jabber/disco.c	Fri Feb 17 04:54:38 2023 -0600
@@ -381,43 +381,6 @@
 }
 
 static void
-jabber_disco_stun_srv_resolve_cb(GObject *sender, GAsyncResult *result, gpointer data) {
-	GError *error = NULL;
-	GList *services = NULL;
-	JabberStream *js = (JabberStream *) data;
-	gint results = 0;
-
-	services = g_resolver_lookup_service_finish(G_RESOLVER(sender),
-			result, &error);
-
-	if(error != NULL) {
-		purple_debug_info("jabber", "Failed to look up a STUN record : %s\n", error->message);
-
-		g_error_free(error);
-
-		return;
-	}
-
-	results = g_list_length(services);
-
-	purple_debug_info("jabber", "got %d SRV responses for STUN.\n", results);
-
-	if (results > 0) {
-		GSrvTarget *target = (GSrvTarget *)services->data;
-		const gchar *hostname = g_srv_target_get_hostname(target);
-
-		js->stun_ip = g_strdup(hostname);
-		js->stun_port = g_srv_target_get_port(target);
-
-		purple_debug_info("jabber", "set stun address to %s:%d\n",
-			hostname, js->stun_port);
-	}
-
-	g_resolver_free_targets(services);
-}
-
-
-static void
 jabber_disco_server_info_result_cb(JabberStream *js, const char *from,
                                    JabberIqType type,
                                    G_GNUC_UNUSED const char *id,
@@ -446,7 +409,7 @@
 
 	for (child = purple_xmlnode_get_child(query, "identity"); child;
 	     child = purple_xmlnode_get_next_twin(child)) {
-		const char *category, *type, *name, *stun_ip;
+		const char *category, *type, *name;
 		category = purple_xmlnode_get_attrib(child, "category");
 		type = purple_xmlnode_get_attrib(child, "type");
 		if(purple_strequal(category, "pubsub") && purple_strequal(type, "pep")) {
@@ -468,19 +431,6 @@
 
 		g_free(js->server_name);
 		js->server_name = g_strdup(name);
-		stun_ip = purple_network_get_stun_ip();
-		if (!stun_ip || !*stun_ip) {
-			GResolver *resolver = g_resolver_get_default();
-			g_resolver_lookup_service_async(resolver,
-			                                "stun",
-			                                "udp",
-			                                js->user->domain,
-			                                NULL,
-			                                jabber_disco_stun_srv_resolve_cb,
-			                                js);
-			g_object_unref(resolver);
-			/* TODO: add TURN support later... */
-		}
 	}
 
 	for (child = purple_xmlnode_get_child(query, "feature"); child;
--- a/libpurple/protocols/jabber/jabber.c	Fri Feb 17 04:54:01 2023 -0600
+++ b/libpurple/protocols/jabber/jabber.c	Fri Feb 17 04:54:38 2023 -0600
@@ -936,8 +936,6 @@
 	js->protocol_version.major = 1;
 	js->protocol_version.minor = 0;
 	js->sessions = NULL;
-	js->stun_ip = NULL;
-	js->stun_port = 0;
 
 	/* if we are idle, set idle-ness on the stream (this could happen if we get
 		disconnected and the reconnects while being idle. I don't think it makes
@@ -1143,8 +1141,6 @@
 	g_cancellable_cancel(js->cancellable);
 	g_object_unref(G_OBJECT(js->cancellable));
 
-	g_free(js->stun_ip);
-
 	g_free(js);
 
 	purple_connection_set_protocol_data(gc, NULL);
--- a/libpurple/protocols/jabber/jabber.h	Fri Feb 17 04:54:01 2023 -0600
+++ b/libpurple/protocols/jabber/jabber.h	Fri Feb 17 04:54:38 2023 -0600
@@ -245,9 +245,6 @@
 
 	/* keep a hash table of JingleSessions */
 	GHashTable *sessions;
-
-	gchar *stun_ip;
-	int stun_port;
 };
 
 typedef gboolean (JabberFeatureEnabled)(JabberStream *js, const gchar *namespace);
--- a/libpurple/protocols/jabber/jingle/jingle.c	Fri Feb 17 04:54:01 2023 -0600
+++ b/libpurple/protocols/jabber/jingle/jingle.c	Fri Feb 17 04:54:38 2023 -0600
@@ -459,57 +459,34 @@
 }
 
 GHashTable *
-jingle_get_params(JabberStream *js, const gchar *relay_ip, guint relay_udp,
-	guint relay_tcp, guint relay_ssltcp, const gchar *relay_username,
-	const gchar *relay_password)
+jingle_get_params(G_GNUC_UNUSED JabberStream *js, const gchar *relay_ip,
+                  guint relay_udp, guint relay_tcp, guint relay_ssltcp,
+                  const gchar *relay_username, const gchar *relay_password)
 {
-	/* don't set a STUN server if one is set globally in prefs, in that case
-	 this will be handled in media.c */
-	gboolean has_account_stun = js->stun_ip && !purple_network_get_stun_ip();
 	GHashTable *params = NULL;
 	GValue *value = NULL;
 
-	if (has_account_stun || relay_ip) {
+	if(relay_ip) {
+		GPtrArray *relay_info = g_ptr_array_new_full(1, (GDestroyNotify)gst_structure_free);
+
 		params = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, (GDestroyNotify)jingle_param_free);
 
-		if (has_account_stun) {
-			purple_debug_info("jabber",
-				"setting param stun-ip for stream using auto-config: %s\n",
-				js->stun_ip);
-			value = g_new(GValue, 1);
-			g_value_init(value, G_TYPE_STRING);
-			g_value_set_string(value, js->stun_ip);
-			g_hash_table_insert(params, "stun-ip", value);
-
-			purple_debug_info("jabber",
-				"setting param stun-port for stream using auto-config: %d\n",
-				js->stun_port);
-			value = g_new(GValue, 1);
-			g_value_init(value, G_TYPE_UINT);
-			g_value_set_uint(value, js->stun_port);
-			g_hash_table_insert(params, "stun-port", value);
+		if (relay_udp) {
+			jingle_create_relay_info(relay_ip, relay_udp, relay_username,
+				relay_password, "udp", relay_info);
+		}
+		if (relay_tcp) {
+			jingle_create_relay_info(relay_ip, relay_tcp, relay_username,
+				relay_password, "tcp", relay_info);
 		}
-
-		if (relay_ip) {
-			GPtrArray *relay_info = g_ptr_array_new_full(1, (GDestroyNotify)gst_structure_free);
-
-			if (relay_udp) {
-				jingle_create_relay_info(relay_ip, relay_udp, relay_username,
-					relay_password, "udp", relay_info);
-			}
-			if (relay_tcp) {
-				jingle_create_relay_info(relay_ip, relay_tcp, relay_username,
-					relay_password, "tcp", relay_info);
-			}
-			if (relay_ssltcp) {
-				jingle_create_relay_info(relay_ip, relay_ssltcp, relay_username,
-					relay_password, "tls", relay_info);
-			}
-			value = g_new(GValue, 1);
-			g_value_init(value, G_TYPE_PTR_ARRAY);
-			g_value_take_boxed(value, relay_info);
-			g_hash_table_insert(params, "relay-info", value);
+		if (relay_ssltcp) {
+			jingle_create_relay_info(relay_ip, relay_ssltcp, relay_username,
+				relay_password, "tls", relay_info);
 		}
+		value = g_new(GValue, 1);
+		g_value_init(value, G_TYPE_PTR_ARRAY);
+		g_value_take_boxed(value, relay_info);
+		g_hash_table_insert(params, "relay-info", value);
 	}
 
 	return params;

mercurial