/soc/2013/ashmew2/filetransferX: a38c45b1b30c: removed xfer_send...
Ashish Gupta
ashmew2 at gmail.com
Sat Aug 10 19:24:21 EDT 2013
Changeset: a38c45b1b30c0de499c094ab46271d911ebf0f0f
Author: Ashish Gupta <ashmew2 at gmail.com>
Date: 2013-08-09 21:58 +0530
Branch: filetransferX
URL: https://hg.pidgin.im/soc/2013/ashmew2/filetransferX/rev/a38c45b1b30c
Description:
removed xfer_send_candidate. Enter libnice
diffstat:
libpurple/media.h | 4 +
libpurple/protocols/jabber/google/google_session.c | 224 ++++----------------
2 files changed, 51 insertions(+), 177 deletions(-)
diffs (truncated from 312 to 300 lines):
diff --git a/libpurple/media.h b/libpurple/media.h
--- a/libpurple/media.h
+++ b/libpurple/media.h
@@ -46,6 +46,10 @@ G_BEGIN_DECLS
/** An opaque structure representing a media call. */
typedef struct _PurpleMedia PurpleMedia;
+/**This struct was not here, added for GTalk FT*/
+typedef struct _PurpleMediaSession PurpleMediaSession;
+typedef struct _PurpleMediaStream PurpleMediaStream;
+
#include "signals.h"
#include "util.h"
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
@@ -23,8 +23,11 @@
#include "google_session.h"
#include "relay.h"
#include "jingle/jingle.h"
+#include "jingle/transport.h"
#include "network.h"
#include "stun.h"
+#include "media.h"
+#include <nice/agent.h>
#ifdef USE_VV
@@ -100,6 +103,7 @@ static void
google_session_send_candidates(PurpleMedia *media, gchar *session_id,
gchar *participant, GoogleSession *session)
{
+
PurpleMedia *session_media =
((GoogleAVSessionData *) session->session_data)->media;
GList *candidates =
@@ -113,6 +117,8 @@ google_session_send_candidates(PurpleMed
if (!strcmp(session_id, "google-video"))
video = TRUE;
+ purple_debug_info("google_session", "Inside send_candidates()\n");
+
for (iter = candidates; iter; iter = iter->next) {
JabberIq *iq;
gchar *ip, *port, *username, *password;
@@ -171,7 +177,7 @@ google_session_send_candidates(PurpleMed
xmlnode_set_attrib(candidate, "generation", "0");
xmlnode_set_attrib(candidate, "network", "0");
xmlnode_insert_child(sess, candidate);
-
+ purple_debug_info("google_session", "Candidate's IP and PORT : %s:%s",ip,port);
g_free(ip);
g_free(port);
g_free(username);
@@ -916,7 +922,7 @@ google_session_handle_transport_accept(J
static void
google_session_handle_transport_info(JabberStream *js, GoogleSession *session, xmlnode *sess, const char *iq_id)
{
-
+
google_session_handle_candidates(js, session, sess, iq_id);
}
@@ -1021,185 +1027,53 @@ gtalk_port_cb(int listenfd, gpointer dat
}
void
-gtalk_xfer_send_candidates(GoogleSession *session)
-{
- 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;
- if(!candidates)
- purple_debug_info("google_session", "Candidate LIST is EMPTY!\n");
-
- purple_debug_info("google_session", "Inside gtalk_xfer_send_candidates()\n");
-
- PurpleMediaCandidate *transport;
- gboolean video = FALSE;
-
- for (iter = candidates; iter; iter = iter->next) {
- 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");
-
-/* guint component_id;*/
-
- 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");
- purple_media_candidate_list_free(candidates);
+cb_candidate_gathering_done(void)
+{
+ purple_debug_info("google_session", "CANDIDATES GATHERED??\n");
}
void
-gtalk_xfer_send_candidate(GoogleSession *session, GList *ip_list)
+gtalk_xfer_send_candidates(GoogleSession *session)
{
- GoogleAVSessionData *session_data = session->session_data;
- GoogleXferSessionData *share_session = session_data->share_session;
+ guint stream_id;
+ gchar buffer[] = "hello world!";
+ GSList *lcands = NULL, *rcands = NULL;
-/* 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*/
+ // Create a nice agent
+ NiceAgent *agent = nice_agent_new (NULL, NICE_COMPATIBILITY_GOOGLE);
- purple_debug_info("google_session", "Inside gtalk_xfer_send_candidatE()\n");
+ // Connect the signals
+ g_signal_connect (G_OBJECT (agent), "candidate-gathering-done",
+ G_CALLBACK (cb_candidate_gathering_done), NULL);
+ /* g_signal_connect (G_OBJECT (agent), "component-state-changed",
+ G_CALLBACK (cb_component_state_changed), NULL);
+ g_signal_connect (G_OBJECT (agent), "new-selected-pair",
+ G_CALLBACK (cb_new_selected_pair), NULL);
+ */
+ // Create a new stream with one component and start gathering candidates
+ stream_id = nice_agent_add_stream (agent, 1);
+ nice_agent_gather_candidates (agent, stream_id);
- PurpleMediaCandidate *transport;
+ // Attach to the component to receive the data
+ /* nice_agent_attach_recv (agent, stream_id, 1, NULL
+ cb_nice_recv, NULL);
+ */
+ // ... Wait until the signal candidate-gathering-done is fired ...
+ lcands = nice_agent_get_local_candidates(agent, stream_id, 1);
- JabberIq *iq;
- gchar *ip, *port, *username, *password;
- gchar pref[16];
- PurpleMediaCandidateType type;
- xmlnode *sess;
- xmlnode *candidate;
- xmlnode *transport_node;
+ // ... Send local candidates to the peer and set the peer's remote candidates
+ nice_agent_set_remote_candidates (agent, stream_id, 1, rcands);
- 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);
+ // ... Wait until the signal new-selected-pair is fired ...
+ // Send our message!
+ nice_agent_send (agent, stream_id, 1, sizeof(buffer), buffer);
- purple_debug_info("google_session", "outside iter loop..\n");
+ // Anything received will be received through the cb_nice_recv callback
+
+ // Destroy the object
+ g_object_unref(agent);
}
-
void
gtalk_xfer_start(PurpleXfer *xfer)
{
@@ -1584,22 +1458,18 @@ google_session_parse_iq(JabberStream *js
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(
+ purple_debug_info("google_session", "Calling send candidates.\n");
+ // gtalk_xfer_send_candidates(session);
+ local_received = stun_received = FALSE;
}
// google_xfer_send(js,session);
More information about the Commits
mailing list