Commit a54f4aac authored by Dafydd Harries's avatar Dafydd Harries

add "nice" prefix to agent, candidate, address

darcs-hash:20070129161236-c9803-bec5e2eb1477d5e12ae0dd3da3794fb73d180294.gz
parent 36fed842
...@@ -6,17 +6,17 @@ ...@@ -6,17 +6,17 @@
#include "address.h" #include "address.h"
Address * NiceAddress *
address_new (void) nice_address_new (void)
{ {
return g_slice_new0 (Address); return g_slice_new0 (NiceAddress);
} }
void void
address_set_ipv4 (Address *addr, guint32 addr_ipv4) nice_address_set_ipv4 (NiceAddress *addr, guint32 addr_ipv4)
{ {
addr->type = ADDRESS_TYPE_IPV4; addr->type = NICE_ADDRESS_TYPE_IPV4;
addr->addr_ipv4 = addr_ipv4; addr->addr_ipv4 = addr_ipv4;
} }
...@@ -27,13 +27,13 @@ address_set_ipv4 (Address *addr, guint32 addr_ipv4) ...@@ -27,13 +27,13 @@ address_set_ipv4 (Address *addr, guint32 addr_ipv4)
* Returns FALSE on error. * Returns FALSE on error.
*/ */
gboolean gboolean
address_set_ipv4_from_string (Address *addr, gchar *str) nice_address_set_ipv4_from_string (NiceAddress *addr, gchar *str)
{ {
struct in_addr iaddr; struct in_addr iaddr;
if (inet_aton (str, &iaddr) != 0) if (inet_aton (str, &iaddr) != 0)
{ {
address_set_ipv4 (addr, ntohl (iaddr.s_addr)); nice_address_set_ipv4 (addr, ntohl (iaddr.s_addr));
return TRUE; return TRUE;
} }
else else
...@@ -45,13 +45,13 @@ address_set_ipv4_from_string (Address *addr, gchar *str) ...@@ -45,13 +45,13 @@ address_set_ipv4_from_string (Address *addr, gchar *str)
gchar * gchar *
address_to_string (Address *addr) nice_address_to_string (NiceAddress *addr)
{ {
struct in_addr iaddr; struct in_addr iaddr;
gchar ip_str[INET_ADDRSTRLEN]; gchar ip_str[INET_ADDRSTRLEN];
const gchar *ret; const gchar *ret;
g_assert (addr->type == ADDRESS_TYPE_IPV4); g_assert (addr->type == NICE_ADDRESS_TYPE_IPV4);
iaddr.s_addr = htonl (addr->addr_ipv4); iaddr.s_addr = htonl (addr->addr_ipv4);
ret = inet_ntop (AF_INET, &iaddr, ip_str, INET_ADDRSTRLEN); ret = inet_ntop (AF_INET, &iaddr, ip_str, INET_ADDRSTRLEN);
g_assert (ret); g_assert (ret);
...@@ -60,22 +60,22 @@ address_to_string (Address *addr) ...@@ -60,22 +60,22 @@ address_to_string (Address *addr)
gboolean gboolean
address_equal (Address *a, Address *b) nice_address_equal (NiceAddress *a, NiceAddress *b)
{ {
if (a->type != b->type) if (a->type != b->type)
return FALSE; return FALSE;
if (a->type == ADDRESS_TYPE_IPV4) if (a->type == NICE_ADDRESS_TYPE_IPV4)
return a->addr_ipv4 == b->addr_ipv4; return a->addr_ipv4 == b->addr_ipv4;
g_assert_not_reached (); g_assert_not_reached ();
} }
Address * NiceAddress *
address_dup (Address *a) nice_address_dup (NiceAddress *a)
{ {
Address *dup = g_slice_new0 (Address); NiceAddress *dup = g_slice_new0 (NiceAddress);
*dup = *a; *dup = *a;
return dup; return dup;
...@@ -83,9 +83,9 @@ address_dup (Address *a) ...@@ -83,9 +83,9 @@ address_dup (Address *a)
void void
address_free (Address *addr) nice_address_free (NiceAddress *addr)
{ {
g_slice_free (Address, addr); g_slice_free (NiceAddress, addr);
} }
...@@ -107,9 +107,9 @@ ipv4_address_is_private (guint32 addr) ...@@ -107,9 +107,9 @@ ipv4_address_is_private (guint32 addr)
gboolean gboolean
address_is_private (Address *a) nice_address_is_private (NiceAddress *a)
{ {
if (a->type == ADDRESS_TYPE_IPV4) if (a->type == NICE_ADDRESS_TYPE_IPV4)
return ipv4_address_is_private (a->addr_ipv4); return ipv4_address_is_private (a->addr_ipv4);
g_assert_not_reached (); g_assert_not_reached ();
......
...@@ -2,20 +2,20 @@ ...@@ -2,20 +2,20 @@
#ifndef _ADDRESS_H #ifndef _ADDRESS_H
#define _ADDRESS_H #define _ADDRESS_H
typedef enum address_type AddressType; typedef enum address_type NiceAddressType;
enum address_type enum address_type
{ {
ADDRESS_TYPE_IPV4, NICE_ADDRESS_TYPE_IPV4,
ADDRESS_TYPE_IPV6, NICE_ADDRESS_TYPE_IPV6,
}; };
typedef struct _address Address; typedef struct _address NiceAddress;
/* XXX: need access to fields to convert to sockaddr_in */ /* XXX: need access to fields to convert to sockaddr_in */
struct _address struct _address
{ {
AddressType type; NiceAddressType type;
union union
{ {
guint32 addr_ipv4; guint32 addr_ipv4;
...@@ -23,20 +23,20 @@ struct _address ...@@ -23,20 +23,20 @@ struct _address
}; };
}; };
Address * NiceAddress *
address_new (void); nice_address_new (void);
void void
address_free (Address *addr); nice_address_free (NiceAddress *addr);
Address * NiceAddress *
address_dup (Address *a); nice_address_dup (NiceAddress *a);
void void
address_set_ipv4 (Address *addr, guint32 addr_ipv4); nice_address_set_ipv4 (NiceAddress *addr, guint32 addr_ipv4);
gboolean gboolean
address_set_ipv4_from_string (Address *addr, gchar *str); nice_address_set_ipv4_from_string (NiceAddress *addr, gchar *str);
gboolean gboolean
address_equal (Address *a, Address *b); nice_address_equal (NiceAddress *a, NiceAddress *b);
gchar * gchar *
address_to_string (Address *addr); nice_address_to_string (NiceAddress *addr);
#endif /* _ADDRESS_H */ #endif /* _ADDRESS_H */
...@@ -67,7 +67,7 @@ struct _stream ...@@ -67,7 +67,7 @@ struct _stream
guint id; guint id;
/* XXX: streams can have multiple components */ /* XXX: streams can have multiple components */
Component *component; Component *component;
AgentRecvHandler handle_recv; NiceAgentRecvHandler handle_recv;
}; };
...@@ -97,8 +97,8 @@ typedef struct _candidate_pair CandidatePair; ...@@ -97,8 +97,8 @@ typedef struct _candidate_pair CandidatePair;
struct _candidate_pair struct _candidate_pair
{ {
Candidate local; NiceCandidate local;
Candidate remote; NiceCandidate remote;
}; };
...@@ -142,7 +142,7 @@ candidate_pair_priority ( ...@@ -142,7 +142,7 @@ candidate_pair_priority (
#if 0 #if 0
static Event * static Event *
event_new (EventType type) nice_event_new (EventType type)
{ {
Event *ev; Event *ev;
...@@ -154,7 +154,7 @@ event_new (EventType type) ...@@ -154,7 +154,7 @@ event_new (EventType type)
void void
event_free (Event *ev) nice_event_free (Event *ev)
{ {
switch (ev->type) switch (ev->type)
{ {
...@@ -169,12 +169,12 @@ event_free (Event *ev) ...@@ -169,12 +169,12 @@ event_free (Event *ev)
/*** agent ***/ /*** agent ***/
Agent * NiceAgent *
ice_agent_new (UDPSocketManager *mgr) nice_agent_new (UDPSocketManager *mgr)
{ {
Agent *agent; NiceAgent *agent;
agent = g_slice_new0 (Agent); agent = g_slice_new0 (NiceAgent);
agent->sockmgr = mgr; agent->sockmgr = mgr;
agent->next_candidate_id = 1; agent->next_candidate_id = 1;
agent->next_stream_id = 1; agent->next_stream_id = 1;
...@@ -183,7 +183,7 @@ ice_agent_new (UDPSocketManager *mgr) ...@@ -183,7 +183,7 @@ ice_agent_new (UDPSocketManager *mgr)
Event * Event *
ice_agent_pop_event (Agent *agent) nice_agent_pop_event (NiceAgent *agent)
{ {
Event *event; Event *event;
GSList *head; GSList *head;
...@@ -200,23 +200,23 @@ ice_agent_pop_event (Agent *agent) ...@@ -200,23 +200,23 @@ ice_agent_pop_event (Agent *agent)
void void
ice_agent_push_event (Agent *agent, Event *ev) nice_agent_push_event (NiceAgent *agent, Event *ev)
{ {
agent->events = g_slist_append (agent->events, ev); agent->events = g_slist_append (agent->events, ev);
} }
static void static void
ice_agent_add_local_host_candidate ( nice_agent_add_local_host_candidate (
Agent *agent, NiceAgent *agent,
guint stream_id, guint stream_id,
guint component_id, guint component_id,
Address *address) NiceAddress *address)
{ {
Candidate *candidate; NiceCandidate *candidate;
struct sockaddr_in sin; struct sockaddr_in sin;
candidate = candidate_new (CANDIDATE_TYPE_HOST); candidate = nice_candidate_new (NICE_CANDIDATE_TYPE_HOST);
candidate->id = agent->next_candidate_id++; candidate->id = agent->next_candidate_id++;
candidate->stream_id = stream_id; candidate->stream_id = stream_id;
candidate->component_id = component_id; candidate->component_id = component_id;
...@@ -235,9 +235,9 @@ ice_agent_add_local_host_candidate ( ...@@ -235,9 +235,9 @@ ice_agent_add_local_host_candidate (
guint guint
ice_agent_add_stream ( nice_agent_add_stream (
Agent *agent, NiceAgent *agent,
AgentRecvHandler handle_recv) NiceAgentRecvHandler handle_recv)
{ {
Stream *stream; Stream *stream;
GSList *i; GSList *i;
...@@ -251,9 +251,9 @@ ice_agent_add_stream ( ...@@ -251,9 +251,9 @@ ice_agent_add_stream (
for (i = agent->local_addresses; i; i = i->next) for (i = agent->local_addresses; i; i = i->next)
{ {
Address *addr = (Address *) i->data; NiceAddress *addr = (NiceAddress *) i->data;
ice_agent_add_local_host_candidate (agent, stream->id, nice_agent_add_local_host_candidate (agent, stream->id,
stream->component->id, addr); stream->component->id, addr);
/* XXX: need to check for redundant candidates? */ /* XXX: need to check for redundant candidates? */
...@@ -265,10 +265,10 @@ ice_agent_add_stream ( ...@@ -265,10 +265,10 @@ ice_agent_add_stream (
void void
ice_agent_add_local_address (Agent *agent, Address *addr) nice_agent_add_local_address (NiceAgent *agent, NiceAddress *addr)
{ {
agent->local_addresses = g_slist_append (agent->local_addresses, agent->local_addresses = g_slist_append (agent->local_addresses,
address_dup (addr)); nice_address_dup (addr));
/* XXX: Should we generate local candidates for existing streams at this /* XXX: Should we generate local candidates for existing streams at this
* point, or require that local addresses are set before media streams are * point, or require that local addresses are set before media streams are
...@@ -278,17 +278,17 @@ ice_agent_add_local_address (Agent *agent, Address *addr) ...@@ -278,17 +278,17 @@ ice_agent_add_local_address (Agent *agent, Address *addr)
void void
ice_agent_add_remote_candidate ( nice_agent_add_remote_candidate (
Agent *agent, NiceAgent *agent,
CandidateType type, NiceCandidateType type,
Address *addr, NiceAddress *addr,
guint port) guint port)
{ {
/* append to agent->remote_candidates */ /* append to agent->remote_candidates */
Candidate *candidate; NiceCandidate *candidate;
candidate = candidate_new (type); candidate = nice_candidate_new (type);
/* do remote candidates need IDs? */ /* do remote candidates need IDs? */
candidate->id = 0; candidate->id = 0;
candidate->addr = *addr; candidate->addr = *addr;
...@@ -301,14 +301,14 @@ ice_agent_add_remote_candidate ( ...@@ -301,14 +301,14 @@ ice_agent_add_remote_candidate (
} }
static Candidate * static NiceCandidate *
_local_candidate_lookup (Agent *agent, guint candidate_id) _local_candidate_lookup (NiceAgent *agent, guint candidate_id)
{ {
GSList *i; GSList *i;
for (i = agent->local_candidates; i; i = i->next) for (i = agent->local_candidates; i; i = i->next)
{ {
Candidate *c = (Candidate *) i->data; NiceCandidate *c = (NiceCandidate *) i->data;
if (c->id == candidate_id) if (c->id == candidate_id)
return c; return c;
...@@ -319,7 +319,7 @@ _local_candidate_lookup (Agent *agent, guint candidate_id) ...@@ -319,7 +319,7 @@ _local_candidate_lookup (Agent *agent, guint candidate_id)
static Stream * static Stream *
_stream_lookup (Agent *agent, guint stream_id) _stream_lookup (NiceAgent *agent, guint stream_id)
{ {
GSList *i; GSList *i;
...@@ -343,11 +343,11 @@ _stream_lookup (Agent *agent, guint stream_id) ...@@ -343,11 +343,11 @@ _stream_lookup (Agent *agent, guint stream_id)
* block if the socket is blocking. * block if the socket is blocking.
*/ */
void void
ice_agent_recv ( nice_agent_recv (
Agent *agent, NiceAgent *agent,
guint candidate_id) guint candidate_id)
{ {
Candidate *candidate; NiceCandidate *candidate;
guint len; guint len;
gchar buf[1024]; gchar buf[1024];
struct sockaddr_in from; struct sockaddr_in from;
...@@ -451,28 +451,28 @@ ice_agent_recv ( ...@@ -451,28 +451,28 @@ ice_agent_recv (
*/ */
/* /*
void void
ice_agent_set_stun_server (Address *addr, guint16 port) nice_agent_set_stun_server (NiceAddress *addr, guint16 port)
{ {
} }
*/ */
const GSList * const GSList *
ice_agent_get_local_candidates ( nice_agent_get_local_candidates (
Agent *agent) NiceAgent *agent)
{ {
return agent->local_candidates; return agent->local_candidates;
} }
void void
ice_agent_free (Agent *agent) nice_agent_free (NiceAgent *agent)
{ {
GSList *i; GSList *i;
for (i = agent->local_addresses; i; i = i->next) for (i = agent->local_addresses; i; i = i->next)
{ {
Address *a = (Address *) i->data; NiceAddress *a = (NiceAddress *) i->data;
address_free (a); nice_address_free (a);
} }
g_slist_free (agent->local_addresses); g_slist_free (agent->local_addresses);
...@@ -480,9 +480,9 @@ ice_agent_free (Agent *agent) ...@@ -480,9 +480,9 @@ ice_agent_free (Agent *agent)
for (i = agent->local_candidates; i; i = i->next) for (i = agent->local_candidates; i; i = i->next)
{ {
Candidate *c = (Candidate *) i->data; NiceCandidate *c = (NiceCandidate *) i->data;
candidate_free (c); nice_candidate_free (c);
} }
g_slist_free (agent->local_candidates); g_slist_free (agent->local_candidates);
...@@ -490,9 +490,9 @@ ice_agent_free (Agent *agent) ...@@ -490,9 +490,9 @@ ice_agent_free (Agent *agent)
for (i = agent->remote_candidates; i; i = i->next) for (i = agent->remote_candidates; i; i = i->next)
{ {
Candidate *c = (Candidate *) i->data; NiceCandidate *c = (NiceCandidate *) i->data;
candidate_free (c); nice_candidate_free (c);
} }
g_slist_free (agent->remote_candidates); g_slist_free (agent->remote_candidates);
...@@ -508,6 +508,6 @@ ice_agent_free (Agent *agent) ...@@ -508,6 +508,6 @@ ice_agent_free (Agent *agent)
g_slist_free (agent->streams); g_slist_free (agent->streams);
agent->streams = NULL; agent->streams = NULL;
g_slice_free (Agent, agent); g_slice_free (NiceAgent, agent);
} }
...@@ -30,13 +30,13 @@ struct _event ...@@ -30,13 +30,13 @@ struct _event
union { union {
struct { struct {
Address *addr; NiceAddress *addr;
guint candidate_id; guint candidate_id;
} request_port; } request_port;
struct { struct {
Address *from; NiceAddress *from;
guint from_port; guint from_port;
Address *to; NiceAddress *to;
guint to_port; guint to_port;
} request_stun_query; } request_stun_query;
}; };
...@@ -50,7 +50,7 @@ event_free (Event *ev); ...@@ -50,7 +50,7 @@ event_free (Event *ev);
/*** agent ***/ /*** agent ***/
typedef struct _agent Agent; typedef struct _agent NiceAgent;
struct _agent struct _agent
{ {
...@@ -65,35 +65,36 @@ struct _agent ...@@ -65,35 +65,36 @@ struct _agent
}; };
typedef void (*AgentRecvHandler) ( typedef void (*NiceAgentRecvHandler) (
Agent *agent, guint stream_id, guint component_id, guint len, gchar *buf); NiceAgent *agent, guint stream_id, guint component_id, guint len,
gchar *buf);
Agent * NiceAgent *
ice_agent_new (UDPSocketManager *mgr); nice_agent_new (UDPSocketManager *mgr);
Event * Event *
ice_agent_pop_event (Agent *agent); nice_agent_pop_event (NiceAgent *agent);
void void
ice_agent_add_local_address (Agent *agent, Address *addr); nice_agent_add_local_address (NiceAgent *agent, NiceAddress *addr);
guint guint
ice_agent_add_stream ( nice_agent_add_stream (
Agent *agent, NiceAgent *agent,
AgentRecvHandler handle_recv); NiceAgentRecvHandler handle_recv);
void void
ice_agent_free (Agent *agent); nice_agent_free (NiceAgent *agent);
void void
ice_agent_add_remote_candidate ( nice_agent_add_remote_candidate (
Agent *agent, NiceAgent *agent,
CandidateType type, NiceCandidateType type,
Address *addr, NiceAddress *addr,
guint port); guint port);
void void
ice_agent_recv ( nice_agent_recv (
Agent *agent, NiceAgent *agent,
guint candidate_id); guint candidate_id);
const GSList * const GSList *
ice_agent_get_local_candidates ( nice_agent_get_local_candidates (
Agent *agent); NiceAgent *agent);
#endif /* _AGENT_H */ #endif /* _AGENT_H */
...@@ -7,33 +7,33 @@ ...@@ -7,33 +7,33 @@
* candidates, server reflexive candidates, and relayed candidates. */ * candidates, server reflexive candidates, and relayed candidates. */
Candidate * NiceCandidate *
candidate_new (CandidateType type) nice_candidate_new (NiceCandidateType type)
{ {
Candidate *candidate; NiceCandidate *candidate;
candidate = g_slice_new0 (Candidate); candidate = g_slice_new0 (NiceCandidate);
candidate->type = type; candidate->type = type;
return candidate; return candidate;
} }
void void
candidate_free (Candidate *candidate) nice_candidate_free (NiceCandidate *candidate)
{ {
g_slice_free (Candidate, candidate); g_slice_free (NiceCandidate, candidate);
} }
gfloat gfloat
candidate_jingle_priority (Candidate *candidate) nice_candidate_jingle_priority (NiceCandidate *candidate)
{ {
switch (candidate->type) switch (candidate->type)
{ {
case CANDIDATE_TYPE_HOST: return 1.0; case NICE_CANDIDATE_TYPE_HOST: return 1.0;
case CANDIDATE_TYPE_SERVER_REFLEXIVE: return 0.9; case NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE: return 0.9;
case CANDIDATE_TYPE_PEER_REFLEXIVE: return 0.9; case NICE_CANDIDATE_TYPE_PEER_REFLEXIVE: return 0.9;
case CANDIDATE_TYPE_RELAYED: return 0.5; case NICE_CANDIDATE_TYPE_RELAYED: return 0.5;
} }
/* appease GCC */ /* appease GCC */
...@@ -60,16 +60,16 @@ _candidate_ice_priority ( ...@@ -60,16 +60,16 @@ _candidate_ice_priority (
guint32 guint32
candidate_ice_priority (Candidate *candidate) nice_candidate_ice_priority (NiceCandidate *candidate)
{ {
guint8 type_preference = 0; guint8 type_preference = 0;
switch (candidate->type) switch (candidate->type)
{ {
case CANDIDATE_TYPE_HOST: type_preference = 120; break; case NICE_CANDIDATE_TYPE_HOST: type_preference = 120; break;
case CANDIDATE_TYPE_PEER_REFLEXIVE: type_preference = 110; break; case NICE_CANDIDATE_TYPE_PEER_REFLEXIVE: type_preference = 110; break;
case CANDIDATE_TYPE_SERVER_REFLEXIVE: type_preference = 100; break; case NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE: type_preference = 100; break;
case CANDIDATE_TYPE_RELAYED: type_preference = 60; break; case NICE_CANDIDATE_TYPE_RELAYED: type_preference = 60; break;
} }
return _candidate_ice_priority (type_preference, 1, candidate->component_id); return _candidate_ice_priority (type_preference, 1, candidate->component_id);
......
...@@ -2,25 +2,25 @@ ...@@ -2,25 +2,25 @@
#ifndef _CANDIDATE_H #ifndef _CANDIDATE_H
#define _CANDIDATE_H #define _CANDIDATE_H
typedef enum candidate_type CandidateType; typedef enum candidate_type NiceCandidateType;
enum candidate_type enum candidate_type
{ {
CANDIDATE_TYPE_HOST, NICE_CANDIDATE_TYPE_HOST,
CANDIDATE_TYPE_SERVER_REFLEXIVE, NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE,
CANDIDATE_TYPE_PEER_REFLEXIVE, NICE_CANDIDATE_TYPE_PEER_REFLEXIVE,
CANDIDATE_TYPE_RELAYED, NICE_CANDIDATE_TYPE_RELAYED,
}; };
typedef struct _candidate Candidate; typedef struct _candidate NiceCandidate;
struct _candidate struct _candidate
{ {
CandidateType type; NiceCandidateType type;
guint id; guint id;
Address addr; NiceAddress addr;
Address base_addr; NiceAddress base_addr;
guint16 port; guint16 port;
guint32 priority; guint32 priority;
guint stream_id; guint stream_id;
...@@ -33,14 +33,14 @@ struct _candidate ...@@ -33,14 +33,14 @@ struct _candidate
}; };
Candidate * NiceCandidate *
candidate_new (CandidateType type); nice_candidate_new (NiceCandidateType type);
void void
candidate_free (Candidate *candidate); nice_candidate_free (NiceCandidate *candidate);
gfloat gfloat
candidate_jingle_priority (Candidate *candidate); nice_candidate_jingle_priority (NiceCandidate *candidate);
guint32 guint32
candidate_ice_priority (Candidate *candidate); nice_candidate_ice_priority (NiceCandidate *candidate);
#endif /* _CANDIDATE_H */ #endif /* _CANDIDATE_H */
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
void void
handle_recv ( handle_recv (
Agent *agent, NiceAgent *agent,
guint stream_id, guint stream_id,
guint component_id, guint component_id,
guint len, guint len,
...@@ -21,13 +21,13 @@ handle_recv ( ...@@ -21,13 +21,13 @@ handle_recv (
int int
main (void) main (void)
{ {
Agent *agent; NiceAgent *agent;
agent = ice_agent_new (NULL); agent = nice_agent_new (NULL);
g_assert (ice_agent_add_stream (agent, handle_recv) == 1); g_assert (nice_agent_add_stream (agent, handle_recv) == 1);
g_assert (ice_agent_add_stream (agent, handle_recv) == 2); g_assert (nice_agent_add_stream (agent, handle_recv) == 2);
g_assert (ice_agent_add_stream (agent, handle_recv) == 3); g_assert (nice_agent_add_stream (agent, handle_recv) == 3);
ice_agent_free (agent); nice_agent_free (agent);
return 0; return 0;
} }
......
...@@ -9,12 +9,12 @@ ...@@ -9,12 +9,12 @@
int int
main (void) main (void)
{ {
Candidate *candidate; NiceCandidate *candidate;
candidate = candidate_new (CANDIDATE_TYPE_HOST); candidate = nice_candidate_new (NICE_CANDIDATE_TYPE_HOST);
g_assert (candidate_ice_priority (candidate) == 0x78000200); g_assert (nice_candidate_ice_priority (candidate) == 0x78000200);
g_assert (candidate_jingle_priority (candidate) == 1.0); g_assert (nice_candidate_jingle_priority (candidate) == 1.0);
candidate_free (candidate); nice_candidate_free (candidate);
return 0; return 0;
} }
......
...@@ -14,7 +14,7 @@ static gboolean cb_called = FALSE; ...@@ -14,7 +14,7 @@ static gboolean cb_called = FALSE;
void void
handle_recv ( handle_recv (
Agent *agent, NiceAgent *agent,
guint stream_id, guint stream_id,
guint component_id, guint component_id,
guint len, guint len,
...@@ -31,9 +31,9 @@ handle_recv ( ...@@ -31,9 +31,9 @@ handle_recv (
int int
main (void) main (void)
{ {
Agent *agent; NiceAgent *agent;
Address addr; NiceAddress addr;
Candidate *candidate; NiceCandidate *candidate;
UDPSocketManager mgr; UDPSocketManager mgr;
UDPSocket *sock; UDPSocket *sock;
struct sockaddr_in from = {0,}; struct sockaddr_in from = {0,};
...@@ -41,21 +41,21 @@ main (void) ...@@ -41,21 +41,21 @@ main (void)
udp_fake_socket_manager_init (&mgr); udp_fake_socket_manager_init (&mgr);
/* set up agent */ /* set up agent */
agent = ice_agent_new (&mgr); agent = nice_agent_new (&mgr);
address_set_ipv4_from_string (&addr, "192.168.0.1"); nice_address_set_ipv4_from_string (&addr, "192.168.0.1");
ice_agent_add_local_address (agent, &addr); nice_agent_add_local_address (agent, &addr);
ice_agent_add_stream (agent, handle_recv); nice_agent_add_stream (agent, handle_recv);
g_assert (agent->local_candidates != NULL); g_assert (agent->local_candidates != NULL);
/* recieve an RTP packet */ /* recieve an RTP packet */
candidate = (Candidate *) agent->local_candidates->data; candidate = (NiceCandidate *) agent->local_candidates->data;
sock = &(candidate->sock); sock = &(candidate->sock);
udp_fake_socket_push_recv (sock, &from, 7, "\x80lalala"); udp_fake_socket_push_recv (sock, &from, 7, "\x80lalala");
ice_agent_recv (agent, candidate->id); nice_agent_recv (agent, candidate->id);
g_assert (cb_called == TRUE); g_assert (cb_called == TRUE);
/* clean up */ /* clean up */
ice_agent_free (agent); nice_agent_free (agent);
udp_socket_manager_close (&mgr); udp_socket_manager_close (&mgr);
return 0; return 0;
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
void void
handle_recv ( handle_recv (
Agent *agent, NiceAgent *agent,
guint stream_id, guint stream_id,
guint component_id, guint component_id,
guint len, guint len,
...@@ -25,9 +25,9 @@ handle_recv ( ...@@ -25,9 +25,9 @@ handle_recv (
int int
main (void) main (void)
{ {
Agent *agent; NiceAgent *agent;
Address local_addr, remote_addr; NiceAddress local_addr, remote_addr;
Candidate *candidate; NiceCandidate *candidate;
UDPSocketManager mgr; UDPSocketManager mgr;
UDPSocket *sock; UDPSocket *sock;
StunMessage *breq, *bres; StunMessage *breq, *bres;
...@@ -41,19 +41,19 @@ main (void) ...@@ -41,19 +41,19 @@ main (void)
udp_fake_socket_manager_init (&mgr); udp_fake_socket_manager_init (&mgr);
address_set_ipv4_from_string (&local_addr, "192.168.0.1"); nice_address_set_ipv4_from_string (&local_addr, "192.168.0.1");
address_set_ipv4_from_string (&remote_addr, "192.168.0.5"); nice_address_set_ipv4_from_string (&remote_addr, "192.168.0.5");
from.sin_family = AF_INET; from.sin_family = AF_INET;
from.sin_addr.s_addr = htonl (remote_addr.addr_ipv4); from.sin_addr.s_addr = htonl (remote_addr.addr_ipv4);
from.sin_port = htons (5678); from.sin_port = htons (5678);
/* set up agent */ /* set up agent */
agent = ice_agent_new (&mgr); agent = nice_agent_new (&mgr);
ice_agent_add_local_address (agent, &local_addr); nice_agent_add_local_address (agent, &local_addr);
ice_agent_add_stream (agent, handle_recv); nice_agent_add_stream (agent, handle_recv);
g_assert (agent->local_candidates != NULL); g_assert (agent->local_candidates != NULL);
candidate = (Candidate *) agent->local_candidates->data; candidate = (NiceCandidate *) agent->local_candidates->data;
sock = &(candidate->sock); sock = &(candidate->sock);
/* send binding request */ /* send binding request */
...@@ -65,7 +65,7 @@ main (void) ...@@ -65,7 +65,7 @@ main (void)
stun_message_free (breq); stun_message_free (breq);
/* tell the agent there's a packet waiting */ /* tell the agent there's a packet waiting */
ice_agent_recv (agent, candidate->id); nice_agent_recv (agent, candidate->id);
/* construct expected response packet */ /* construct expected response packet */
bres = stun_message_new (STUN_MESSAGE_BINDING_RESPONSE); bres = stun_message_new (STUN_MESSAGE_BINDING_RESPONSE);
...@@ -89,7 +89,7 @@ main (void) ...@@ -89,7 +89,7 @@ main (void)
stun_message_free (bres); stun_message_free (bres);
/* clean up */ /* clean up */
ice_agent_free (agent); nice_agent_free (agent);
udp_socket_manager_close (&mgr); udp_socket_manager_close (&mgr);
return 0; return 0;
......
...@@ -13,24 +13,24 @@ ...@@ -13,24 +13,24 @@
int int
main (void) main (void)
{ {
Address addr; NiceAddress addr;
Candidate *candidate; NiceCandidate *candidate;
gchar *str; gchar *str;
candidate = candidate_from_string ("x"); candidate = nice_candidate_from_string ("x");
g_assert (candidate == NULL); g_assert (candidate == NULL);
g_assert (address_set_ipv4_from_string (&addr, "192.168.0.1")); g_assert (nice_address_set_ipv4_from_string (&addr, "192.168.0.1"));
candidate = candidate_from_string ("H/192.168.0.1/1234"); candidate = nice_candidate_from_string ("H/192.168.0.1/1234");
g_assert (candidate != NULL); g_assert (candidate != NULL);
g_assert (address_equal (&addr, &(candidate->addr))); g_assert (nice_address_equal (&addr, &(candidate->addr)));
g_assert (candidate->port == 1234); g_assert (candidate->port == 1234);
str = candidate_to_string (candidate); str = nice_candidate_to_string (candidate);
g_assert (0 == strcmp (str, "H/192.168.0.1/1234")); g_assert (0 == strcmp (str, "H/192.168.0.1/1234"));
g_free (str); g_free (str);
candidate_free (candidate); nice_candidate_free (candidate);
return 0; return 0;
} }
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
void void
handle_recv ( handle_recv (
Agent *agent, NiceAgent *agent,
guint stream_id, guint stream_id,
guint component_id, guint component_id,
guint len, guint len,
...@@ -22,57 +22,57 @@ handle_recv ( ...@@ -22,57 +22,57 @@ handle_recv (
gint gint
main (void) main (void)
{ {
Agent *agent; NiceAgent *agent;
Address addr_local, addr_remote; NiceAddress addr_local, addr_remote;
Candidate *candidate; NiceCandidate *candidate;
UDPSocketManager mgr; UDPSocketManager mgr;
udp_fake_socket_manager_init (&mgr); udp_fake_socket_manager_init (&mgr);
address_set_ipv4_from_string (&addr_local, "192.168.0.1"); nice_address_set_ipv4_from_string (&addr_local, "192.168.0.1");
address_set_ipv4_from_string (&addr_remote, "192.168.0.2"); nice_address_set_ipv4_from_string (&addr_remote, "192.168.0.2");
agent = ice_agent_new (&mgr); agent = nice_agent_new (&mgr);
g_assert (agent->local_addresses == NULL); g_assert (agent->local_addresses == NULL);
g_assert (agent->local_candidates == NULL); g_assert (agent->local_candidates == NULL);
g_assert (ice_agent_pop_event (agent) == NULL); g_assert (nice_agent_pop_event (agent) == NULL);
/* add one local address */ /* add one local address */
ice_agent_add_local_address (agent, &addr_local); nice_agent_add_local_address (agent, &addr_local);
g_assert (agent->local_addresses != NULL); g_assert (agent->local_addresses != NULL);
g_assert (g_slist_length (agent->local_addresses) == 1); g_assert (g_slist_length (agent->local_addresses) == 1);
g_assert (address_equal ((Address *) agent->local_addresses->data, g_assert (nice_address_equal ((NiceAddress *) agent->local_addresses->data,
&addr_local)); &addr_local));
/* no candidates should be generated until we have a stream */ /* no candidates should be generated until we have a stream */
g_assert (agent->local_candidates == NULL); g_assert (agent->local_candidates == NULL);
/* add an audio stream */ /* add an audio stream */
ice_agent_add_stream (agent, handle_recv); nice_agent_add_stream (agent, handle_recv);
/* adding a stream should cause host candidates to be generated */ /* adding a stream should cause host candidates to be generated */
g_assert (agent->local_candidates != NULL); g_assert (agent->local_candidates != NULL);
g_assert (g_slist_length (agent->local_candidates) == 1); g_assert (g_slist_length (agent->local_candidates) == 1);
candidate = (Candidate *) agent->local_candidates->data; candidate = (NiceCandidate *) agent->local_candidates->data;
g_assert (address_equal (&(candidate->addr), &addr_local)); g_assert (nice_address_equal (&(candidate->addr), &addr_local));
g_assert (candidate->id == 1); g_assert (candidate->id == 1);
/* fake socket manager uses incremental port numbers starting at 1 */ /* fake socket manager uses incremental port numbers starting at 1 */
g_assert (candidate->port == 1); g_assert (candidate->port == 1);
/* add remote candidate */ /* add remote candidate */
ice_agent_add_remote_candidate (agent, CANDIDATE_TYPE_HOST, &addr_remote, nice_agent_add_remote_candidate (agent, NICE_CANDIDATE_TYPE_HOST,
2345); &addr_remote, 2345);
g_assert (agent->remote_candidates != NULL); g_assert (agent->remote_candidates != NULL);
g_assert (g_slist_length (agent->remote_candidates) == 1); g_assert (g_slist_length (agent->remote_candidates) == 1);
candidate = (Candidate *) agent->remote_candidates->data; candidate = (NiceCandidate *) agent->remote_candidates->data;
g_assert (address_equal (&(candidate->addr), &addr_remote)); g_assert (nice_address_equal (&(candidate->addr), &addr_remote));
g_assert (candidate->port == 2345); g_assert (candidate->port == 2345);
/* check there's no unexpected events, and clean up */ /* check there's no unexpected events, and clean up */
g_assert (ice_agent_pop_event (agent) == NULL); g_assert (nice_agent_pop_event (agent) == NULL);
ice_agent_free (agent); nice_agent_free (agent);
return 0; return 0;
} }
...@@ -13,12 +13,12 @@ ...@@ -13,12 +13,12 @@
/* format is: /* format is:
* type/ip/port * type/ip/port
*/ */
Candidate * NiceCandidate *
candidate_from_string (const gchar *s) nice_candidate_from_string (const gchar *s)
{ {
CandidateType type; NiceCandidateType type;
Candidate *candidate; NiceCandidate *candidate;
Address *addr; NiceAddress *addr;
gchar *first_slash; gchar *first_slash;
gchar *last_slash; gchar *last_slash;
gchar tmp[128]; gchar tmp[128];
...@@ -32,16 +32,16 @@ candidate_from_string (const gchar *s) ...@@ -32,16 +32,16 @@ candidate_from_string (const gchar *s)
switch (s[0]) switch (s[0])
{ {
case 'H': case 'H':
type = CANDIDATE_TYPE_HOST; type = NICE_CANDIDATE_TYPE_HOST;
break; break;
case 'S': case 'S':
type = CANDIDATE_TYPE_SERVER_REFLEXIVE; type = NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE;
break; break;
case 'P': case 'P':
type = CANDIDATE_TYPE_PEER_REFLEXIVE; type = NICE_CANDIDATE_TYPE_PEER_REFLEXIVE;
break; break;
case 'R': case 'R':
type = CANDIDATE_TYPE_RELAYED; type = NICE_CANDIDATE_TYPE_RELAYED;
break; break;
default: default:
return NULL; return NULL;
...@@ -72,9 +72,9 @@ candidate_from_string (const gchar *s) ...@@ -72,9 +72,9 @@ candidate_from_string (const gchar *s)
port = strtol (last_slash + 1, NULL, 10); port = strtol (last_slash + 1, NULL, 10);
candidate = candidate_new (type); candidate = nice_candidate_new (type);
addr = address_new (); addr = nice_address_new ();
address_set_ipv4 (addr, ntohl (ip)); nice_address_set_ipv4 (addr, ntohl (ip));
candidate->addr = *addr; candidate->addr = *addr;
candidate->port = port; candidate->port = port;
...@@ -82,7 +82,7 @@ candidate_from_string (const gchar *s) ...@@ -82,7 +82,7 @@ candidate_from_string (const gchar *s)
} }
gchar * gchar *
candidate_to_string (Candidate *candidate) nice_candidate_to_string (NiceCandidate *candidate)
{ {
gchar *addr_tmp; gchar *addr_tmp;
gchar *ret; gchar *ret;
...@@ -90,23 +90,23 @@ candidate_to_string (Candidate *candidate) ...@@ -90,23 +90,23 @@ candidate_to_string (Candidate *candidate)
switch (candidate->type) switch (candidate->type)
{ {
case CANDIDATE_TYPE_HOST: case NICE_CANDIDATE_TYPE_HOST:
type = 'H'; type = 'H';
break; break;
case CANDIDATE_TYPE_SERVER_REFLEXIVE: case NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE:
type = 'S'; type = 'S';
break; break;
case CANDIDATE_TYPE_PEER_REFLEXIVE: case NICE_CANDIDATE_TYPE_PEER_REFLEXIVE:
type = 'P'; type = 'P';
break; break;
case CANDIDATE_TYPE_RELAYED: case NICE_CANDIDATE_TYPE_RELAYED:
type = 'R'; type = 'R';
break; break;
default: default:
return NULL; return NULL;
} }
addr_tmp = address_to_string (&(candidate->addr)); addr_tmp = nice_address_to_string (&(candidate->addr));
ret = g_strdup_printf ("%c/%s/%d", type, addr_tmp, candidate->port); ret = g_strdup_printf ("%c/%s/%d", type, addr_tmp, candidate->port);
g_free (addr_tmp); g_free (addr_tmp);
return ret; return ret;
......
Candidate * NiceCandidate *
candidate_from_string (const gchar *s); nice_candidate_from_string (const gchar *s);
gchar * gchar *
candidate_to_string (Candidate *candidate); nice_candidate_to_string (NiceCandidate *candidate);
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
static void static void
handle_recv ( handle_recv (
Agent *agent, NiceAgent *agent,
guint stream_id, guint stream_id,
guint component_id, guint component_id,
guint len, guint len,
...@@ -29,22 +29,22 @@ static gboolean ...@@ -29,22 +29,22 @@ static gboolean
make_agent ( make_agent (
gchar *ip, gchar *ip,
UDPSocketManager *mgr, UDPSocketManager *mgr,
Agent **ret_agent, NiceAgent **ret_agent,
UDPSocket **ret_sock) UDPSocket **ret_sock)
{ {
Agent *agent; NiceAgent *agent;
Address addr_local; NiceAddress addr_local;
Candidate *candidate; NiceCandidate *candidate;
agent = ice_agent_new (mgr); agent = nice_agent_new (mgr);
address_set_ipv4_from_string (&addr_local, ip); nice_address_set_ipv4_from_string (&addr_local, ip);
ice_agent_add_local_address (agent, &addr_local); nice_agent_add_local_address (agent, &addr_local);
ice_agent_add_stream (agent, handle_recv); nice_agent_add_stream (agent, handle_recv);
g_assert (agent->local_candidates != NULL); g_assert (agent->local_candidates != NULL);
candidate = (Candidate *) agent->local_candidates->data; candidate = (NiceCandidate *) agent->local_candidates->data;
g_debug ("allocated socket %d port %d for candidate %d", g_debug ("allocated socket %d port %d for candidate %d",
candidate->sock.fileno, ntohs (candidate->sock.addr.sin_port), candidate->sock.fileno, ntohs (candidate->sock.addr.sin_port),
candidate->id); candidate->id);
...@@ -72,7 +72,7 @@ handle_tcp_read (guint fileno) ...@@ -72,7 +72,7 @@ handle_tcp_read (guint fileno)
static void static void
handle_connection (guint fileno, const struct sockaddr_in *sin, gpointer data) handle_connection (guint fileno, const struct sockaddr_in *sin, gpointer data)
{ {
Agent *agent; NiceAgent *agent;
UDPSocketManager mgr; UDPSocketManager mgr;
UDPSocket *sock; UDPSocket *sock;
GSList *sockets = NULL; GSList *sockets = NULL;
...@@ -92,8 +92,8 @@ handle_connection (guint fileno, const struct sockaddr_in *sin, gpointer data) ...@@ -92,8 +92,8 @@ handle_connection (guint fileno, const struct sockaddr_in *sin, gpointer data)
sockets = g_slist_append (sockets, sock); sockets = g_slist_append (sockets, sock);
/* send first local candidate to remote end */ /* send first local candidate to remote end */
candidate_str = candidate_to_string ( candidate_str = nice_candidate_to_string (
(Candidate *) ice_agent_get_local_candidates (agent)->data); (NiceCandidate *) nice_agent_get_local_candidates (agent)->data);
send (fileno, candidate_str, strlen (candidate_str), 0); send (fileno, candidate_str, strlen (candidate_str), 0);
send (fileno, "\n", 1, 0); send (fileno, "\n", 1, 0);
g_free (candidate_str); g_free (candidate_str);
...@@ -133,7 +133,7 @@ handle_connection (guint fileno, const struct sockaddr_in *sin, gpointer data) ...@@ -133,7 +133,7 @@ handle_connection (guint fileno, const struct sockaddr_in *sin, gpointer data)
{ {
/* UDP data */ /* UDP data */
/* XXX: candidate number is hardcoded */ /* XXX: candidate number is hardcoded */
ice_agent_recv (agent, 1); nice_agent_recv (agent, 1);
} }
} }
} }
...@@ -226,3 +226,4 @@ main (int argc, char **argv) ...@@ -226,3 +226,4 @@ main (int argc, char **argv)
return 0; return 0;
} }
libnice { libnice {
global: global:
ice_*; nice_*;
udp_*; udp_*;
address_*;
candidate_*;
}; };
HIDDEN { HIDDEN {
......
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