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