/soc/2013/ashmew2/filetransferX: 51258728fd4a: Possible candidat...

Ashish Gupta ashmew2 at gmail.com
Wed Aug 7 21:49:08 EDT 2013


Changeset: 51258728fd4a0588b14bf880b2c83752c8ff96de
Author:	 Ashish Gupta <ashmew2 at gmail.com>
Date:	 2013-08-08 07:18 +0530
Branch:	 filetransferX
URL: https://hg.pidgin.im/soc/2013/ashmew2/filetransferX/rev/51258728fd4a

Description:

Possible candidate fix

diffstat:

 libpurple/protocols/jabber/google/google_session.c |  134 ++++++++++++++++++--
 1 files changed, 116 insertions(+), 18 deletions(-)

diffs (197 lines):

diff --git a/libpurple/protocols/jabber/google/google_session.c b/libpurple/protocols/jabber/google/google_session.c
--- a/libpurple/protocols/jabber/google/google_session.c
+++ b/libpurple/protocols/jabber/google/google_session.c
@@ -877,7 +877,7 @@ google_session_handle_candidates(JabberS
 				session_data->share_session->remote_share_candidates = 
 					g_list_append(session_data->share_session->remote_share_candidates,
 						      info);
-				purple_debug_info("google_session", "Added remote_candid to sharelist\n");
+				purple_debug_info("google_session", "Added candidate to sharelist\n");
 			}
 		}
 		else {
@@ -1026,6 +1026,8 @@ gtalk_xfer_send_candidates(GoogleSession
 	GoogleAVSessionData *session_data =  session->session_data;
 	GoogleXferSessionData *share_session = session_data->share_session;
 
+/* TODO:From what I learnt about the GTalk File Transfers, GTalk always sends out two candidates, one local and one stun. We need to reciprocate with our local address, our public (stun) address and 3 relay addresses (which is Google's STUN IP, js->stun_ip). So this only needs to be modified according to that. Furthermore, once the candidates are sent out properly, assuming we are the sender of the file, we get a HTTP GET/ REquest by Gtalk with the source-url of the file. Then the actual data of file moves. */
+
 	GList *candidates = share_session->remote_share_candidates;
 	/*TODO: Candidates should be only local according to the existing media implementation..Why? Let's keep it that way for now in the loop*/
 	GList *iter;
@@ -1112,6 +1114,91 @@ gtalk_xfer_send_candidates(GoogleSession
 	purple_media_candidate_list_free(candidates);
 }
 
+void
+gtalk_xfer_send_candidate(GoogleSession *session, GList *ip_list)
+{	
+	GoogleAVSessionData *session_data =  session->session_data;
+	GoogleXferSessionData *share_session = session_data->share_session;
+
+/* From what I learnt about the GTalk File Transfers, GTalk always sends out two candidates, one local and one stun. We need to reciprocate with our local address, our public (stun) address and 3 relay addresses (which is Google's STUN IP, js->stun_ip). So this only needs to be modified according to that. Furthermore, once the candidates are sent out properly, assuming we are the sender of the file, 
+	GList *candidates = share_session->remote_share_candidates;
+	/*TODO: Candidates should be only local according to the existing media implementation..Why? Let's keep it that way for now in the loop*/
+
+	purple_debug_info("google_session", "Inside gtalk_xfer_send_candidatE()\n");
+
+	PurpleMediaCandidate *transport;
+
+	JabberIq *iq;
+	gchar *ip, *port, *username, *password;
+	gchar pref[16];
+	PurpleMediaCandidateType type;
+	xmlnode *sess;
+	xmlnode *candidate;
+	xmlnode *transport_node;
+
+	purple_debug_info("google_session", "inside iter loop..\n");
+	
+	transport = PURPLE_MEDIA_CANDIDATE(iter->data);
+	
+	iq = jabber_iq_new(session->js, JABBER_IQ_SET);
+	sess = google_session_create_xmlnode(session, "transport-info");
+	xmlnode_insert_child(iq->node, sess);
+	
+	xmlnode_set_attrib(iq->node, "to", session->remote_jid);
+	
+	candidate = xmlnode_new("candidate");
+	transport_node = xmlnode_new("transport");
+	
+	ip = purple_media_candidate_get_ip(transport);
+	port = g_strdup_printf("%d",
+			       purple_media_candidate_get_port(transport));
+	g_ascii_dtostr(pref, 16,
+		       purple_media_candidate_get_priority(transport) / 1000.0);
+	username = purple_media_candidate_get_username(transport);
+	password = purple_media_candidate_get_password(transport);
+	type = purple_media_candidate_get_candidate_type(transport);
+	if(ip)
+		xmlnode_set_attrib(candidate, "address", ip);
+	if(port)
+		xmlnode_set_attrib(candidate, "port", port);
+	if(username)
+		xmlnode_set_attrib(candidate, "username", username);
+	
+	xmlnode_set_attrib(candidate, "name", "private-1");
+	xmlnode_set_attrib(candidate, "password",
+			   password != NULL ? password : "");
+	if(pref)
+		xmlnode_set_attrib(candidate, "preference", pref);
+	
+	xmlnode_set_attrib(candidate, "protocol",
+			   purple_media_candidate_get_protocol(transport)
+			   == PURPLE_MEDIA_NETWORK_PROTOCOL_UDP ?
+			   "udp" : "tcp");
+	
+	xmlnode_set_attrib(candidate, "type", type ==
+			   PURPLE_MEDIA_CANDIDATE_TYPE_SRFLX ? "stun" :
+			   type ==
+			   PURPLE_MEDIA_CANDIDATE_TYPE_RELAY ? "relay" :
+			   "local"
+		);
+	
+	xmlnode_set_attrib(candidate, "generation", "0");
+	xmlnode_set_attrib(candidate, "network", "0");
+	
+	xmlnode_insert_child(sess, transport_node);
+	xmlnode_insert_child(transport_node, candidate);
+	xmlnode_set_namespace(transport_node, NS_GOOGLE_TRANSPORT_P2P);
+	
+	g_free(ip);
+	g_free(port);
+	g_free(username);
+	g_free(password);
+	
+	jabber_iq_send(iq);
+
+	purple_debug_info("google_session", "outside iter loop..\n");
+}
+
 
 void
 gtalk_xfer_start(PurpleXfer *xfer)
@@ -1163,7 +1250,18 @@ gtalk_xfer_send(PurpleConnection *gc, co
   PurpleStunNatDiscovery *stun_discovery;
 
   xfer = gtalk_xfer_new(gc, who);
-  
+  purple_debug_info("google_session", "Just Created an Xfer.");
+  if(1) {
+	  GList *iplist = purple_network_get_all_local_system_ips();
+	  GList *iter;
+	  for(iter = iplist; iter; iter=iter->next) {
+		  purple_debug_info("google_session", "\n <ALL> IP : %s\n",iter->data);
+	  }
+			g_list_free(iplist);
+			purple_debug_info("google_session", "get_pub_ip : %s",purple_network_get_public_ip());
+			
+  }
+
   if(!xfer) {
 	  purple_debug_info("google_session", "Failed to Create an Xfer for Sending a File..");
 	  return;
@@ -1461,6 +1559,8 @@ google_session_parse_iq(JabberStream *js
 	const char *type = xmlnode_get_attrib(sess, "type");
 	purple_debug_info("google_session", "\nType of IQ being parsed : %s\n, STUN IP : %s\n",type,purple_network_get_stun_ip());
 	GoogleAVSessionData *session_data = (GoogleAVSessionData *)(session->session_data);
+	static gboolean local_received=FALSE, stun_received=FALSE;
+	xmlnode *candidate, *transport;
 
 	if (!strcmp(type, "initiate")) {
 		google_session_handle_initiate(js, session, sess, iq_id);
@@ -1472,14 +1572,24 @@ google_session_parse_iq(JabberStream *js
 		google_session_handle_reject(js, session, sess);
 	} else if (!strcmp(type, "terminate")) {
 		google_session_handle_terminate(js, session, sess);
-
 	} else if (!strcmp(type, "candidates")) {
 		google_session_handle_candidates(js, session, sess, iq_id);
 	} else if (!strcmp(type, "transport-accept")) {
 		purple_debug_info("google_session", "Inside transport-accept handle block..Calling it now..\n");
 		google_session_handle_transport_accept(js, session, sess, iq_id);
 	} else if (!strcmp(type, "transport-info")) {
+		transport = xmlnode_get_child(sess, "transport");
+		candidate = xmlnode_get_child(transport, "candidate");
+		if (!strcmp(xmlnode_get_attrib(candidate, "type"), "local"))
+			local_received = TRUE;
+		if (!strcmp(xmlnode_get_attrib(candidate, "type"), "stun"))
+			stun_received = TRUE;
+
 		google_session_handle_transport_info(js, session, sess, iq_id);
+		if(local_received && stun_received) {
+			/*Time to send out our candidates if both the local and stun have been received*/
+			gtalk_xfer_send_candidates(
+		}
 //		google_xfer_send(js,session);
 //		purple_debug_info("google_session", "Back in parse_iq\n");
 //		if(js->stun_ip)
@@ -1487,25 +1597,13 @@ google_session_parse_iq(JabberStream *js
 		static int num_candid=0;
 		num_candid++;
 		if(num_candid==2) {
-			purple_debug_info("google_session", "Calling send_candids()\n");
-			gtalk_xfer_send_candidates(session);
+//			purple_debug_info("google_session", "Calling send_candids()\n");
+//			gtalk_xfer_send_candidates(session);
 		}
-
-/*		if(1) {
-			GList *iplist = purple_network_get_all_local_system_ips();
-			GList *iter;
-			for(iter = iplist; iter; iter=iter->next) {
-				purple_debug_info("google_session", "\nIP : %s\n",iter->data);
-			}
-			g_list_free(iplist);
-			purple_debug_info("google_session", "get_pub_ip : %s",purple_network_get_public_ip());
-			
-			}*/
 	}
 	else {
 		purple_debug_info("google_session", "No suitable IQ Parse Handler Found..\n");
-	}
-	
+	}	
 }
 
 	



More information about the Commits mailing list