/soc/2013/ashmew2/filetransferX: 6833ab2ddc2d: Changed GoogleXfe...
Ashish Gupta
ashmew2 at gmail.com
Mon Aug 19 19:25:51 EDT 2013
Changeset: 6833ab2ddc2d90e197b561b5cde300a276929524
Author: Ashish Gupta <ashmew2 at gmail.com>
Date: 2013-08-20 01:44 +0530
Branch: filetransferX
URL: https://hg.pidgin.im/soc/2013/ashmew2/filetransferX/rev/6833ab2ddc2d
Description:
Changed GoogleXferSessionData struct
diffstat:
libpurple/protocols/jabber/google/google_session.c | 183 +++++++++++++++++---
1 files changed, 153 insertions(+), 30 deletions(-)
diffs (truncated from 381 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
@@ -29,6 +29,7 @@
#include "media.h"
#include "relay.h"
#include <nice/agent.h>
+#include <nice/pseudotcp.h>
#ifdef USE_VV
@@ -54,13 +55,18 @@ typedef struct {
guint64 filesize;
gchar *preview_url;
gchar *source_url;
+ PurpleXfer *xfer;
/*Needs to have a manifest Entry for Folder Sharing*/
NiceAgent *share_agent; /*TODO : Assess the usefulness of share_agent and stream_id*/
ShareChannel *share_channel;
+ NiceComponentState agent_state;
+ PurpleCircBuffer *buffer;
guint stream_id;
GList *remote_share_candidates; /* lists of PurpleMediaCandidate OR NiceCandidates(maybe?)*/
GList *local_share_candidates;
+
} GoogleXferSessionData;
+/*Thanks to malu*/
typedef struct {
NiceAgent *agent;
@@ -417,7 +423,7 @@ jabber_google_relay_response_session_ini
session_data->share_session;
NiceCandidate *relay_candidate_udp, *relay_candidate_tcp;
NiceCandidate *relay_candidate_ssltcp;
- guint stream_id;
+ guint stream_id = share_session->stream_id;
NiceAgent *agent;
if(session_data->share) {
@@ -427,7 +433,8 @@ jabber_google_relay_response_session_ini
return;
*/
GoogleXferSessionData *share_session = session_data->share_session;
-
+ agent = share_session->share_agent;
+
if(!share_session->share_agent) {
agent = nice_agent_new_reliable (NULL, NICE_COMPATIBILITY_RFC5245);
/*Add relay candidates to our candidate list?*/
@@ -453,13 +460,18 @@ jabber_google_relay_response_session_ini
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_udp->turn = g_new0(TurnServer, 1);
+ nice_address_set_from_string(&relay_candidate_udp->turn->server, relay_ip);
+ relay_candidate_udp->turn->type = NICE_RELAY_TYPE_TURN_UDP;
+ relay_candidate_udp->turn->username = g_strdup_printf("%s",relay_username);
+ relay_candidate_udp->turn->password = g_strdup_printf("%s",relay_password);
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_append(share_session->local_share_candidates, relay_candidate_udp);
share_session->local_share_candidates = g_list_append(share_session->local_share_candidates, relay_candidate_tcp);
share_session->local_share_candidates = g_list_append(share_session->local_share_candidates, relay_candidate_ssltcp);
@@ -467,19 +479,32 @@ jabber_google_relay_response_session_ini
purple_debug_info("google_session", "Added relay candidates without a crash.\n");
/* purple_debug_info("google_session", "Trying to Set Relay IP : %s\n", relay_ip);*/
+ if (relay_ip) {
+ if (relay_udp)
+ nice_agent_set_relay_info(agent, share_session->stream_id, 1, relay_ip, relay_udp,
+ relay_username, relay_password, NICE_RELAY_TYPE_TURN_UDP);
+ if (relay_tcp)
+ nice_agent_set_relay_info(agent, share_session->stream_id, 1, relay_ip, relay_tcp,
+ relay_username, relay_password, NICE_RELAY_TYPE_TURN_TCP);
+ if (relay_ssltcp)
+ nice_agent_set_relay_info(agent, share_session->stream_id, 1, relay_ip, relay_ssltcp,
+ relay_username, relay_password, NICE_RELAY_TYPE_TURN_TLS);
+ }
-/* if(!nice_agent_set_relay_info (agent, share_session->stream_id, 1, relay_ip, relay_udp, relay_username,
+/* nice_agent_set_relay_info (agent, share_session->stream_id, 1, 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 Succeeded..\n");
+*/
+ purple_debug_info("google_session", "Calling xfer_send_canddiates()\n");
/*TODO: Uncomment send_candidates below*/
gtalk_xfer_send_candidates(session);
return;
}
session_data->media = purple_media_manager_create_media(
- purple_media_manager_get(),
+ purple_media_manager_get(),v
purple_connection_get_account(js->gc),
"fsrtpconference", session->remote_jid, TRUE);
@@ -1107,6 +1132,12 @@ gtalk_xfer_handle_candidates(JabberStrea
JabberIq *result;
purple_debug_info("google_session", "Inside gtalk_xfer_handle_candidates..\n");
+
+ /*Sending IQ_RESULT first and then processing the candidate*/
+ result = jabber_iq_new(js, JABBER_IQ_RESULT);
+ jabber_iq_set_id(result, iq_id);
+ xmlnode_set_attrib(result->node, "to", session->remote_jid);
+ jabber_iq_send(result);
if(sess)
candidate_node = xmlnode_get_child(xmlnode_get_child(sess, "transport"), "candidate");
@@ -1142,11 +1173,6 @@ gtalk_xfer_handle_candidates(JabberStrea
}
purple_debug_info("google_session", "Added remote candidate to Nice Agent.\n");
-/*TODO: Send Result IQ as well*/
- result = jabber_iq_new(js, JABBER_IQ_RESULT);
- jabber_iq_set_id(result, iq_id);
- xmlnode_set_attrib(result->node, "to", session->remote_jid);
- jabber_iq_send(result);
}
static void
@@ -1261,6 +1287,31 @@ gtalk_port_cb(int listenfd, gpointer dat
}
+void pseudo_tcp_opened(PseudoTcpSocket *tcp, gpointer data)
+{
+ purple_debug_info("google_session", "Inside pseudo_tcp_opened!\n");
+}
+
+void pseudo_tcp_readable(PseudoTcpSocket *tcp, gpointer data)
+{
+ purple_debug_info("google_session", "Inside pseudo_tcp_readable\n");
+}
+
+void pseudo_tcp_writable(PseudoTcpSocket *tcp, gpointer data)
+{
+ purple_debug_info("google_session", "Inside pseudo_tcp_writable\n");
+}
+
+void pseudo_tcp_closed(PseudoTcpSocket *tcp, guint32 error, gpointer data)
+{
+ purple_debug_info("google_session", "Inside pseudo_tcp_closed\n");
+}
+
+PseudoTcpWriteResult pseudo_write_packet(PseudoTcpSocket *tcp, const gchar * buffer,
+ guint32 len, gpointer data)
+{
+ purple_debug_info("google_session", "Inside pseudo_write_packet with buffer : %s and len = %u\n", buffer, len);
+}
void
gtalk_xfer_send_candidates(GoogleSession *session)
@@ -1270,7 +1321,19 @@ gtalk_xfer_send_candidates(GoogleSession
GoogleXferSessionData *share_session = session_data->share_session;
GList *candidates = share_session->local_share_candidates;
GList *iter;
+ PseudoTcpCallbacks *tcp_cb = g_new0(PseudoTcpCallbacks, 1);
+ PseudoTcpSocket *tcp_socket;
+ /*Set up the callback struct */
+ tcp_cb->PseudoTcpOpened = pseudo_tcp_opened;
+ tcp_cb->PseudoTcpReadable = pseudo_tcp_readable;
+ tcp_cb->PseudoTcpWritable = pseudo_tcp_writable;
+ tcp_cb->PseudoTcpClosed = pseudo_tcp_closed;
+ tcp_cb->WritePacket = pseudo_write_packet;
+ /*End of callback assignment*/
+
+ tcp_socket = pseudo_tcp_socket_new(0, tcp_cb);
+
/*Is component ID necessary? This is a share session TODO*/
/* component_id = purple_media_candidate_get_component_id(
transport);
@@ -1285,6 +1348,17 @@ gtalk_xfer_send_candidates(GoogleSession
else
purple_debug_info("google_session","Getting local credentials SUCCESSFUL..\n");
*/
+/*TODO: Try to add a socket to the candidate */
+ purple_debug_info("google_session", "Trying to connect the socket");
+
+ if(tcp_socket)
+ purple_debug_info("google_session", "Socket is VALID and not null\n");
+
+/* if(pseudo_tcp_socket_connect(tcp_socket))
+ purple_debug_info("google_session", "Socket Connect returned TRUE!!\n");
+ else
+ purple_debug_info("google_session", "Socket Connect returned fALSE :'( \n");
+*/
for(iter = candidates; iter; iter = iter->next) {
JabberIq *iq;
gchar *ip = g_malloc(NICE_ADDRESS_STRING_LEN + 1);
@@ -1295,12 +1369,14 @@ gtalk_xfer_send_candidates(GoogleSession
NiceCandidate *nice_candid = (NiceCandidate *)iter->data;
NiceCandidateType type;
+ /*TODO: ADd TURN information for RELAY candidates most probably*/
+ nice_candid->sockptr = tcp_socket;
+
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);
- purple_debug_info("google_session", "IQ Created. Now Transport Node : \n");
transport = xmlnode_new("transport");
xmlnode_set_namespace(transport, NS_GOOGLE_TRANSPORT_P2P);
xmlnode_insert_child(sess, transport);
@@ -1346,6 +1422,18 @@ gtalk_xfer_send_candidates(GoogleSession
type == NICE_CANDIDATE_TYPE_RELAYED ? "relay"
: "local");
+ if(type == NICE_CANDIDATE_TYPE_RELAYED) {
+ if(nice_candid->turn) {
+ gchar *turn_ip = g_malloc(NICE_ADDRESS_STRING_LEN + 1);
+ purple_debug_info("google_session", "turn is NOT NULL..\n");
+ nice_address_to_string(&nice_candid->turn->server, turn_ip);
+ purple_debug_info("google_session", "turn IP : %s\n", turn_ip);
+ }
+ else
+ purple_debug_info("google_session", "TURN is NULL for candidate..\n");
+ }
+
+
xmlnode_set_attrib(candidate, "generation", "0");
xmlnode_set_attrib(candidate, "network", "0");
xmlnode_insert_child(transport, candidate);
@@ -1355,7 +1443,6 @@ gtalk_xfer_send_candidates(GoogleSession
g_free(username);
g_free(password);
jabber_iq_send(iq);
-
}
}
@@ -1422,7 +1509,7 @@ void
cb_nice_recv(NiceAgent *agent, guint stream_id, guint component_id,
guint len, gchar *buf, gpointer data)
{
- purple_debug_info("google_session", "Inside cb_nice_recv\n");
+ purple_debug_info("google_session", "__Inside cb_nice_recv\n");
}
char *nice_component_state_to_str(guint state)
@@ -1450,14 +1537,45 @@ char *nice_component_state_to_str(guint
void cb_nice_component_state_changed(NiceAgent *agent,guint stream_id, guint component_id,
guint state, gpointer user_data)
{
- purple_debug_info("google_session", "State of NiceAgent Changed...Current State : [%d]%s\n", state, nice_component_state_to_str(state));
- /*TODO: Add more stuff related to state changes here*/
+ GoogleXferSessionData *share_session = (GoogleXferSessionData *)user_data;
+
+ purple_debug_info("google_session", "__State of NiceAgent Changed...Current State : [%d]%s.Stream ID: %d", state, nice_component_state_to_str(state), stream_id);
+
+ if(state == NICE_COMPONENT_STATE_CONNECTED) {
+
+ /*
+ PurpleUtilFetchUrlData *url_data = NULL;
+ gchar *url = g_strdup_printf("http://%s", share_session->source_url);
+
+ url_data = purple_util_fetch_url_request(url, FALSE, NULL, TRUE, , FALSE,
+ jabber_google_relay_fetch_cb, data);*/
+ }
+
}
+/*TODO: Add more stuff related to state changes here*/
+
void cb_nice_component_writable(NiceAgent *agent, guint stream_id, guint component_id,
gpointer user_data)
{
- purple_debug_info("google_session", "WRITABLE NOW ! (Inside cb_nice_component_writable\n");
+ purple_debug_info("google_session", "__WRITABLE NOW ! (Inside cb_nice_component_writable\n");
+}
+
+void cb_new_selected_pair(NiceAgent *agent, guint stream_id, guint component_id,
+ gchar *lfoundation, gchar *rfoundation, gpointer user_data)
+{
+ purple_debug_info("google_session", "__GOT NEW SELECTED PAIR! with %s:%s", lfoundation, rfoundation);
+}
+
+void cb_new_candidate(NiceAgent *agent, guint stream_id, guint component_id,
+ gchar *foundation, gpointer user_data)
+{
+ purple_debug_info("google_session", "__NEW CANDIDATE!\n");
+}
+
+void cb_initial_binding(NiceAgent *agent, guint stream_id, gpointer user_data)
+{
+ purple_debug_info("google_session", "__Initial binding request..\n");
}
void
More information about the Commits
mailing list