Commit 89292b9f authored by Dafydd Harries's avatar Dafydd Harries

store the candidates in the components rather than in the agent

darcs-hash:20070217155355-c9803-ec94ff5a0483e801e8a708385bb5fad1c245b59b.gz
parent e3cac908
This diff is collapsed.
......@@ -52,8 +52,6 @@ struct _NiceAgent
guint next_stream_id;
NiceUDPSocketFactory *socket_factory;
GSList *local_addresses;
GSList *local_candidates;
GSList *remote_candidates;
GSList *streams;
gboolean main_context_set;
GMainContext *main_context;
......@@ -134,6 +132,12 @@ nice_agent_get_local_candidates (
guint stream_id,
guint component_id);
GSList *
nice_agent_get_remote_candidates (
NiceAgent *agent,
guint stream_id,
guint component_id);
gboolean
nice_agent_main_context_attach (
NiceAgent *agent,
......
......@@ -24,15 +24,12 @@ main (void)
g_assert (nice_agent_add_stream (agent, 1) == 3);
g_assert (NULL != agent->streams);
g_assert (NULL != agent->local_candidates);
nice_agent_remove_stream (agent, 1);
nice_agent_remove_stream (agent, 2);
nice_agent_remove_stream (agent, 3);
g_assert (NULL == agent->streams);
/* check no local candidates were left behind when streams were removed*/
g_assert (NULL == agent->local_candidates);
g_object_unref (agent);
nice_udp_socket_factory_close (&factory);
......
......@@ -43,9 +43,12 @@ main (void)
{
NiceUDPSocket *sock;
NiceCandidate *candidate;
GSList *candidates;
candidate = agent->local_candidates->data;
candidates = nice_agent_get_local_candidates (agent, 1, 1);
candidate = candidates->data;
sock = &candidate->sock;
g_slist_free (candidates);
nice_udp_fake_socket_push_recv (sock, &addr, 6, "\x80hello");
}
......
......@@ -32,7 +32,6 @@ main (void)
NiceAgent *agent;
NiceAddress addr = {0,};
NiceUDPSocketFactory factory;
NiceCandidate *candidate;
NiceUDPSocket *sock;
gint pipe_fds[2];
GSList *fds = NULL;
......@@ -50,8 +49,15 @@ main (void)
nice_agent_add_local_address (agent, &addr);
nice_agent_add_stream (agent, 1);
candidate = agent->local_candidates->data;
sock = &candidate->sock;
{
GSList *candidates;
NiceCandidate *candidate;
candidates = nice_agent_get_local_candidates (agent, 1, 1);
candidate = candidates->data;
sock = &candidate->sock;
g_slist_free (candidates);
}
/* set up pipe and fd list */
......
......@@ -20,7 +20,6 @@ main (void)
g_assert (nice_address_set_ipv4_from_string (&addr, "192.168.0.1"));
nice_agent_add_local_address (agent, &addr);
nice_agent_add_stream (agent, 1);
g_assert (agent->local_candidates != NULL);
/* recieve an RTP packet */
......@@ -29,8 +28,11 @@ main (void)
NiceUDPSocket *sock;
guint len;
gchar buf[1024];
GSList *candidates;
candidate = agent->local_candidates->data;
candidates = nice_agent_get_local_candidates (agent, 1, 1);
candidate = candidates->data;
g_slist_free (candidates);
sock = &(candidate->sock);
nice_udp_fake_socket_push_recv (sock, &addr, 7, "\x80lalala");
len = nice_agent_recv (agent, candidate->stream_id,
......
......@@ -59,14 +59,24 @@ send_connectivity_check (
NiceCandidate *remote;
gchar *username;
g_assert (agent->local_candidates);
g_assert (agent->local_candidates->data);
local = agent->local_candidates->data;
g_assert (local->id == 1);
{
GSList *candidates;
candidates = nice_agent_get_local_candidates (agent, 1, 1);
g_assert (g_slist_length (candidates) > 0);
local = candidates->data;
g_assert (local->id == 1);
g_slist_free (candidates);
}
g_assert (agent->remote_candidates);
g_assert (agent->remote_candidates->data);
remote = agent->remote_candidates->data;
{
GSList *candidates;
candidates = nice_agent_get_remote_candidates (agent, 1, 1);
g_assert (g_slist_length (candidates) > 0);
remote = candidates->data;
g_slist_free (candidates);
}
sock = &local->sock;
......@@ -165,13 +175,19 @@ main (void)
{
NiceUDPSocket *sock;
NiceCandidate *candidate;
NiceAddress addr;
gchar buf[1024];
guint len;
candidate = agent->local_candidates->data;
sock = &candidate->sock;
{
GSList *candidates;
NiceCandidate *candidate;
candidates = nice_agent_get_local_candidates (agent, 1, 1);
candidate = candidates->data;
sock = &candidate->sock;
g_slist_free (candidates);
}
/* If we send data before we've received a connectivity check, we won't
* have an affinity for any of the remote candidates, so the packet will
......
......@@ -8,10 +8,9 @@
static void
test_stun_no_password (
NiceAgent *agent,
NiceAddress from)
NiceAddress from,
NiceUDPSocket *sock)
{
NiceCandidate *candidate;
NiceUDPSocket *sock;
NiceAddress to = {0,};
guint len;
gchar buf[1024];
......@@ -20,9 +19,6 @@ test_stun_no_password (
memset (buf, '\0', 1024);
candidate = agent->local_candidates->data;
sock = &candidate->sock;
{
StunMessage *breq;
......@@ -62,10 +58,9 @@ test_stun_no_password (
static void
test_stun_invalid_password (
NiceAgent *agent,
NiceAddress from)
NiceAddress from,
NiceUDPSocket *sock)
{
NiceCandidate *candidate;
NiceUDPSocket *sock;
NiceAddress to = {0,};
guint len;
gchar buf[1024];
......@@ -74,9 +69,6 @@ test_stun_invalid_password (
memset (buf, '\0', 1024);
candidate = agent->local_candidates->data;
sock = &candidate->sock;
{
StunMessage *breq;
......@@ -117,10 +109,10 @@ test_stun_invalid_password (
static void
test_stun_valid_password (
NiceAgent *agent,
NiceAddress from)
NiceAddress from,
NiceCandidate *candidate,
NiceUDPSocket *sock)
{
NiceCandidate *candidate;
NiceUDPSocket *sock;
NiceAddress to = {0,};
guint len;
guint packed_len;
......@@ -130,13 +122,7 @@ test_stun_valid_password (
memset (buf, '\0', 1024);
candidate = agent->local_candidates->data;
sock = &candidate->sock;
username = g_strconcat (
((NiceCandidate *) agent->local_candidates->data)->username,
"username",
NULL);
username = g_strconcat (candidate->username, "username", NULL);
{
StunMessage *breq;
......@@ -190,6 +176,7 @@ main (void)
NiceCandidate *candidate;
NiceUDPSocketFactory factory;
NiceUDPSocket *sock;
GSList *candidates;
g_type_init ();
......@@ -205,14 +192,16 @@ main (void)
nice_agent_add_stream (agent, 1);
nice_agent_add_remote_candidate (agent, 1, 1, NICE_CANDIDATE_TYPE_HOST,
&remote_addr, "username", "password");
g_assert (agent->local_candidates != NULL);
candidate = agent->local_candidates->data;
candidates = nice_agent_get_local_candidates (agent, 1, 1);
candidate = candidates->data;
sock = &(candidate->sock);
g_slist_free (candidates);
/* run tests */
test_stun_no_password (agent, remote_addr);
test_stun_invalid_password (agent, remote_addr);
test_stun_valid_password (agent, remote_addr);
test_stun_no_password (agent, remote_addr, sock);
test_stun_invalid_password (agent, remote_addr, sock);
test_stun_valid_password (agent, remote_addr, candidate, sock);
/* clean up */
g_object_unref (agent);
......
......@@ -11,6 +11,7 @@ main (void)
NiceAddress addr_local = {0,}, addr_remote = {0,};
NiceCandidate *candidate;
NiceUDPSocketFactory factory;
GSList *candidates;
g_type_init ();
......@@ -23,7 +24,6 @@ main (void)
agent = nice_agent_new (&factory);
g_assert (agent->local_addresses == NULL);
g_assert (agent->local_candidates == NULL);
/* add one local address */
nice_agent_add_local_address (agent, &addr_local);
......@@ -32,33 +32,33 @@ main (void)
g_assert (g_slist_length (agent->local_addresses) == 1);
g_assert (nice_address_equal (agent->local_addresses->data, &addr_local));
/* no candidates should be generated until we have a stream */
g_assert (agent->local_candidates == NULL);
/* add a stream */
nice_agent_add_stream (agent, 1);
/* adding a stream should cause host candidates to be generated */
g_assert (agent->local_candidates != NULL);
g_assert (g_slist_length (agent->local_candidates) == 1);
candidate = agent->local_candidates->data;
candidates = nice_agent_get_local_candidates (agent, 1, 1);
g_assert (g_slist_length (candidates) == 1);
candidate = candidates->data;
/* fake socket manager uses incremental port numbers starting at 1 */
addr_local.port = 1;
g_assert (nice_address_equal (&(candidate->addr), &addr_local));
g_assert (candidate->id == 1);
g_slist_free (candidates);
/* add remote candidate */
nice_agent_add_remote_candidate (agent, 1, 1, NICE_CANDIDATE_TYPE_HOST,
&addr_remote, "username", "password");
g_assert (agent->remote_candidates != NULL);
g_assert (g_slist_length (agent->remote_candidates) == 1);
candidate = agent->remote_candidates->data;
candidates = nice_agent_get_remote_candidates (agent, 1, 1);
g_assert (candidates != NULL);
g_assert (g_slist_length (candidates) == 1);
candidate = candidates->data;
g_assert (nice_address_equal (&(candidate->addr), &addr_remote));
g_assert (candidate->stream_id == 1);
g_assert (candidate->component_id == 1);
g_assert (candidate->type == NICE_CANDIDATE_TYPE_HOST);
g_assert (0 == strcmp (candidate->username, "username"));
g_assert (0 == strcmp (candidate->password, "password"));
g_slist_free (candidates);
/* clean up */
g_object_unref (agent);
......
......@@ -118,11 +118,15 @@ main (gint argc, gchar *argv[])
{
NiceCandidate *candidate;
GSList *candidates;
candidate = agent->local_candidates->data;
candidates = nice_agent_get_local_candidates (agent, 1, 1);
g_assert (candidates);
candidate = candidates->data;
len = g_snprintf (buf, 1024, "0 0 X1 127.0.0.1 %d %s %s",
candidate->addr.port, candidate->username, candidate->password);
nice_udp_socket_send (&sock, &send_addr, len, buf);
g_slist_free (candidates);
}
// set up signalling callback
......
......@@ -22,14 +22,24 @@ send_connectivity_check (
NiceCandidate *remote;
gchar *username;
g_assert (agent->local_candidates);
g_assert (agent->local_candidates->data);
local = agent->local_candidates->data;
g_assert (local->id == 1);
{
GSList *candidates;
candidates = nice_agent_get_local_candidates (agent, 1, 1);
g_assert (candidates);
local = candidates->data;
g_assert (local->id == 1);
g_slist_free (candidates);
}
g_assert (agent->remote_candidates);
g_assert (agent->remote_candidates->data);
remote = agent->remote_candidates->data;
{
GSList *candidates;
candidates = nice_agent_get_remote_candidates (agent, 1, 1);
g_assert (candidates);
remote = candidates->data;
g_slist_free (candidates);
}
sock = &local->sock;
......@@ -99,12 +109,22 @@ recv_cb (
/* return value is whether to keep the source */
NiceAgent *agent = data;
NiceCandidate *candidate = agent->local_candidates->data;
NiceUDPSocket *sock = &candidate->sock;
NiceCandidate *candidate;
NiceUDPSocket *sock;
NiceAddress from;
guint len;
gchar buf[1024];
{
GSList *candidates;
candidates = nice_agent_get_local_candidates (agent, 1, 1);
g_assert (candidates);
candidate = candidates->data;
g_slist_free (candidates);
}
sock = &candidate->sock;
len = nice_udp_fake_socket_pop_send (
sock, &from, 1024, buf);
......@@ -137,9 +157,9 @@ main (gint argc, gchar *argv[])
nice_agent_add_local_address (agent, &addr);
nice_address_set_ipv4 (&addr, 0xc0a80002);
addr.port = 2345;
nice_agent_add_stream (agent, 1);
nice_agent_add_remote_candidate (agent, 1, 1, NICE_CANDIDATE_TYPE_HOST,
&addr, "username", "password");
nice_agent_add_stream (agent, 1);
// send connectivity check so that sending works
......@@ -150,9 +170,13 @@ main (gint argc, gchar *argv[])
GSource *source;
NiceCandidate *candidate;
NiceUDPSocket *sock;
GSList *candidates;
candidate = agent->local_candidates->data;
candidates = nice_agent_get_local_candidates (agent, 1, 1);
g_assert (candidates);
candidate = candidates->data;
sock = &candidate->sock;
g_slist_free (candidates);
// send test packet
......
......@@ -26,6 +26,7 @@ make_agent (
NiceAgent *agent;
NiceAddress addr_local;
NiceCandidate *candidate;
GSList *candidates;
agent = nice_agent_new (factory);
......@@ -35,10 +36,12 @@ make_agent (
nice_agent_add_local_address (agent, &addr_local);
nice_agent_add_stream (agent, 1);
g_assert (agent->local_candidates != NULL);
candidate = agent->local_candidates->data;
candidates = nice_agent_get_local_candidates (agent, 1, 1);
g_assert (candidates != NULL);
candidate = candidates->data;
g_debug ("allocated socket %d port %d for candidate %d",
candidate->sock.fileno, candidate->sock.addr.port, candidate->id);
g_slist_free (candidates);
*ret_agent = agent;
*ret_sock = &(candidate->sock);
......@@ -91,12 +94,17 @@ handle_connection (guint fileno, const struct sockaddr_in *sin, gpointer data)
if (!make_agent ((gchar *) data, &factory, &agent, &sock))
return;
/* send first local candidate to remote end */
candidate_str = nice_candidate_to_string (
agent->local_candidates->data);
send (fileno, candidate_str, strlen (candidate_str), 0);
send (fileno, "\n", 1, 0);
g_free (candidate_str);
{
GSList *candidates;
/* send first local candidate to remote end */
candidates = nice_agent_get_local_candidates (agent, 1, 1);
candidate_str = nice_candidate_to_string (candidates->data);
send (fileno, candidate_str, strlen (candidate_str), 0);
send (fileno, "\n", 1, 0);
g_free (candidate_str);
g_slist_free (candidates);
}
/* event loop */
......
......@@ -88,11 +88,14 @@ accept_connection (
{
NiceCandidate *candidate;
GSList *candidates;
candidate = agent->local_candidates->data;
candidates = nice_agent_get_local_candidates (agent, 1, 1);
candidate = candidates->data;
len = g_snprintf (buf, 1024, "0 0 X1 127.0.0.1 %d %s %s",
candidate->addr.port, candidate->username, candidate->password);
nice_udp_socket_send (sock, &send_addr, len, buf);
g_slist_free (candidates);
}
// IO loop
......
......@@ -12,6 +12,7 @@ T nice_agent_add_local_address
T nice_agent_add_remote_candidate
T nice_agent_add_stream
T nice_agent_get_local_candidates
T nice_agent_get_remote_candidates
T nice_agent_get_type
T nice_agent_main_context_attach
T nice_agent_new
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment