Skip to content

Instantly share code, notes, and snippets.

@shadeslayer
Created April 6, 2015 01:32
Show Gist options
  • Select an option

  • Save shadeslayer/c098d34a378d3d8c00bc to your computer and use it in GitHub Desktop.

Select an option

Save shadeslayer/c098d34a378d3d8c00bc to your computer and use it in GitHub Desktop.
> $ NICE_DEBUG=all G_MESSAGES_DEBUG=all ./tests/test-credentials [±set_local_creds ●●]
(process:7449): libnice-DEBUG: Created NiceStream (1 created, 0 destroyed)
(process:7449): libnice-DEBUG: Created NiceComponent (1 created, 0 destroyed)
(process:7449): libnice-DEBUG: Agent 0xda1060 : allocating stream id 1 (0xda3400)
(process:7449): libnice-DEBUG: Created NiceStream (2 created, 0 destroyed)
(process:7449): libnice-DEBUG: Created NiceComponent (2 created, 0 destroyed)
(process:7449): libnice-DEBUG: Agent 0xda1170 : allocating stream id 1 (0xda72a0)
(process:7449): libnice-DEBUG: Agent 0xda1060 : In ICE-FULL mode, starting candidate gathering.
(process:7449): libnice-DEBUG: Agent 0xda1060 : libnice compiled without UPnP support
(process:7449): libnice-DEBUG: Agent 0xda1060: Trying to create host candidate on port 0
(process:7449): libnice-DEBUG: Agent 0xda1060: Could not set IPV6 socket ToS: Protocol not available
(process:7449): libnice-DEBUG: Component 0xda3840 (agent 0xda1060): Attach source (stream 1).
(process:7449): libnice-DEBUG: Attaching source 0xdae8b0 (socket 0xd9c8a0, FD 6) to context 0xdab360
(process:7449): libnice-DEBUG: Agent 0xda1060: Candidate gathering FINISHED, no scheduled items.
(process:7449): libnice-DEBUG: Agent 0xda1060: gathered UDP local candidate : [127.0.0.1]:42387 for s1/c1. U/P '(null)'/'(null)'
(process:7449): libnice-tests-DEBUG: test-credentials:cb_candidate_gathering_done: 0x1
(process:7449): libnice-tests-DEBUG: lagent finished gathering candidates
(process:7449): libnice-DEBUG: Agent 0xda1170 : In ICE-FULL mode, starting candidate gathering.
(process:7449): libnice-DEBUG: Agent 0xda1170 : libnice compiled without UPnP support
(process:7449): libnice-DEBUG: Agent 0xda1170: Trying to create host candidate on port 0
(process:7449): libnice-DEBUG: Agent 0xda1170: Could not set IPV6 socket ToS: Protocol not available
(process:7449): libnice-DEBUG: Component 0xda76e0 (agent 0xda1170): Attach source (stream 1).
(process:7449): libnice-DEBUG: Attaching source 0xdae960 (socket 0xdae5e0, FD 7) to context 0xdab360
(process:7449): libnice-DEBUG: Agent 0xda1170: Candidate gathering FINISHED, no scheduled items.
(process:7449): libnice-DEBUG: Agent 0xda1170: gathered UDP local candidate : [127.0.0.1]:36871 for s1/c1. U/P '(null)'/'(null)'
(process:7449): libnice-tests-DEBUG: test-credentials:cb_candidate_gathering_done: 0x2
(process:7449): libnice-tests-DEBUG: ragent finished gathering candidates
(process:7449): libnice-tests-DEBUG: test-credentials:swap_candidates
(process:7449): libnice-DEBUG: Agent 0xda1170: set_remote_candidates 1 1
(process:7449): libnice-DEBUG: Agent 0xda1170 : Adding UDP remote candidate with addr [127.0.0.1]:42387 for s1/c1. U/P '(null)'/'(null)' prio: 2013266431
(process:7449): libnice-DEBUG: Agent 0xda1170, Adding check pair between 1 and 1
(process:7449): libnice-DEBUG: Agent 0xda1170 : creating new pair 0xd9f000 state 5
(process:7449): libnice-DEBUG: Agent 0xda1170 : added a new conncheck 0xd9f000 with foundation of '1:1' to list 1.
(process:7449): libnice-DEBUG: Agent 0xda1170 : stream 1 component 1 STATE-CHANGE disconnected -> connecting.
(process:7449): libnice-DEBUG: Agent 0xda1170 : Pair 0xd9f000 with s/c-id 1/1 (1:1) unfrozen.
(process:7449): libnice-DEBUG: Agent 0xda1170 : pair 0xd9f000 state WAITING
(process:7449): libnice-DEBUG: Agent 0xda1170 : priv_conn_check_unfreeze_next returned 1
(process:7449): libnice-DEBUG: Agent 0xda1170 : pair 0xd9f000 state IN_PROGRESS
(process:7449): libnice-DEBUG: Agent 0xda1170 : STUN-CC REQ to '127.0.0.1:42387', socket=7, pair=1:1 (c-id:1), tie=12195390406545576023, username='' (0), password='' (0), priority=1845494271.
(process:7449): libnice-DEBUG: Agent 0xda1170: no credentials found, cancelling conncheck
(process:7449): libnice-DEBUG: Agent 0xda1170 : STUN connectivity check was cancelled, marking as done.
(process:7449): libnice-DEBUG: Agent 0xda1170 : pair 0xd9f000 state FAILED
(process:7449): libnice-DEBUG: Agent 0xda1170 : timer tick #1: 0 frozen, 0 in-progress, 0 waiting, 0 succeeded, 0 discovered, 0 nominated, 0 waiting-for-nom.
(process:7449): libnice-DEBUG: Agent 0xda1170 : priv_conn_check_tick_unlocked returned 1
(process:7449): libnice-DEBUG: Agent 0xda1170 : conn_check_schedule_next returning 1
(process:7449): libnice-tests-DEBUG: test-credentials:swap_candidates
(process:7449): libnice-DEBUG: Agent 0xda1060: set_remote_candidates 1 1
(process:7449): libnice-DEBUG: Agent 0xda1060 : Adding UDP remote candidate with addr [127.0.0.1]:36871 for s1/c1. U/P '(null)'/'(null)' prio: 2013266431
(process:7449): libnice-DEBUG: Agent 0xda1060, Adding check pair between 1 and 1
(process:7449): libnice-DEBUG: Agent 0xda1060 : creating new pair 0xdb1800 state 5
(process:7449): libnice-DEBUG: Agent 0xda1060 : added a new conncheck 0xdb1800 with foundation of '1:1' to list 1.
(process:7449): libnice-DEBUG: Agent 0xda1060 : stream 1 component 1 STATE-CHANGE disconnected -> connecting.
(process:7449): libnice-DEBUG: Agent 0xda1060 : Pair 0xdb1800 with s/c-id 1/1 (1:1) unfrozen.
(process:7449): libnice-DEBUG: Agent 0xda1060 : pair 0xdb1800 state WAITING
(process:7449): libnice-DEBUG: Agent 0xda1060 : priv_conn_check_unfreeze_next returned 1
(process:7449): libnice-DEBUG: Agent 0xda1060 : pair 0xdb1800 state IN_PROGRESS
(process:7449): libnice-DEBUG: Agent 0xda1060 : STUN-CC REQ to '127.0.0.1:36871', socket=6, pair=1:1 (c-id:1), tie=16540578358656053489, username='' (0), password='' (0), priority=1845494271.
(process:7449): libnice-DEBUG: Agent 0xda1060: no credentials found, cancelling conncheck
(process:7449): libnice-DEBUG: Agent 0xda1060 : STUN connectivity check was cancelled, marking as done.
(process:7449): libnice-DEBUG: Agent 0xda1060 : pair 0xdb1800 state FAILED
(process:7449): libnice-DEBUG: Agent 0xda1060 : timer tick #2: 0 frozen, 0 in-progress, 0 waiting, 0 succeeded, 0 discovered, 0 nominated, 0 waiting-for-nom.
(process:7449): libnice-DEBUG: Agent 0xda1060 : priv_conn_check_tick_unlocked returned 1
(process:7449): libnice-DEBUG: Agent 0xda1060 : conn_check_schedule_next returning 1
(process:7449): libnice-DEBUG: Agent 0xda1060, freeing conncheck_list of stream 0xda3400
(process:7449): libnice-DEBUG: Free socket sources for component 0xda3840.
(process:7449): libnice-DEBUG: Detaching source 0xdae8b0 (socket 0xd9c8a0, FD 6) from context 0xdab360
(process:7449): libnice-DEBUG: Destroyed NiceComponent (2 created, 1 destroyed)
(process:7449): libnice-DEBUG: Destroyed NiceStream (2 created, 1 destroyed)
(process:7449): libnice-DEBUG: Agent 0xda1170, freeing conncheck_list of stream 0xda72a0
(process:7449): libnice-DEBUG: Free socket sources for component 0xda76e0.
(process:7449): libnice-DEBUG: Detaching source 0xdae960 (socket 0xdae5e0, FD 7) from context 0xdab360
(process:7449): libnice-DEBUG: Destroyed NiceComponent (2 created, 2 destroyed)
(process:7449): libnice-DEBUG: Destroyed NiceStream (2 created, 2 destroyed)
/*
* This file is part of the Nice GLib ICE library.
*
* (C) 2015 Rohan Garg <[email protected]>
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Nice GLib ICE library.
*
* The Initial Developers of the Original Code are Collabora Ltd and Nokia
* Corporation. All Rights Reserved.
*
* Contributors:
* Dafydd Harries, Collabora Ltd.
* Kai Vehmanen, Nokia
*
* Alternatively, the contents of this file may be used under the terms of the
* the GNU Lesser General Public License Version 2.1 (the "LGPL"), in which
* case the provisions of LGPL are applicable instead of those above. If you
* wish to allow use of your version of this file only under the terms of the
* LGPL and not to allow others to use your version of this file under the
* MPL, indicate your decision by deleting the provisions above and replace
* them with the notice and other provisions required by the LGPL. If you do
* not delete the provisions above, a recipient may use your version of this
* file under either the MPL or the LGPL.
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "agent.h"
#include "agent-priv.h"
#include <string.h>
#include <stdio.h>
#define LEFT_AGENT GINT_TO_POINTER(1)
#define RIGHT_AGENT GINT_TO_POINTER(2)
#define USE_UPNP 0
static void cb_nice_recv (NiceAgent *agent, guint stream_id, guint component_id, guint len, gchar *buf, gpointer user_data)
{
g_debug ("test-credentials:%s: %p", G_STRFUNC, user_data);
}
static void swap_candidates(NiceAgent *local, guint local_id, NiceAgent *remote, guint remote_id)
{
GSList *cands = NULL;
g_debug ("test-credentials:%s", G_STRFUNC);
cands = nice_agent_get_local_candidates(local, local_id,
NICE_COMPONENT_TYPE_RTP);
g_assert(nice_agent_set_remote_candidates(remote, remote_id,
NICE_COMPONENT_TYPE_RTP, cands));
g_slist_free_full (cands, (GDestroyNotify) nice_candidate_free);
}
static void cb_candidate_gathering_done(NiceAgent *agent, guint stream_id, gpointer data)
{
static gboolean L_CAND_DONE = false, R_CAND_DONE = false;
static NiceAgent *lagent = NULL, *ragent = NULL;
g_debug ("test-credentials:%s: %p", G_STRFUNC, data);
if (GPOINTER_TO_UINT(data) == 1) {
g_debug ("lagent finished gathering candidates");
L_CAND_DONE = true;
lagent = agent;
} else if (GPOINTER_TO_UINT(data) == 2) {
g_debug ("ragent finished gathering candidates");
R_CAND_DONE = true;
ragent = agent;
}
if (L_CAND_DONE && R_CAND_DONE) {
swap_candidates (lagent, 1, ragent, 1);
swap_candidates (ragent, 1, lagent, 1);
}
}
static void setup(NiceAgent *lagent, NiceAgent *ragent)
{
NiceAddress addr;
g_assert (nice_agent_add_stream (lagent, 1) == 1);
g_assert (nice_agent_add_stream (ragent, 1) == 1);
g_assert (NULL != lagent->streams);
g_assert (NULL != ragent->streams);
nice_address_init (&addr);
g_assert (nice_address_set_from_string (&addr, "127.0.0.1"));
nice_agent_add_local_address (lagent, &addr);
nice_agent_add_local_address (ragent, &addr);
nice_agent_attach_recv (lagent, 1, NICE_COMPONENT_TYPE_RTP,
g_main_context_default (),
cb_nice_recv, LEFT_AGENT);
nice_agent_attach_recv (ragent, 1, NICE_COMPONENT_TYPE_RTP,
g_main_context_default (),
cb_nice_recv, RIGHT_AGENT);
g_signal_connect(G_OBJECT(lagent), "candidate-gathering-done",
G_CALLBACK(cb_candidate_gathering_done), LEFT_AGENT);
g_signal_connect(G_OBJECT(ragent), "candidate-gathering-done",
G_CALLBACK(cb_candidate_gathering_done), RIGHT_AGENT);
g_object_set (G_OBJECT (lagent), "ice-tcp", FALSE, NULL);
g_object_set (G_OBJECT (ragent), "ice-tcp", FALSE, NULL);
g_object_set (G_OBJECT (lagent), "controlling-mode", TRUE, NULL);
g_object_set (G_OBJECT (ragent), "controlling-mode", FALSE, NULL);
g_object_set (G_OBJECT (lagent), "upnp", USE_UPNP, NULL);
g_object_set (G_OBJECT (ragent), "upnp", USE_UPNP, NULL);
g_object_set_data (G_OBJECT (lagent), "other-agent", ragent);
g_object_set_data (G_OBJECT (ragent), "other-agent", lagent);
}
static void teardown(NiceAgent *lagent, NiceAgent *ragent)
{
nice_agent_remove_stream (lagent, 1);
nice_agent_remove_stream (ragent, 1);
}
static void set_credentials(NiceAgent *lagent, NiceAgent *ragent)
{
gchar *ufrag = NULL, *password = NULL;
nice_agent_get_local_credentials (lagent, 1, &ufrag, &password);
nice_agent_set_remote_credentials (ragent, 1, ufrag, password);
g_free (ufrag);
g_free (password);
nice_agent_get_local_credentials (ragent, 1, &ufrag, &password);
nice_agent_set_remote_credentials (lagent, 1, ufrag, password);
g_free (ufrag);
g_free (password);
}
int main (void)
{
NiceAgent *lagent = NULL, *ragent = NULL;
gchar *ufrag = NULL, *password = NULL;
#ifdef G_OS_WIN32
WSADATA w;
WSAStartup(0x0202, &w);
#endif
g_type_init ();
g_thread_init (NULL);
lagent = nice_agent_new (NULL, NICE_COMPATIBILITY_RFC5245);
ragent = nice_agent_new (NULL, NICE_COMPATIBILITY_RFC5245);
setup (lagent, ragent);
nice_agent_set_local_credentials (lagent, 1, "unicorns", "awesome");
nice_agent_get_local_credentials (lagent, 1, &ufrag, &password);
g_assert (g_strcmp0("unicorns", ufrag) == 0);
g_assert (g_strcmp0("awesome", password) == 0);
nice_agent_gather_candidates (lagent, 1);
nice_agent_gather_candidates (ragent, 1);
set_credentials (lagent, ragent);
teardown (lagent, ragent);
g_object_unref (lagent);
g_object_unref (ragent);
#ifdef G_OS_WIN32
WSACleanup();
#endif
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment