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 @@
#include "address.h"
Address *
address_new (void)
NiceAddress *
nice_address_new (void)
{
return g_slice_new0 (Address);
return g_slice_new0 (NiceAddress);
}
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;
}
......@@ -27,13 +27,13 @@ address_set_ipv4 (Address *addr, guint32 addr_ipv4)
* Returns FALSE on error.
*/
gboolean
address_set_ipv4_from_string (Address *addr, gchar *str)
nice_address_set_ipv4_from_string (NiceAddress *addr, gchar *str)
{
struct in_addr iaddr;
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;
}
else
......@@ -45,13 +45,13 @@ address_set_ipv4_from_string (Address *addr, gchar *str)
gchar *
address_to_string (Address *addr)
nice_address_to_string (NiceAddress *addr)
{
struct in_addr iaddr;
gchar ip_str[INET_ADDRSTRLEN];
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);
ret = inet_ntop (AF_INET, &iaddr, ip_str, INET_ADDRSTRLEN);
g_assert (ret);
......@@ -60,22 +60,22 @@ address_to_string (Address *addr)
gboolean
address_equal (Address *a, Address *b)
nice_address_equal (NiceAddress *a, NiceAddress *b)
{
if (a->type != b->type)
return FALSE;
if (a->type == ADDRESS_TYPE_IPV4)
if (a->type == NICE_ADDRESS_TYPE_IPV4)
return a->addr_ipv4 == b->addr_ipv4;
g_assert_not_reached ();
}
Address *
address_dup (Address *a)
NiceAddress *
nice_address_dup (NiceAddress *a)
{
Address *dup = g_slice_new0 (Address);
NiceAddress *dup = g_slice_new0 (NiceAddress);
*dup = *a;
return dup;
......@@ -83,9 +83,9 @@ address_dup (Address *a)
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)
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);
g_assert_not_reached ();
......
......@@ -2,20 +2,20 @@
#ifndef _ADDRESS_H
#define _ADDRESS_H
typedef enum address_type AddressType;
typedef enum address_type NiceAddressType;
enum address_type
{
ADDRESS_TYPE_IPV4,
ADDRESS_TYPE_IPV6,
NICE_ADDRESS_TYPE_IPV4,
NICE_ADDRESS_TYPE_IPV6,
};
typedef struct _address Address;
typedef struct _address NiceAddress;
/* XXX: need access to fields to convert to sockaddr_in */
struct _address
{
AddressType type;
NiceAddressType type;
union
{
guint32 addr_ipv4;
......@@ -23,20 +23,20 @@ struct _address
};
};
Address *
address_new (void);
NiceAddress *
nice_address_new (void);
void
address_free (Address *addr);
Address *
address_dup (Address *a);
nice_address_free (NiceAddress *addr);
NiceAddress *
nice_address_dup (NiceAddress *a);
void
address_set_ipv4 (Address *addr, guint32 addr_ipv4);
nice_address_set_ipv4 (NiceAddress *addr, guint32 addr_ipv4);
gboolean
address_set_ipv4_from_string (Address *addr, gchar *str);
nice_address_set_ipv4_from_string (NiceAddress *addr, gchar *str);
gboolean
address_equal (Address *a, Address *b);
nice_address_equal (NiceAddress *a, NiceAddress *b);
gchar *
address_to_string (Address *addr);
nice_address_to_string (NiceAddress *addr);
#endif /* _ADDRESS_H */
......@@ -67,7 +67,7 @@ struct _stream
guint id;
/* XXX: streams can have multiple components */
Component *component;
AgentRecvHandler handle_recv;
NiceAgentRecvHandler handle_recv;
};
......@@ -97,8 +97,8 @@ typedef struct _candidate_pair CandidatePair;
struct _candidate_pair
{
Candidate local;
Candidate remote;
NiceCandidate local;
NiceCandidate remote;
};
......@@ -142,7 +142,7 @@ candidate_pair_priority (
#if 0
static Event *
event_new (EventType type)
nice_event_new (EventType type)
{
Event *ev;
......@@ -154,7 +154,7 @@ event_new (EventType type)
void
event_free (Event *ev)
nice_event_free (Event *ev)
{
switch (ev->type)
{
......@@ -169,12 +169,12 @@ event_free (Event *ev)
/*** agent ***/
Agent *
ice_agent_new (UDPSocketManager *mgr)
NiceAgent *
nice_agent_new (UDPSocketManager *mgr)
{
Agent *agent;
NiceAgent *agent;
agent = g_slice_new0 (Agent);
agent = g_slice_new0 (NiceAgent);
agent->sockmgr = mgr;
agent->next_candidate_id = 1;
agent->next_stream_id = 1;
......@@ -183,7 +183,7 @@ ice_agent_new (UDPSocketManager *mgr)
Event *
ice_agent_pop_event (Agent *agent)
nice_agent_pop_event (NiceAgent *agent)
{
Event *event;
GSList *head;
......@@ -200,23 +200,23 @@ ice_agent_pop_event (Agent *agent)
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);
}
static void
ice_agent_add_local_host_candidate (
Agent *agent,
nice_agent_add_local_host_candidate (
NiceAgent *agent,
guint stream_id,
guint component_id,
Address *address)
NiceAddress *address)
{
Candidate *candidate;
NiceCandidate *candidate;
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->stream_id = stream_id;
candidate->component_id = component_id;
......@@ -235,9 +235,9 @@ ice_agent_add_local_host_candidate (
guint
ice_agent_add_stream (
Agent *agent,
AgentRecvHandler handle_recv)
nice_agent_add_stream (
NiceAgent *agent,
NiceAgentRecvHandler handle_recv)
{
Stream *stream;
GSList *i;
......@@ -251,9 +251,9 @@ ice_agent_add_stream (
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);
/* XXX: need to check for redundant candidates? */
......@@ -265,10 +265,10 @@ ice_agent_add_stream (
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,
address_dup (addr));
nice_address_dup (addr));
/* XXX: Should we generate local candidates for existing streams at this
* 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)
void
ice_agent_add_remote_candidate (
Agent *agent,
CandidateType type,
Address *addr,
nice_agent_add_remote_candidate (
NiceAgent *agent,
NiceCandidateType type,
NiceAddress *addr,
guint port)
{
/* append to agent->remote_candidates */
Candidate *candidate;
NiceCandidate *candidate;
candidate = candidate_new (type);
candidate = nice_candidate_new (type);
/* do remote candidates need IDs? */
candidate->id = 0;
candidate->addr = *addr;
......@@ -301,14 +301,14 @@ ice_agent_add_remote_candidate (
}
static Candidate *
_local_candidate_lookup (Agent *agent, guint candidate_id)
static NiceCandidate *
_local_candidate_lookup (NiceAgent *agent, guint candidate_id)
{
GSList *i;
for (i = agent->local_candidates; i; i = i->next)
{
Candidate *c = (Candidate *) i->data;
NiceCandidate *c = (NiceCandidate *) i->data;
if (c->id == candidate_id)
return c;
......@@ -319,7 +319,7 @@ _local_candidate_lookup (Agent *agent, guint candidate_id)
static Stream *
_stream_lookup (Agent *agent, guint stream_id)
_stream_lookup (NiceAgent *agent, guint stream_id)
{
GSList *i;
......@@ -343,11 +343,11 @@ _stream_lookup (Agent *agent, guint stream_id)
* block if the socket is blocking.
*/
void
ice_agent_recv (
Agent *agent,
nice_agent_recv (
NiceAgent *agent,
guint candidate_id)
{
Candidate *candidate;
NiceCandidate *candidate;
guint len;
gchar buf[1024];
struct sockaddr_in from;
......@@ -451,28 +451,28 @@ ice_agent_recv (
*/
/*
void
ice_agent_set_stun_server (Address *addr, guint16 port)
nice_agent_set_stun_server (NiceAddress *addr, guint16 port)
{
}
*/
const GSList *
ice_agent_get_local_candidates (
Agent *agent)
nice_agent_get_local_candidates (
NiceAgent *agent)
{
return agent->local_candidates;
}
void
ice_agent_free (Agent *agent)
nice_agent_free (NiceAgent *agent)
{
GSList *i;
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);
......@@ -480,9 +480,9 @@ ice_agent_free (Agent *agent)
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);
......@@ -490,9 +490,9 @@ ice_agent_free (Agent *agent)
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);
......@@ -508,6 +508,6 @@ ice_agent_free (Agent *agent)
g_slist_free (agent->streams);
agent->streams = NULL;
g_slice_free (Agent, agent);
g_slice_free (NiceAgent, agent);
}
......@@ -30,13 +30,13 @@ struct _event
union {
struct {
Address *addr;
NiceAddress *addr;
guint candidate_id;
} request_port;
struct {
Address *from;
NiceAddress *from;
guint from_port;
Address *to;
NiceAddress *to;
guint to_port;
} request_stun_query;
};
......@@ -50,7 +50,7 @@ event_free (Event *ev);
/*** agent ***/
typedef struct _agent Agent;
typedef struct _agent NiceAgent;
struct _agent
{
......@@ -65,35 +65,36 @@ struct _agent
};
typedef void (*AgentRecvHandler) (
Agent *agent, guint stream_id, guint component_id, guint len, gchar *buf);
typedef void (*NiceAgentRecvHandler) (
NiceAgent *agent, guint stream_id, guint component_id, guint len,
gchar *buf);
Agent *
ice_agent_new (UDPSocketManager *mgr);
NiceAgent *
nice_agent_new (UDPSocketManager *mgr);
Event *
ice_agent_pop_event (Agent *agent);
nice_agent_pop_event (NiceAgent *agent);
void
ice_agent_add_local_address (Agent *agent, Address *addr);
nice_agent_add_local_address (NiceAgent *agent, NiceAddress *addr);
guint
ice_agent_add_stream (
Agent *agent,
AgentRecvHandler handle_recv);
nice_agent_add_stream (
NiceAgent *agent,
NiceAgentRecvHandler handle_recv);
void
ice_agent_free (Agent *agent);
nice_agent_free (NiceAgent *agent);
void
ice_agent_add_remote_candidate (
Agent *agent,
CandidateType type,
Address *addr,
nice_agent_add_remote_candidate (
NiceAgent *agent,
NiceCandidateType type,
NiceAddress *addr,
guint port);
void
ice_agent_recv (
Agent *agent,
nice_agent_recv (
NiceAgent *agent,
guint candidate_id);
const GSList *
ice_agent_get_local_candidates (
Agent *agent);
nice_agent_get_local_candidates (
NiceAgent *agent);
#endif /* _AGENT_H */
......@@ -7,33 +7,33 @@
* candidates, server reflexive candidates, and relayed candidates. */
Candidate *
candidate_new (CandidateType type)
NiceCandidate *
nice_candidate_new (NiceCandidateType type)
{
Candidate *candidate;
NiceCandidate *candidate;
candidate = g_slice_new0 (Candidate);
candidate = g_slice_new0 (NiceCandidate);
candidate->type = type;
return candidate;
}
void
candidate_free (Candidate *candidate)
nice_candidate_free (NiceCandidate *candidate)
{
g_slice_free (Candidate, candidate);
g_slice_free (NiceCandidate, candidate);
}
gfloat
candidate_jingle_priority (Candidate *candidate)
nice_candidate_jingle_priority (NiceCandidate *candidate)
{
switch (candidate->type)
{
case CANDIDATE_TYPE_HOST: return 1.0;
case CANDIDATE_TYPE_SERVER_REFLEXIVE: return 0.9;
case CANDIDATE_TYPE_PEER_REFLEXIVE: return 0.9;
case CANDIDATE_TYPE_RELAYED: return 0.5;
case NICE_CANDIDATE_TYPE_HOST: return 1.0;
case NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE: return 0.9;
case NICE_CANDIDATE_TYPE_PEER_REFLEXIVE: return 0.9;
case NICE_CANDIDATE_TYPE_RELAYED: return 0.5;
}
/* appease GCC */
......@@ -60,16 +60,16 @@ _candidate_ice_priority (
guint32
candidate_ice_priority (Candidate *candidate)
nice_candidate_ice_priority (NiceCandidate *candidate)
{
guint8 type_preference = 0;
switch (candidate->type)
{
case CANDIDATE_TYPE_HOST: type_preference = 120; break;
case CANDIDATE_TYPE_PEER_REFLEXIVE: type_preference = 110; break;
case CANDIDATE_TYPE_SERVER_REFLEXIVE: type_preference = 100; break;
case CANDIDATE_TYPE_RELAYED: type_preference = 60; break;
case NICE_CANDIDATE_TYPE_HOST: type_preference = 120; break;
case NICE_CANDIDATE_TYPE_PEER_REFLEXIVE: type_preference = 110; break;
case NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE: type_preference = 100; break;
case NICE_CANDIDATE_TYPE_RELAYED: type_preference = 60; break;
}
return _candidate_ice_priority (type_preference, 1, candidate->component_id);
......
......@@ -2,25 +2,25 @@
#ifndef _CANDIDATE_H
#define _CANDIDATE_H
typedef enum candidate_type CandidateType;
typedef enum candidate_type NiceCandidateType;
enum candidate_type
{
CANDIDATE_TYPE_HOST,
CANDIDATE_TYPE_SERVER_REFLEXIVE,
CANDIDATE_TYPE_PEER_REFLEXIVE,
CANDIDATE_TYPE_RELAYED,
NICE_CANDIDATE_TYPE_HOST,
NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE,
NICE_CANDIDATE_TYPE_PEER_REFLEXIVE,
NICE_CANDIDATE_TYPE_RELAYED,
};
typedef struct _candidate Candidate;
typedef struct _candidate NiceCandidate;
struct _candidate
{
CandidateType type;
NiceCandidateType type;
guint id;
Address addr;
Address base_addr;
NiceAddress addr;
NiceAddress base_addr;
guint16 port;
guint32 priority;
guint stream_id;
......@@ -33,14 +33,14 @@ struct _candidate
};
Candidate *
candidate_new (CandidateType type);
NiceCandidate *
nice_candidate_new (NiceCandidateType type);
void
candidate_free (Candidate *candidate);
nice_candidate_free (NiceCandidate *candidate);
gfloat
candidate_jingle_priority (Candidate *candidate);
nice_candidate_jingle_priority (NiceCandidate *candidate);
guint32
candidate_ice_priority (Candidate *candidate);
nice_candidate_ice_priority (NiceCandidate *candidate);
#endif /* _CANDIDATE_H */
......@@ -9,7 +9,7 @@
void
handle_recv (
Agent *agent,
NiceAgent *agent,
guint stream_id,
guint component_id,
guint len,
......@@ -21,13 +21,13 @@ handle_recv (
int
main (void)
{
Agent *agent;
NiceAgent *agent;
agent = ice_agent_new (NULL);
g_assert (ice_agent_add_stream (agent, handle_recv) == 1);
g_assert (ice_agent_add_stream (agent, handle_recv) == 2);
g_assert (ice_agent_add_stream (agent, handle_recv) == 3);
ice_agent_free (agent);
agent = nice_agent_new (NULL);
g_assert (nice_agent_add_stream (agent, handle_recv) == 1);
g_assert (nice_agent_add_stream (agent, handle_recv) == 2);
g_assert (nice_agent_add_stream (agent, handle_recv) == 3);
nice_agent_free (agent);
return 0;
}
......
......@@ -9,12 +9,12 @@
int
main (void)
{
Candidate *candidate;
NiceCandidate *candidate;
candidate = candidate_new (CANDIDATE_TYPE_HOST);
g_assert (candidate_ice_priority (candidate) == 0x78000200);
g_assert (candidate_jingle_priority (candidate) == 1.0);
candidate_free (candidate);
candidate = nice_candidate_new (NICE_CANDIDATE_TYPE_HOST);
g_assert (nice_candidate_ice_priority (candidate) == 0x78000200);
g_assert (nice_candidate_jingle_priority (candidate) == 1.0);
nice_candidate_free (candidate);
return 0;
}
......
......@@ -14,7 +14,7 @@ static gboolean cb_called = FALSE;
void