Commit 50e8cf84 authored by Olivier Crête's avatar Olivier Crête

Don't pass the agent to the socket layer

parent 5aa81a86
...@@ -1392,8 +1392,7 @@ priv_add_new_candidate_discovery_turn (NiceAgent *agent, ...@@ -1392,8 +1392,7 @@ priv_add_new_candidate_discovery_turn (NiceAgent *agent,
agent->proxy_ip != NULL && agent->proxy_ip != NULL &&
nice_address_set_from_string (&proxy_server, agent->proxy_ip)) { nice_address_set_from_string (&proxy_server, agent->proxy_ip)) {
nice_address_set_port (&proxy_server, agent->proxy_port); nice_address_set_port (&proxy_server, agent->proxy_port);
socket = nice_tcp_bsd_socket_new (agent, agent->main_context, socket = nice_tcp_bsd_socket_new (agent->main_context, &proxy_server);
&proxy_server);
if (socket) { if (socket) {
_priv_set_socket_tos (agent, socket, stream->tos); _priv_set_socket_tos (agent, socket, stream->tos);
...@@ -1411,15 +1410,14 @@ priv_add_new_candidate_discovery_turn (NiceAgent *agent, ...@@ -1411,15 +1410,14 @@ priv_add_new_candidate_discovery_turn (NiceAgent *agent,
} }
if (socket == NULL) { if (socket == NULL) {
socket = nice_tcp_bsd_socket_new (agent, agent->main_context, socket = nice_tcp_bsd_socket_new (agent->main_context, &turn->server);
&turn->server);
_priv_set_socket_tos (agent, socket, stream->tos); _priv_set_socket_tos (agent, socket, stream->tos);
} }
if (turn->type == NICE_RELAY_TYPE_TURN_TLS && if (turn->type == NICE_RELAY_TYPE_TURN_TLS &&
agent->compatibility == NICE_COMPATIBILITY_GOOGLE) { agent->compatibility == NICE_COMPATIBILITY_GOOGLE) {
socket = nice_pseudossl_socket_new (agent, socket); socket = nice_pseudossl_socket_new (socket);
} }
cdisco->nicesock = nice_tcp_turn_socket_new (agent, socket, cdisco->nicesock = nice_tcp_turn_socket_new (socket,
agent_to_turn_socket_compatibility (agent)); agent_to_turn_socket_compatibility (agent));
agent_attach_stream_component_socket (agent, stream, agent_attach_stream_component_socket (agent, stream,
...@@ -2818,7 +2816,7 @@ GSource* agent_timeout_add_with_context (NiceAgent *agent, guint interval, ...@@ -2818,7 +2816,7 @@ GSource* agent_timeout_add_with_context (NiceAgent *agent, guint interval,
{ {
GSource *source; GSource *source;
g_return_val_if_fail (function != NULL, 0); g_return_val_if_fail (function != NULL, NULL);
source = g_timeout_source_new (interval); source = g_timeout_source_new (interval);
......
...@@ -598,7 +598,7 @@ discovery_add_relay_candidate ( ...@@ -598,7 +598,7 @@ discovery_add_relay_candidate (
candidate->turn = turn; candidate->turn = turn;
/* step: link to the base candidate+socket */ /* step: link to the base candidate+socket */
relay_socket = nice_turn_socket_new (agent, address, relay_socket = nice_turn_socket_new (agent->main_context, address,
base_socket, &turn->server, base_socket, &turn->server,
turn->username, turn->password, turn->username, turn->password,
agent_to_turn_socket_compatibility (agent)); agent_to_turn_socket_compatibility (agent));
......
...@@ -101,7 +101,7 @@ static void free_to_be_sent (struct to_be_sent *tbs); ...@@ -101,7 +101,7 @@ static void free_to_be_sent (struct to_be_sent *tbs);
NiceSocket * NiceSocket *
nice_pseudossl_socket_new (NiceAgent *agent, NiceSocket *base_socket) nice_pseudossl_socket_new (NiceSocket *base_socket)
{ {
PseudoSSLPriv *priv; PseudoSSLPriv *priv;
NiceSocket *sock = g_slice_new0 (NiceSocket); NiceSocket *sock = g_slice_new0 (NiceSocket);
......
...@@ -38,13 +38,12 @@ ...@@ -38,13 +38,12 @@
#define _PSEUDOSSL_H #define _PSEUDOSSL_H
#include "socket.h" #include "socket.h"
#include "agent.h"
G_BEGIN_DECLS G_BEGIN_DECLS
NiceSocket * NiceSocket *
nice_pseudossl_socket_new (NiceAgent *agent, NiceSocket *base_socket); nice_pseudossl_socket_new (NiceSocket *base_socket);
G_END_DECLS G_END_DECLS
......
...@@ -54,7 +54,6 @@ ...@@ -54,7 +54,6 @@
#endif #endif
typedef struct { typedef struct {
NiceAgent *agent;
NiceAddress server_addr; NiceAddress server_addr;
GQueue send_queue; GQueue send_queue;
GMainContext *context; GMainContext *context;
...@@ -86,7 +85,7 @@ static gboolean socket_send_more (GIOChannel *source, GIOCondition condition, ...@@ -86,7 +85,7 @@ static gboolean socket_send_more (GIOChannel *source, GIOCondition condition,
gpointer data); gpointer data);
NiceSocket * NiceSocket *
nice_tcp_bsd_socket_new (NiceAgent *agent, GMainContext *ctx, NiceAddress *addr) nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr)
{ {
int sockfd = -1; int sockfd = -1;
int ret; int ret;
...@@ -163,7 +162,6 @@ nice_tcp_bsd_socket_new (NiceAgent *agent, GMainContext *ctx, NiceAddress *addr) ...@@ -163,7 +162,6 @@ nice_tcp_bsd_socket_new (NiceAgent *agent, GMainContext *ctx, NiceAddress *addr)
sock->priv = priv = g_slice_new0 (TcpPriv); sock->priv = priv = g_slice_new0 (TcpPriv);
priv->agent = agent;
priv->context = g_main_context_ref (ctx); priv->context = g_main_context_ref (ctx);
priv->server_addr = *addr; priv->server_addr = *addr;
priv->error = FALSE; priv->error = FALSE;
......
...@@ -38,13 +38,12 @@ ...@@ -38,13 +38,12 @@
#define _TCP_BSD_H #define _TCP_BSD_H
#include "socket.h" #include "socket.h"
#include "agent.h"
G_BEGIN_DECLS G_BEGIN_DECLS
NiceSocket * NiceSocket *
nice_tcp_bsd_socket_new (NiceAgent *agent, GMainContext *ctx, NiceAddress *addr); nice_tcp_bsd_socket_new (GMainContext *ctx, NiceAddress *addr);
G_END_DECLS G_END_DECLS
......
...@@ -70,7 +70,7 @@ static gboolean socket_send (NiceSocket *sock, const NiceAddress *to, ...@@ -70,7 +70,7 @@ static gboolean socket_send (NiceSocket *sock, const NiceAddress *to,
static gboolean socket_is_reliable (NiceSocket *sock); static gboolean socket_is_reliable (NiceSocket *sock);
NiceSocket * NiceSocket *
nice_tcp_turn_socket_new (NiceAgent *agent, NiceSocket *base_socket, nice_tcp_turn_socket_new (NiceSocket *base_socket,
NiceTurnSocketCompatibility compatibility) NiceTurnSocketCompatibility compatibility)
{ {
TurnTcpPriv *priv; TurnTcpPriv *priv;
......
...@@ -44,7 +44,7 @@ G_BEGIN_DECLS ...@@ -44,7 +44,7 @@ G_BEGIN_DECLS
NiceSocket * NiceSocket *
nice_tcp_turn_socket_new (NiceAgent *agent, NiceSocket *base_socket, nice_tcp_turn_socket_new (NiceSocket *base_socket,
NiceTurnSocketCompatibility compatibility); NiceTurnSocketCompatibility compatibility);
......
...@@ -71,7 +71,7 @@ typedef struct { ...@@ -71,7 +71,7 @@ typedef struct {
} ChannelBinding; } ChannelBinding;
typedef struct { typedef struct {
NiceAgent *nice; GMainContext *ctx;
StunAgent agent; StunAgent agent;
GList *channels; GList *channels;
GList *pending_bindings; GList *pending_bindings;
...@@ -161,7 +161,7 @@ priv_send_data_queue_destroy (gpointer data) ...@@ -161,7 +161,7 @@ priv_send_data_queue_destroy (gpointer data)
} }
NiceSocket * NiceSocket *
nice_turn_socket_new (NiceAgent *agent, NiceAddress *addr, nice_turn_socket_new (GMainContext *ctx, NiceAddress *addr,
NiceSocket *base_socket, NiceAddress *server_addr, NiceSocket *base_socket, NiceAddress *server_addr,
gchar *username, gchar *password, gchar *username, gchar *password,
NiceTurnSocketCompatibility compatibility) NiceTurnSocketCompatibility compatibility)
...@@ -198,10 +198,11 @@ nice_turn_socket_new (NiceAgent *agent, NiceAddress *addr, ...@@ -198,10 +198,11 @@ nice_turn_socket_new (NiceAgent *agent, NiceAddress *addr,
STUN_AGENT_USAGE_NO_ALIGNED_ATTRIBUTES); STUN_AGENT_USAGE_NO_ALIGNED_ATTRIBUTES);
} }
priv->nice = agent;
priv->channels = NULL; priv->channels = NULL;
priv->current_binding = NULL; priv->current_binding = NULL;
priv->base_socket = base_socket; priv->base_socket = base_socket;
if (ctx)
priv->ctx = g_main_context_ref (ctx);
if (compatibility == NICE_TURN_SOCKET_COMPATIBILITY_MSN || if (compatibility == NICE_TURN_SOCKET_COMPATIBILITY_MSN ||
compatibility == NICE_TURN_SOCKET_COMPATIBILITY_OC2007) { compatibility == NICE_TURN_SOCKET_COMPATIBILITY_OC2007) {
...@@ -291,6 +292,9 @@ socket_close (NiceSocket *sock) ...@@ -291,6 +292,9 @@ socket_close (NiceSocket *sock)
if (priv->permission_timeout_source) if (priv->permission_timeout_source)
g_source_remove (priv->permission_timeout_source); g_source_remove (priv->permission_timeout_source);
if (priv->ctx)
g_main_context_unref (priv->ctx);
g_free (priv->current_binding); g_free (priv->current_binding);
g_free (priv->current_binding_msg); g_free (priv->current_binding_msg);
g_free (priv->current_create_permission_msg); g_free (priv->current_create_permission_msg);
...@@ -321,6 +325,22 @@ socket_recv (NiceSocket *sock, NiceAddress *from, guint len, gchar *buf) ...@@ -321,6 +325,22 @@ socket_recv (NiceSocket *sock, NiceAddress *from, guint len, gchar *buf)
return recv_len; return recv_len;
} }
static GSource *
priv_timeout_add_with_context (TurnPriv *priv, guint interval,
GSourceFunc function, gpointer data)
{
GSource *source;
g_return_val_if_fail (function != NULL, NULL);
source = g_timeout_source_new (interval);
g_source_set_callback (source, function, data, NULL);
g_source_attach (source, priv->ctx);
return source;
}
static StunMessageReturn static StunMessageReturn
stun_message_append_ms_connection_id(StunMessage *msg, stun_message_append_ms_connection_id(StunMessage *msg,
uint8_t *ms_connection_id, uint32_t ms_sequence_num) uint8_t *ms_connection_id, uint32_t ms_sequence_num)
...@@ -557,7 +577,7 @@ socket_send (NiceSocket *sock, const NiceAddress *to, ...@@ -557,7 +577,7 @@ socket_send (NiceSocket *sock, const NiceAddress *to,
req->priv = priv; req->priv = priv;
stun_message_id (&msg, req->id); stun_message_id (&msg, req->id);
req->source = agent_timeout_add_with_context (priv->nice, req->source = priv_timeout_add_with_context (priv,
STUN_END_TIMEOUT, priv_forget_send_request, req); STUN_END_TIMEOUT, priv_forget_send_request, req);
g_queue_push_tail (priv->send_requests, req); g_queue_push_tail (priv->send_requests, req);
} }
...@@ -1275,7 +1295,7 @@ priv_schedule_tick (TurnPriv *priv) ...@@ -1275,7 +1295,7 @@ priv_schedule_tick (TurnPriv *priv)
guint timeout = stun_timer_remainder (&priv->current_binding_msg->timer); guint timeout = stun_timer_remainder (&priv->current_binding_msg->timer);
if (timeout > 0) { if (timeout > 0) {
priv->tick_source_channel_bind = priv->tick_source_channel_bind =
agent_timeout_add_with_context (priv->nice, timeout, priv_timeout_add_with_context (priv, timeout,
priv_retransmissions_tick, priv); priv_retransmissions_tick, priv);
} else { } else {
priv_retransmissions_tick_unlocked (priv); priv_retransmissions_tick_unlocked (priv);
...@@ -1288,7 +1308,7 @@ priv_schedule_tick (TurnPriv *priv) ...@@ -1288,7 +1308,7 @@ priv_schedule_tick (TurnPriv *priv)
if (timeout > 0) { if (timeout > 0) {
priv->tick_source_create_permission = priv->tick_source_create_permission =
agent_timeout_add_with_context (priv->nice, priv_timeout_add_with_context (priv,
timeout, timeout,
priv_retransmissions_create_permission_tick, priv_retransmissions_create_permission_tick,
priv); priv);
......
...@@ -47,7 +47,6 @@ typedef enum { ...@@ -47,7 +47,6 @@ typedef enum {
} NiceTurnSocketCompatibility; } NiceTurnSocketCompatibility;
#include "socket.h" #include "socket.h"
#include "agent.h"
#include "stun/stunmessage.h" #include "stun/stunmessage.h"
...@@ -62,7 +61,7 @@ gboolean ...@@ -62,7 +61,7 @@ gboolean
nice_turn_socket_set_peer (NiceSocket *sock, NiceAddress *peer); nice_turn_socket_set_peer (NiceSocket *sock, NiceAddress *peer);
NiceSocket * NiceSocket *
nice_turn_socket_new (NiceAgent *agent, NiceAddress *addr, nice_turn_socket_new (GMainContext *ctx, NiceAddress *addr,
NiceSocket *base_socket, NiceAddress *server_addr, NiceSocket *base_socket, NiceAddress *server_addr,
gchar *username, gchar *password, NiceTurnSocketCompatibility compatibility); gchar *username, gchar *password, NiceTurnSocketCompatibility compatibility);
......
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