/soc/2013/ashmew2/filetransferX: ef1c61fd13b3: Added relay candi...
Ashish Gupta
ashmew2 at gmail.com
Thu Aug 15 18:41:45 EDT 2013
Changeset: ef1c61fd13b30ec18be97a93f6d3c04c74882898
Author: Ashish Gupta <ashmew2 at gmail.com>
Date: 2013-08-16 04:00 +0530
Branch: filetransferX
URL: https://hg.pidgin.im/soc/2013/ashmew2/filetransferX/rev/ef1c61fd13b3
Description:
Added relay candidates to XferSessionData
diffstat:
libpurple/protocols/jabber/google/google_session.c | 158 ++++++++++++++++++--
libpurple/protocols/jabber/google/relay.c | 7 +-
libpurple/protocols/jabber/google/relay.h | 6 +
3 files changed, 149 insertions(+), 22 deletions(-)
diffs (truncated from 322 to 300 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
@@ -27,6 +27,7 @@
#include "network.h"
#include "stun.h"
#include "media.h"
+#include "relay.h"
#include <nice/agent.h>
#ifdef USE_VV
@@ -395,6 +396,8 @@ jabber_google_relay_response_session_ini
(GoogleAVSessionData *) session->session_data;
GoogleXferSessionData *share_session =
session_data->share_session;
+ NiceCandidate *relay_candidate_udp, *relay_candidate_tcp;
+ NiceCandidate *relay_candidate_ssltcp;
if(session_data->share) {
/*TODO: Relocate? Define a new function? Only time will tell :P
@@ -405,12 +408,45 @@ jabber_google_relay_response_session_ini
GoogleXferSessionData *share_session = session_data->share_session;
NiceAgent *agent = nice_agent_new_reliable (NULL, NICE_COMPATIBILITY_RFC5245);
guint stream_id;
+
+ /*Add relay candidates to our candidate list?*/
+/* * candidate address='49.248.181.68' port='46448' username='HKmLfAkZB81f7r8x' password='' preference='0.000000' protocol='udp' type='stun' component='1' network='0' generation='0' name='private-1'
+ */
+
+ share_session->share_agent = agent;
+ stream_id = nice_agent_add_stream (agent, 1);
+ share_session->stream_id = stream_id;
+
+/*TODO: Add candidates here to the local_candidates GList in GoogleXferSessionData;*/
+
+ relay_candidate_udp = nice_candidate_new(NICE_CANDIDATE_TYPE_RELAYED);
+ relay_candidate_udp->transport = NICE_CANDIDATE_TRANSPORT_UDP;
+ relay_candidate_udp->priority = 0;
+ relay_candidate_udp->stream_id = stream_id;
+ relay_candidate_udp->username = g_strdup_printf("%s",relay_username);
+ relay_candidate_udp->password = g_strdup_printf("%s",relay_password);
+ nice_address_set_from_string(&relay_candidate_udp->addr, relay_ip);
+ nice_address_set_port(&relay_candidate_udp->addr, relay_udp);
+
+ relay_candidate_tcp = nice_candidate_copy(relay_candidate_udp);
+ nice_address_set_port(&relay_candidate_tcp->addr, relay_tcp);
+
+ relay_candidate_ssltcp = nice_candidate_copy(relay_candidate_udp);
+ nice_address_set_port(&relay_candidate_ssltcp->addr, relay_ssltcp);
+
+ share_session->local_share_candidates = g_list_prepend(share_session->local_share_candidates, relay_candidate_udp);
+ share_session->local_share_candidates = g_list_prepend(share_session->local_share_candidates, relay_candidate_tcp);
+ share_session->local_share_candidates = g_list_prepend(share_session->local_share_candidates, relay_candidate_ssltcp);
+
+ purple_debug_info("google_session", "Added relay candidates without a crash");
+
purple_debug_info("google_session", "Trying to Set Relay IP : %s\n", relay_ip);
- if(nice_agent_set_relay_info (agent, share_session->stream_id, 0, relay_ip, 80, relay_username,
+ if(!nice_agent_set_relay_info (agent, share_session->stream_id, 0, relay_ip, relay_udp, relay_username,
relay_password, NICE_RELAY_TYPE_TURN_UDP))
purple_debug_info("google_session","Setting Relay on Niceagent Failed..\n");
else
- purple_debug_info("google_session","Setting Relay on Niceagent Failed..\n");
+ purple_debug_info("google_session","Setting Relay on Niceagent Succeeded..\n");
+ return;
}
session_data->media = purple_media_manager_create_media(
@@ -838,6 +874,14 @@ google_session_handle_info(JabberStream
}
static void
+gtalk_get_request_cb(PurpleUtilFetchUrlData *url_data,
+ gpointer user_data, const gchar *url_text, gsize len,
+ const gchar *error_message)
+{
+ purple_debug_info("google_session", "inside gtalk_get_request_cb");
+}
+
+static void
google_session_handle_candidates(JabberStream *js, GoogleSession *session, xmlnode *sess, const char *iq_id)
{
JabberIq *result;
@@ -847,7 +891,11 @@ google_session_handle_candidates(JabberS
char n[4];
GoogleAVSessionData *session_data =
(GoogleAVSessionData *) session->session_data;
-
+ GoogleXferSessionData* share_session =
+ session_data->share_session;
+
+ gchar *temp_ip;
+
cand_parent = sess;
if(session_data->share) {
transport = xmlnode_get_child(sess, "transport");
@@ -866,6 +914,8 @@ google_session_handle_candidates(JabberS
const gchar *preference = xmlnode_get_attrib(cand, "preference");
guint component_id;
+ temp_ip = g_strdup(address);
+
if (cname && type && address && port) {
PurpleMediaCandidateType candidate_type;
guint prio = preference ? g_ascii_strtod(preference, NULL) * 1000 : 0;
@@ -945,6 +995,35 @@ google_session_handle_candidates(JabberS
jabber_iq_set_id(result, iq_id);
xmlnode_set_attrib(result->node, "to", session->remote_jid);
jabber_iq_send(result);
+
+/* TODO: Relocate me to proper place */
+
+ if(1) {
+ PurpleUtilFetchUrlData *url_data = NULL;
+ gchar *url = g_strdup_printf("http://%s", temp_ip);
+ gchar *request =
+ g_strdup_printf("Connection: Keep-Alive\r\n"
+ "Content-Length: 0\r\n"
+ "User-Agent: Google Talk\r\n"
+ "\r\n"
+ "GET %s HTTP/1.1\r\n\r\n"
+ ,share_session->source_url);
+
+ JabberGoogleRelayCallbackData *data = g_new0(JabberGoogleRelayCallbackData, 1);
+
+ data->session = session;
+ data->cb = NULL;
+
+ purple_debug_info("google_session","Sending GET Request For File..\n");
+ url_data =
+ purple_util_fetch_url_request(url, FALSE, NULL, FALSE, request, FALSE,
+ gtalk_get_request_cb, data);
+ if (url_data)
+ purple_debug_info("google_session", "Got some finite data..\n");
+ else
+ purple_debug_info("google_session", "Got no data....\n");
+
+ }
}
static void
@@ -1067,11 +1146,19 @@ gtalk_port_cb(int listenfd, gpointer dat
void
cb_candidate_gathering_done(NiceAgent *agent, guint stream_id, gpointer user_data)
{
-/* guint stream_id = temp->stream_id;
+/*
+ guint stream_id = temp->stream_id;
NiceAgent *agent = temp->agent;
*/
GList *lcands = nice_agent_get_local_candidates(agent, stream_id, 1);
char *local_ufrag, *local_password;
+ GoogleSession *session = (GoogleSession *)user_data;
+ JabberStream *js = session->js;
+ char *buf1,*buf2,*buf3;
+ gchar *me = g_strdup_printf("%s@%s/%s",
+ js->user->node,
+ js->user->domain,
+ js->user->resource);
nice_agent_get_local_credentials(agent, stream_id,
&local_ufrag, &local_password);
@@ -1080,13 +1167,12 @@ cb_candidate_gathering_done(NiceAgent *a
if(lcands) {
GList *iter = lcands;
- GoogleSession *session = (GoogleSession *)user_data;
GoogleAVSessionData *session_data = (GoogleAVSessionData *)session->session_data;
GoogleXferSessionData *share_session = (GoogleXferSessionData *)session_data->share_session;
- purple_debug_info("google_session", "lcands is nOT null..\n");
+ purple_debug_info("google_session", "lcands is NOT null..\n");
for(; iter; iter = iter->next) {
NiceCandidate *candid = (NiceCandidate *)iter->data;
-/*Insert it into our GoogleXferSession's local_share_candidates*/
+ /*Insert it into our GoogleXferSession's local_share_candidates*/
share_session->local_share_candidates = g_list_prepend(share_session->local_share_candidates, candid);
if(1) {
@@ -1174,16 +1260,26 @@ cb_candidate_gathering_done(NiceAgent *a
g_free(port);
g_free(username);
g_free(password);
-
jabber_iq_send(iq);
}
/*TODO: Put me at my proper location*/
- /*Sending each candidate here itself*/
-
+ /*Sending each candidate here itself*/
}
+
+
}
else
purple_debug_info("google_session", "lcands is NULL\n");
+
+/*Send relay candidates. TODO: Relocate and Fix Initiator*/
+ buf1=g_strdup_printf("<iq to=\"%s\" type=\"set\" id=\"%s\" from=\"%s\"><session type=\"transport-info\" id=\"%s\" initiator=\"%s\" xmlns=\"http://www.google.com/session\"><transport xmlns=\"http://www.google.com/transport/p2p\"><candidate name=\"private-1\" address=\"74.125.135.127\" port=\"19305\" preference=\"0\" username=\"foob0aasdasda\" protocol=\"udp\" generation=\"0\" password=\"lalalsdlsad2\" type=\"relay\" network=\"0\"/></transport></session></iq>", session->remote_jid, jabber_get_next_id(js), me, session->id.id, session->remote_jid);
+ buf2=g_strdup_printf("<iq to=\"%s\" type=\"set\" id=\"%s\" from=\"%s\"><session type=\"transport-info\" id=\"%s\" initiator=\"%s\" xmlns=\"http://www.google.com/session\"><transport xmlns=\"http://www.google.com/transport/p2p\"><candidate name=\"private-1\" address=\"74.125.135.127\" port=\"19305\" preference=\"0\" username=\"foob0aasdasda\" protocol=\"udp\" generation=\"0\" password=\"lalalsdlsad2\" type=\"relay\" network=\"0\"/></transport></session></iq>", session->remote_jid, jabber_get_next_id(js), me, session->id.id, session->remote_jid);
+ buf3=g_strdup_printf("<iq to=\"%s\" type=\"set\" id=\"%s\" from=\"%s\"><session type=\"transport-info\" id=\"%s\" initiator=\"%s\" xmlns=\"http://www.google.com/session\"><transport xmlns=\"http://www.google.com/transport/p2p\"><candidate name=\"private-1\" address=\"74.125.135.127\" port=\"443\" preference=\"0\" username=\"foob0aasdasda\" protocol=\"udp\" generation=\"0\" password=\"lalalsdlsad2\" type=\"relay\" network=\"0\"/></transport></session></iq>", session->remote_jid, jabber_get_next_id(js), me, session->id.id, session->remote_jid);
+
+ jabber_send_raw(js,buf1,strlen(buf1));
+ jabber_send_raw(js,buf2,strlen(buf2));
+ jabber_send_raw(js,buf3,strlen(buf3));
+ purple_debug_info("google_session", "Sent ALL CANDIDATES \n");
}
void
@@ -1196,15 +1292,45 @@ cb_nice_recv(NiceAgent *agent, guint str
void
gtalk_xfer_send_candidates(GoogleSession *session)
{
+/*Successful sample of sending candidates :
+Received this list :
- guint stream_id;
+* iq xmlns='jabber:client' to='doondoon1234 at gmail.com/b35d7c07' type='set' id='49' from='eionrobb at gmail.com/Talk.v10477686AA7'
+ * session xmlns='http://www.google.com/session' type='transport-info' id='1047464894' initiator='doondoon1234 at gmail.com/b35d7c07'
+ * transport xmlns='http://www.google.com/transport/p2p'
+x * candidate name='private-1' address='10.0.0.177' port='59851' preference='1' username='VO2xc53vhwD3+yve' protocol='udp' generation='0' password='KLk2cMGnK6TC2DNR' type='local' network='0'
+
+
+* iq xmlns='jabber:client' to='doondoon1234 at gmail.com/b35d7c07' type='set' id='50' from='eionrobb at gmail.com/Talk.v10477686AA7'
+ * session xmlns='http://www.google.com/session' type='transport-info' id='1047464894' initiator='doondoon1234 at gmail.com/b35d7c07'
+ * transport xmlns='http://www.google.com/transport/p2p'
+ * candidate name='private-1' address='131.203.245.222' port='59852' preference='0.9' username='M2bzFytmwffmxdg2' protocol='udp' generation='0' password='K6T8Zo1RiuAZPdQQ' type='stun' network='0'
+wocky/-DEBUG: 08/08/2013 00:45:41.963341: _write_node_tree: Serializing tree:
+
+OUR Response :
+
+* iq xmlns='jabber:client' type='set' to='eionrobb at gmail.com/Talk.v10477686AA7' id='82139671'
+ * session xmlns='http://www.google.com/session' initiator='doondoon1234 at gmail.com/b35d7c07' id='1047464894' type='transport-info'
+ * transport xmlns='http://www.google.com/transport/p2p'
+ * candidate address='192.168.19.101' port='46448' username='281fPx+dTKp+JC4T' password='' preference='0.000015' protocol='udp' type='local' component='1' network='0' generation='0' name='private-1'
+ * candidate address='74.125.135.127' port='19305' username='JkrSpsOQtm6rNIHp' password='' preference='0.000000' protocol='udp' type='relay' component='1' network='0' generation='0' name='private-1'
+ * candidate address='49.248.181.68' port='46448' username='HKmLfAkZB81f7r8x' password='' preference='0.000000' protocol='udp' type='stun' component='1' network='0' generation='0' name='private-1'
+ * candidate address='74.125.135.127' port='19305' username='JkrSpsOQtm6rNIHp' password='' preference='0.000000' protocol='udp' type='relay' component='1' network='0' generation='0' name='private-1'
+ * candidate address='74.125.135.127' port='443' username='JkrSpsOQtm6rNIHp' password='' preference='0.000000' protocol='udp' type='relay' component='1' network='0' generation='0' name='private-1'
+
+This will most probably end in successful candidate exchange.
+ */
+
gchar buffer[] = "hello world!";
GSList *lcands = NULL, *rcands = NULL;
TempStruct *temp_struct = g_new0(TempStruct, 1);
GMainLoop *gloop;
- // Create a nice agent
- NiceAgent *agent = nice_agent_new_reliable (NULL, NICE_COMPATIBILITY_RFC5245);
+ GoogleAVSessionData *session_data = (GoogleAVSessionData *)session->session_data;
+ GoogleXferSessionData *share_session = session_data->share_session;
+
+ NiceAgent *agent = share_session->share_agent;
JabberStream *js = session->js;
+ guint stream_id = share_session->stream_id;
if(!g_object_get_data(G_OBJECT (agent), "stun->server")) {
purple_debug_info("google_session", "Agent's STUN is NULL..");
@@ -1228,9 +1354,10 @@ gtalk_xfer_send_candidates(GoogleSession
*/
// Create a new stream with one component and start gathering candidates
+/* Removed and put in handle_initiate_cb()
stream_id = nice_agent_add_stream (agent, 1);
temp_struct->stream_id = stream_id;
-
+*/
nice_agent_attach_recv(agent, stream_id, 1,
g_main_loop_get_context (gloop), cb_nice_recv, NULL);
/* nice_agent_attach_recv (agent, stream_id, 1, NULL,
@@ -1238,7 +1365,6 @@ gtalk_xfer_send_candidates(GoogleSession
*/
g_signal_connect (G_OBJECT (agent), "candidate-gathering-done",
G_CALLBACK (cb_candidate_gathering_done), session);
-
if(!nice_agent_gather_candidates (agent, stream_id))
purple_debug_info("google_session", "Gather candidates returned FALSE\n");
@@ -1669,7 +1795,7 @@ google_session_parse_iq(JabberStream *js
if(local_received && stun_received) {
/*Time to send out our candidates if both the local and stun have been received*/
purple_debug_info("google_session", "Calling send candidates.\n");
- gtalk_xfer_send_candidates(session);
+// gtalk_xfer_send_candidates(session);
local_received = stun_received = FALSE;
}
// google_xfer_send(js,session);
diff --git a/libpurple/protocols/jabber/google/relay.c b/libpurple/protocols/jabber/google/relay.c
--- a/libpurple/protocols/jabber/google/relay.c
+++ b/libpurple/protocols/jabber/google/relay.c
@@ -23,11 +23,6 @@
#include "relay.h"
-typedef struct {
- GoogleSession *session;
- JabberGoogleRelayCallback *cb;
-} JabberGoogleRelayCallbackData;
-
static void
jabber_google_relay_parse_response(const gchar *response, gchar **ip,
More information about the Commits
mailing list