Commit 01e72828 authored by Youness Alaoui's avatar Youness Alaoui

Port libnice to the new NiceSocket API

parent 4d04f6a4
......@@ -68,8 +68,8 @@ struct _NiceAgent
GObject parent; /**< gobject pointer */
gboolean full_mode; /**< property: full-mode */
NiceUDPSocketFactory udp_socket_factory; /**< property: socket factory */
NiceUDPSocketFactory relay_socket_factory; /**< property: socket factory */
NiceSocketFactory *udp_socket_factory; /**< property: socket factory */
NiceSocketFactory *relay_socket_factory; /**< property: socket factory */
GTimeVal next_check_tv; /**< property: next conncheck timestamp */
gchar *stun_server_ip; /**< property: STUN server IP */
guint stun_server_port; /**< property: STUN server port */
......@@ -138,6 +138,6 @@ GSource *agent_timeout_add_with_context (NiceAgent *agent, guint interval, GSour
void priv_attach_stream_component_socket (NiceAgent *agent,
Stream *stream,
Component *component,
NiceUDPSocket *udp_socket);
NiceSocket *socket);
#endif /*_NICE_AGENT_PRIV_H */
......@@ -57,8 +57,7 @@
#include "debug.h"
#include "udp.h"
#include "udp-bsd.h"
#include "socket.h"
#include "udp-turn.h"
#include "candidate.h"
#include "component.h"
......@@ -377,8 +376,10 @@ nice_agent_init (NiceAgent *agent)
STUN_AGENT_USAGE_SHORT_TERM_CREDENTIALS |
STUN_AGENT_USAGE_USE_FINGERPRINT);
nice_udp_bsd_socket_factory_init (&agent->udp_socket_factory);
nice_udp_turn_socket_factory_init (&agent->relay_socket_factory);
agent->udp_socket_factory =
nice_socket_factory_new (NICE_SOCKET_FACTORY_UDP_BSD);
agent->relay_socket_factory =
nice_socket_factory_new (NICE_SOCKET_FACTORY_UDP_RELAY);
agent->rng = nice_rng_new ();
priv_generate_tie_breaker (agent);
......@@ -1305,22 +1306,21 @@ _nice_agent_recv (
NiceAgent *agent,
Stream *stream,
Component *component,
NiceUDPSocket *udp_socket,
NiceSocket *socket,
guint buf_len,
gchar *buf)
{
NiceAddress from;
gint len;
len = nice_udp_socket_recv (udp_socket, &from,
buf_len, buf);
len = nice_socket_recv (socket, &from, buf_len, buf);
#ifndef NDEBUG
if (len >= 0) {
gchar tmpbuf[INET6_ADDRSTRLEN];
nice_address_to_string (&from, tmpbuf);
nice_debug ("Agent %p : Packet received on local socket %u from [%s]:%u (%u octets).", agent,
udp_socket->fileno, tmpbuf, nice_address_get_port (&from), len);
socket->fileno, tmpbuf, nice_address_get_port (&from), len);
}
#endif
......@@ -1341,7 +1341,7 @@ _nice_agent_recv (
NiceCandidate *cand = i->data;
if (cand->type == NICE_CANDIDATE_TYPE_RELAYED) {
len = nice_udp_turn_socket_parse_recv (cand->sockptr, &from, len, buf, &from, buf, len);
udp_socket = cand->sockptr;
socket = cand->sockptr;
}
}
}
......@@ -1352,7 +1352,7 @@ _nice_agent_recv (
return len;
if (conn_check_handle_inbound_stun (agent, stream, component, udp_socket,
if (conn_check_handle_inbound_stun (agent, stream, component, socket,
&from, buf, len))
/* handled STUN message*/
return 0;
......@@ -1399,7 +1399,7 @@ nice_agent_recv (
for (i = component->sockets; i; i = i->next)
{
NiceUDPSocket *sockptr = i->data;
NiceSocket *sockptr = i->data;
FD_SET (sockptr->fileno, &fds);
max_fd = MAX (sockptr->fileno, max_fd);
......@@ -1421,7 +1421,7 @@ nice_agent_recv (
for (j = 0; j <= max_fd; j++)
if (FD_ISSET (j, &fds))
{
NiceUDPSocket *socket;
NiceSocket *socket;
socket = component_find_udp_socket_by_fd (component, j);
g_assert (socket);
......@@ -1454,7 +1454,7 @@ nice_agent_recv_sock (
guint buf_len,
gchar *buf)
{
NiceUDPSocket *socket;
NiceSocket *socket;
Stream *stream;
Component *component;
guint ret = 0;
......@@ -1517,7 +1517,7 @@ nice_agent_poll_read (
for (j = component->sockets; j; j = j->next)
{
NiceUDPSocket *sockptr = j->data;
NiceSocket *sockptr = j->data;
FD_SET (sockptr->fileno, &fds);
max_fd = MAX (sockptr->fileno, max_fd);
......@@ -1554,7 +1554,7 @@ nice_agent_poll_read (
}
else
{
NiceUDPSocket *socket = NULL;
NiceSocket *socket = NULL;
Stream *stream = NULL;
Component *component = NULL;
gchar buf[MAX_BUFFER_SIZE];
......@@ -1622,7 +1622,7 @@ nice_agent_send (
if (component->selected_pair.local != NULL)
{
NiceUDPSocket *sock;
NiceSocket *sock;
NiceAddress *addr;
#ifndef NDEBUG
......@@ -1636,7 +1636,7 @@ nice_agent_send (
sock = component->selected_pair.local->sockptr;
addr = &component->selected_pair.remote->addr;
nice_udp_socket_send (sock, addr, len, buf);
nice_socket_send (sock, addr, len, buf);
component->media_after_tick = TRUE;
ret = len;
......@@ -1802,10 +1802,10 @@ nice_agent_dispose (GObject *object)
if (G_OBJECT_CLASS (nice_agent_parent_class)->dispose)
G_OBJECT_CLASS (nice_agent_parent_class)->dispose (object);
nice_udp_socket_factory_close (&agent->udp_socket_factory);
nice_udp_socket_factory_close (&agent->relay_socket_factory);
nice_socket_factory_free (agent->udp_socket_factory);
agent->udp_socket_factory = NULL;
nice_socket_factory_free (agent->relay_socket_factory);
agent->relay_socket_factory = NULL;
g_static_rec_mutex_free (&agent->mutex);
}
......@@ -1818,7 +1818,7 @@ struct _IOCtx
NiceAgent *agent;
Stream *stream;
Component *component;
NiceUDPSocket *socket;
NiceSocket *socket;
};
......@@ -1827,7 +1827,7 @@ io_ctx_new (
NiceAgent *agent,
Stream *stream,
Component *component,
NiceUDPSocket *socket)
NiceSocket *socket)
{
IOCtx *ctx;
......@@ -1888,7 +1888,7 @@ void
priv_attach_stream_component_socket (NiceAgent *agent,
Stream *stream,
Component *component,
NiceUDPSocket *udp_socket)
NiceSocket *socket)
{
GIOChannel *io;
GSource *source;
......@@ -1897,11 +1897,11 @@ priv_attach_stream_component_socket (NiceAgent *agent,
if (!component->ctx)
return;
io = g_io_channel_unix_new (udp_socket->fileno);
io = g_io_channel_unix_new (socket->fileno);
/* note: without G_IO_ERR the glib mainloop goes into
* busyloop if errors are encountered */
source = g_io_create_watch (io, G_IO_IN | G_IO_ERR);
ctx = io_ctx_new (agent, stream, component, udp_socket);
ctx = io_ctx_new (agent, stream, component, socket);
g_source_set_callback (source, (GSourceFunc) nice_agent_g_source_cb,
ctx, (GDestroyNotify) io_ctx_free);
nice_debug ("Agent %p : Attach source %p (stream %u).", agent, source, stream->id);
......
......@@ -41,7 +41,7 @@
#include <glib-object.h>
#include "udp.h"
#include "socket.h"
#include "address.h"
#include "candidate.h"
#include "random.h"
......
......@@ -39,7 +39,7 @@
#ifndef _CANDIDATE_H
#define _CANDIDATE_H
#include "udp.h"
#include "socket.h"
G_BEGIN_DECLS
......@@ -76,7 +76,7 @@ struct _NiceCandidate
guint stream_id;
guint component_id;
gchar foundation[NICE_CANDIDATE_MAX_FOUNDATION];
NiceUDPSocket *sockptr;
NiceSocket *sockptr;
gchar *username; /* pointer to a NULL-terminated username string */
gchar *password; /* pointer to a NULL-terminated password string */
};
......
......@@ -87,9 +87,8 @@ component_free (Component *cmp)
cmp->restart_candidate = NULL;
for (i = cmp->sockets; i; i = i->next) {
NiceUDPSocket *udpsocket = i->data;
nice_udp_socket_close (udpsocket);
g_slice_free (NiceUDPSocket, udpsocket);
NiceSocket *udpsocket = i->data;
nice_socket_free (udpsocket);
}
for (i = cmp->gsources; i; i = i->next) {
......@@ -130,7 +129,7 @@ component_find_udp_socket_by_fd (Component *component, guint fd)
for (i = component->sockets; i; i = i->next)
{
NiceUDPSocket *sockptr = i->data;
NiceSocket *sockptr = i->data;
if (sockptr->fileno == fd)
return sockptr;
......
......@@ -67,7 +67,7 @@ struct _CandidatePair
struct _IncomingCheck
{
NiceAddress from;
NiceUDPSocket *local_socket;
NiceSocket *local_socket;
uint32_t priority;
gboolean use_candidate;
};
......@@ -79,7 +79,7 @@ struct _Component
NiceComponentState state;
GSList *local_candidates; /**< list of Candidate objs */
GSList *remote_candidates; /**< list of Candidate objs */
GSList *sockets; /**< list of NiceUDPSocket objs */
GSList *sockets; /**< list of NiceSocket objs */
GSList *gsources; /**< list of GSource objs */
GSList *incoming_checks; /**< list of IncomingCheck objs */
NiceAddress turn_server; /**< TURN server address */
......
This diff is collapsed.
......@@ -86,7 +86,7 @@ void conn_check_free (NiceAgent *agent);
gboolean conn_check_schedule_next (NiceAgent *agent);
int conn_check_send (NiceAgent *agent, CandidateCheckPair *pair);
gboolean conn_check_prune_stream (NiceAgent *agent, Stream *stream);
gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream, Component *component, NiceUDPSocket *udp_socket, const NiceAddress *from, gchar *buf, guint len);
gboolean conn_check_handle_inbound_stun (NiceAgent *agent, Stream *stream, Component *component, NiceSocket *udp_socket, const NiceAddress *from, gchar *buf, guint len);
gint conn_check_compare (const CandidateCheckPair *a, const CandidateCheckPair *b);
void conn_check_remote_candidates_set(NiceAgent *agent);
......
......@@ -281,7 +281,7 @@ NiceCandidate *discovery_add_local_host_candidate (
NiceCandidate *candidate;
Component *component;
Stream *stream;
NiceUDPSocket *udp_socket = NULL;
NiceSocket *udp_socket = NULL;
gboolean errors = FALSE;
if (!agent_find_component (agent, stream_id, component_id, &stream, &component))
......@@ -347,7 +347,7 @@ NiceCandidate *discovery_add_local_host_candidate (
if (candidate)
nice_candidate_free (candidate), candidate = NULL;
if (udp_socket)
g_slice_free (NiceUDPSocket, udp_socket);
nice_socket_free (udp_socket);
}
return candidate;
......@@ -365,7 +365,7 @@ discovery_add_server_reflexive_candidate (
guint stream_id,
guint component_id,
NiceAddress *address,
NiceUDPSocket *base_socket)
NiceSocket *base_socket)
{
NiceCandidate *candidate;
Component *component;
......@@ -422,21 +422,21 @@ discovery_add_relay_candidate (
guint stream_id,
guint component_id,
NiceAddress *address,
NiceUDPSocket *base_socket)
NiceSocket *base_socket)
{
NiceCandidate *candidate;
Component *component;
Stream *stream;
gboolean result = FALSE;
gboolean errors = FALSE;
NiceUDPSocket *relay_socket = NULL;
NiceSocket *relay_socket = NULL;
if (!agent_find_component (agent, stream_id, component_id, &stream, &component))
return NULL;
candidate = nice_candidate_new (NICE_CANDIDATE_TYPE_RELAYED);
if (candidate) {
relay_socket = g_slice_new0 (NiceUDPSocket);
relay_socket = g_slice_new0 (NiceSocket);
if (relay_socket) {
if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE) {
candidate->priority = nice_candidate_jingle_priority (candidate) * 1000;
......@@ -451,7 +451,7 @@ discovery_add_relay_candidate (
candidate->addr = *address;
/* step: link to the base candidate+socket */
if (nice_udp_turn_create_socket_full (&agent->relay_socket_factory,
if (nice_udp_turn_create_socket_full (agent->relay_socket_factory,
relay_socket, address, base_socket, &component->turn_server,
component->turn_username, component->turn_password,
priv_agent_to_udp_turn_compatibility (agent))) {
......@@ -484,7 +484,7 @@ discovery_add_relay_candidate (
if (candidate)
nice_candidate_free (candidate), candidate = NULL;
if (relay_socket)
g_slice_free (NiceUDPSocket, relay_socket);
g_slice_free (NiceSocket, relay_socket);
}
return candidate;
}
......@@ -501,7 +501,7 @@ discovery_add_peer_reflexive_candidate (
guint stream_id,
guint component_id,
NiceAddress *address,
NiceUDPSocket *base_socket,
NiceSocket *base_socket,
NiceCandidate *local,
NiceCandidate *remote)
{
......@@ -602,7 +602,7 @@ NiceCandidate *discovery_learn_remote_peer_reflexive_candidate (
Component *component,
guint32 priority,
const NiceAddress *remote_address,
NiceUDPSocket *udp_socket,
NiceSocket *udp_socket,
NiceCandidate *local,
NiceCandidate *remote)
{
......@@ -751,7 +751,7 @@ static gboolean priv_discovery_tick_unlocked (gpointer pointer)
stun_timer_start (&cand->timer);
/* send the conncheck */
nice_udp_socket_send (cand->nicesock, &cand->server,
nice_socket_send (cand->nicesock, &cand->server,
buffer_len, (gchar *)cand->stun_buffer);
/* case: success, start waiting for the result */
......@@ -800,7 +800,7 @@ static gboolean priv_discovery_tick_unlocked (gpointer pointer)
timeout);
/* TODO retransmit */
nice_udp_socket_send (cand->nicesock, &cand->server,
nice_socket_send (cand->nicesock, &cand->server,
stun_message_length (&cand->stun_message),
(gchar *)cand->stun_buffer);
......
......@@ -48,7 +48,7 @@ struct _CandidateDiscovery
NiceAgent *agent; /**< back pointer to owner */
NiceCandidateType type; /**< candidate type STUN or TURN */
guint socket; /**< XXX: should be taken from local cand: existing socket to use */
NiceUDPSocket *nicesock; /**< XXX: should be taken from local cand: existing socket to use */
NiceSocket *nicesock; /**< XXX: should be taken from local cand: existing socket to use */
NiceAddress server; /**< STUN/TURN server address */
NiceAddress *interface; /**< Address of local interface */
GTimeVal next_tick; /**< next tick timestamp */
......@@ -84,7 +84,7 @@ discovery_add_relay_candidate (
guint stream_id,
guint component_id,
NiceAddress *address,
NiceUDPSocket *base_socket);
NiceSocket *base_socket);
NiceCandidate*
discovery_add_server_reflexive_candidate (
......@@ -92,7 +92,7 @@ discovery_add_server_reflexive_candidate (
guint stream_id,
guint component_id,
NiceAddress *address,
NiceUDPSocket *base_socket);
NiceSocket *base_socket);
NiceCandidate*
discovery_add_peer_reflexive_candidate (
......@@ -100,7 +100,7 @@ discovery_add_peer_reflexive_candidate (
guint stream_id,
guint component_id,
NiceAddress *address,
NiceUDPSocket *base_socket,
NiceSocket *base_socket,
NiceCandidate *local,
NiceCandidate *remote);
......@@ -111,7 +111,7 @@ discovery_learn_remote_peer_reflexive_candidate (
Component *component,
guint32 priority,
const NiceAddress *remote_address,
NiceUDPSocket *udp_socket,
NiceSocket *udp_socket,
NiceCandidate *local,
NiceCandidate *remote);
......
......@@ -38,9 +38,7 @@
#ifndef _NICE_H
#define _NICE_H
#include "udp.h"
#include "udp-bsd.h"
#include "udp-fake.h"
#include "socket.h"
#include "agent.h"
#include "random.h"
#include "random-glib.h"
......
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