Commit 16d51b09 authored by Olivier Crête's avatar Olivier Crête

agent: Remove explicit parent pointers

Remove all pointers that don't include have a reference except to agents
parent da41258a
...@@ -1582,7 +1582,7 @@ static void ...@@ -1582,7 +1582,7 @@ static void
g_cancellable_cancel (component->tcp_writable_cancellable); g_cancellable_cancel (component->tcp_writable_cancellable);
agent_queue_signal (agent, signals[SIGNAL_RELIABLE_TRANSPORT_WRITABLE], agent_queue_signal (agent, signals[SIGNAL_RELIABLE_TRANSPORT_WRITABLE],
component->stream->id, component->id); component->stream_id, component->id);
} }
static void static void
...@@ -1600,8 +1600,7 @@ pseudo_tcp_socket_create (NiceAgent *agent, NiceStream *stream, NiceComponent *c ...@@ -1600,8 +1600,7 @@ pseudo_tcp_socket_create (NiceAgent *agent, NiceStream *stream, NiceComponent *c
agent, component->id); agent, component->id);
} }
static void priv_pseudo_tcp_error (NiceAgent *agent, NiceStream *stream, static void priv_pseudo_tcp_error (NiceAgent *agent, NiceComponent *component)
NiceComponent *component)
{ {
if (component->tcp_writable_cancellable) { if (component->tcp_writable_cancellable) {
g_cancellable_cancel (component->tcp_writable_cancellable); g_cancellable_cancel (component->tcp_writable_cancellable);
...@@ -1609,7 +1608,7 @@ static void priv_pseudo_tcp_error (NiceAgent *agent, NiceStream *stream, ...@@ -1609,7 +1608,7 @@ static void priv_pseudo_tcp_error (NiceAgent *agent, NiceStream *stream,
} }
if (component->tcp) { if (component->tcp) {
agent_signal_component_state_change (agent, stream->id, agent_signal_component_state_change (agent, component->stream_id,
component->id, NICE_COMPONENT_STATE_FAILED); component->id, NICE_COMPONENT_STATE_FAILED);
nice_component_detach_all_sockets (component); nice_component_detach_all_sockets (component);
pseudo_tcp_socket_close (component->tcp, TRUE); pseudo_tcp_socket_close (component->tcp, TRUE);
...@@ -1627,10 +1626,9 @@ pseudo_tcp_socket_opened (PseudoTcpSocket *sock, gpointer user_data) ...@@ -1627,10 +1626,9 @@ pseudo_tcp_socket_opened (PseudoTcpSocket *sock, gpointer user_data)
{ {
NiceComponent *component = user_data; NiceComponent *component = user_data;
NiceAgent *agent = component->agent; NiceAgent *agent = component->agent;
NiceStream *stream = component->stream;
nice_debug ("Agent %p: s%d:%d pseudo Tcp socket Opened", agent, nice_debug ("Agent %p: s%d:%d pseudo Tcp socket Opened", agent,
stream->id, component->id); component->stream_id, component->id);
agent_signal_socket_writable (agent, component); agent_signal_socket_writable (agent, component);
} }
...@@ -1787,15 +1785,21 @@ pseudo_tcp_socket_readable (PseudoTcpSocket *sock, gpointer user_data) ...@@ -1787,15 +1785,21 @@ pseudo_tcp_socket_readable (PseudoTcpSocket *sock, gpointer user_data)
{ {
NiceComponent *component = user_data; NiceComponent *component = user_data;
NiceAgent *agent = component->agent; NiceAgent *agent = component->agent;
NiceStream *stream = component->stream;
gboolean has_io_callback; gboolean has_io_callback;
guint stream_id = stream->id; NiceStream *stream = NULL;
guint stream_id = component->stream_id;
guint component_id = component->id; guint component_id = component->id;
g_object_ref (agent); g_object_ref (agent);
if (!agent_find_component (agent, stream_id, component_id,
&stream, &component)) {
g_object_unref (agent);
goto out;
}
nice_debug_verbose ("Agent %p: s%d:%d pseudo Tcp socket readable", agent, nice_debug_verbose ("Agent %p: s%d:%d pseudo Tcp socket readable", agent,
stream->id, component->id); stream_id, component->id);
component->tcp_readable = TRUE; component->tcp_readable = TRUE;
...@@ -1826,7 +1830,7 @@ pseudo_tcp_socket_readable (PseudoTcpSocket *sock, gpointer user_data) ...@@ -1826,7 +1830,7 @@ pseudo_tcp_socket_readable (PseudoTcpSocket *sock, gpointer user_data)
/* Handle errors. */ /* Handle errors. */
if (pseudo_tcp_socket_get_error (sock) != EWOULDBLOCK) { if (pseudo_tcp_socket_get_error (sock) != EWOULDBLOCK) {
nice_debug ("%s: calling priv_pseudo_tcp_error()", G_STRFUNC); nice_debug ("%s: calling priv_pseudo_tcp_error()", G_STRFUNC);
priv_pseudo_tcp_error (agent, stream, component); priv_pseudo_tcp_error (agent, component);
} }
if (component->recv_buf_error != NULL) { if (component->recv_buf_error != NULL) {
...@@ -1889,7 +1893,7 @@ pseudo_tcp_socket_readable (PseudoTcpSocket *sock, gpointer user_data) ...@@ -1889,7 +1893,7 @@ pseudo_tcp_socket_readable (PseudoTcpSocket *sock, gpointer user_data)
component->tcp_readable = FALSE; component->tcp_readable = FALSE;
} else if (n_valid_messages < 0) { } else if (n_valid_messages < 0) {
nice_debug ("%s: calling priv_pseudo_tcp_error()", G_STRFUNC); nice_debug ("%s: calling priv_pseudo_tcp_error()", G_STRFUNC);
priv_pseudo_tcp_error (agent, stream, component); priv_pseudo_tcp_error (agent, component);
} else if (n_valid_messages == 0) { } else if (n_valid_messages == 0) {
/* Reached EOS. */ /* Reached EOS. */
component->tcp_readable = FALSE; component->tcp_readable = FALSE;
...@@ -1912,10 +1916,9 @@ pseudo_tcp_socket_writable (PseudoTcpSocket *sock, gpointer user_data) ...@@ -1912,10 +1916,9 @@ pseudo_tcp_socket_writable (PseudoTcpSocket *sock, gpointer user_data)
{ {
NiceComponent *component = user_data; NiceComponent *component = user_data;
NiceAgent *agent = component->agent; NiceAgent *agent = component->agent;
NiceStream *stream = component->stream;
nice_debug_verbose ("Agent %p: s%d:%d pseudo Tcp socket writable", agent, nice_debug_verbose ("Agent %p: s%d:%d pseudo Tcp socket writable", agent,
stream->id, component->id); component->stream_id, component->id);
agent_signal_socket_writable (agent, component); agent_signal_socket_writable (agent, component);
} }
...@@ -1926,11 +1929,11 @@ pseudo_tcp_socket_closed (PseudoTcpSocket *sock, guint32 err, ...@@ -1926,11 +1929,11 @@ pseudo_tcp_socket_closed (PseudoTcpSocket *sock, guint32 err,
{ {
NiceComponent *component = user_data; NiceComponent *component = user_data;
NiceAgent *agent = component->agent; NiceAgent *agent = component->agent;
NiceStream *stream = component->stream;
nice_debug ("Agent %p: s%d:%d pseudo Tcp socket closed. " nice_debug ("Agent %p: s%d:%d pseudo Tcp socket closed. "
"Calling priv_pseudo_tcp_error().", agent, stream->id, component->id); "Calling priv_pseudo_tcp_error().", agent, component->stream_id,
priv_pseudo_tcp_error (agent, stream, component); component->id);
priv_pseudo_tcp_error (agent, component);
} }
...@@ -1953,7 +1956,7 @@ pseudo_tcp_socket_write_packet (PseudoTcpSocket *psocket, ...@@ -1953,7 +1956,7 @@ pseudo_tcp_socket_write_packet (PseudoTcpSocket *psocket,
nice_debug_verbose ( nice_debug_verbose (
"Agent %p : s%d:%d: sending %d bytes on socket %p (FD %d) to [%s]:%d", "Agent %p : s%d:%d: sending %d bytes on socket %p (FD %d) to [%s]:%d",
component->agent, component->stream->id, component->id, len, component->agent, component->stream_id, component->id, len,
sock->fileno, g_socket_get_fd (sock->fileno), tmpbuf, sock->fileno, g_socket_get_fd (sock->fileno), tmpbuf,
nice_address_get_port (addr)); nice_address_get_port (addr));
} }
...@@ -1983,7 +1986,9 @@ notify_pseudo_tcp_socket_clock_agent_locked (NiceAgent *agent, ...@@ -1983,7 +1986,9 @@ notify_pseudo_tcp_socket_clock_agent_locked (NiceAgent *agent,
NiceComponent *component = user_data; NiceComponent *component = user_data;
NiceStream *stream; NiceStream *stream;
stream = component->stream; stream = agent_find_stream (agent, component->stream_id);
if (!stream)
return G_SOURCE_REMOVE;
pseudo_tcp_socket_notify_clock (component->tcp); pseudo_tcp_socket_notify_clock (component->tcp);
adjust_tcp_clock (agent, stream, component); adjust_tcp_clock (agent, stream, component);
...@@ -2018,7 +2023,7 @@ adjust_tcp_clock (NiceAgent *agent, NiceStream *stream, NiceComponent *component ...@@ -2018,7 +2023,7 @@ adjust_tcp_clock (NiceAgent *agent, NiceStream *stream, NiceComponent *component
nice_debug ("Agent %p: component %d pseudo-TCP socket should be " nice_debug ("Agent %p: component %d pseudo-TCP socket should be "
"destroyed. Calling priv_pseudo_tcp_error().", "destroyed. Calling priv_pseudo_tcp_error().",
agent, component->id); agent, component->id);
priv_pseudo_tcp_error (agent, stream, component); priv_pseudo_tcp_error (agent, component);
} }
} }
} }
...@@ -2028,7 +2033,6 @@ _tcp_sock_is_writable (NiceSocket *sock, gpointer user_data) ...@@ -2028,7 +2033,6 @@ _tcp_sock_is_writable (NiceSocket *sock, gpointer user_data)
{ {
NiceComponent *component = user_data; NiceComponent *component = user_data;
NiceAgent *agent = component->agent; NiceAgent *agent = component->agent;
NiceStream *stream = component->stream;
agent_lock (agent); agent_lock (agent);
...@@ -2041,7 +2045,7 @@ _tcp_sock_is_writable (NiceSocket *sock, gpointer user_data) ...@@ -2041,7 +2045,7 @@ _tcp_sock_is_writable (NiceSocket *sock, gpointer user_data)
} }
nice_debug ("Agent %p: s%d:%d Tcp socket writable", agent, nice_debug ("Agent %p: s%d:%d Tcp socket writable", agent,
stream->id, component->id); component->stream_id, component->id);
agent_signal_socket_writable (agent, component); agent_signal_socket_writable (agent, component);
agent_unlock_and_emit (agent); agent_unlock_and_emit (agent);
...@@ -2413,9 +2417,8 @@ priv_add_new_candidate_discovery_stun (NiceAgent *agent, ...@@ -2413,9 +2417,8 @@ priv_add_new_candidate_discovery_stun (NiceAgent *agent,
cdisco->type = NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE; cdisco->type = NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE;
cdisco->nicesock = nicesock; cdisco->nicesock = nicesock;
cdisco->server = server; cdisco->server = server;
cdisco->stream = stream; cdisco->stream_id = stream->id;
cdisco->component = nice_stream_find_component_by_id (stream, component_id); cdisco->component_id = component_id;
cdisco->agent = agent;
stun_agent_init (&cdisco->stun_agent, STUN_ALL_KNOWN_ATTRIBUTES, stun_agent_init (&cdisco->stun_agent, STUN_ALL_KNOWN_ATTRIBUTES,
STUN_COMPATIBILITY_RFC3489, STUN_COMPATIBILITY_RFC3489,
(agent->compatibility == NICE_COMPATIBILITY_OC2007 || (agent->compatibility == NICE_COMPATIBILITY_OC2007 ||
...@@ -2556,9 +2559,8 @@ priv_add_new_candidate_discovery_turn (NiceAgent *agent, ...@@ -2556,9 +2559,8 @@ priv_add_new_candidate_discovery_turn (NiceAgent *agent,
cdisco->turn = turn_server_ref (turn); cdisco->turn = turn_server_ref (turn);
cdisco->server = turn->server; cdisco->server = turn->server;
cdisco->stream = stream; cdisco->stream_id = stream->id;
cdisco->component = nice_stream_find_component_by_id (stream, component_id); cdisco->component_id = component_id;
cdisco->agent = agent;
if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE) { if (agent->compatibility == NICE_COMPATIBILITY_GOOGLE) {
stun_agent_init (&cdisco->stun_agent, STUN_ALL_KNOWN_ATTRIBUTES, stun_agent_init (&cdisco->stun_agent, STUN_ALL_KNOWN_ATTRIBUTES,
...@@ -2603,10 +2605,9 @@ nice_agent_add_stream ( ...@@ -2603,10 +2605,9 @@ nice_agent_add_stream (
g_return_val_if_fail (n_components >= 1, 0); g_return_val_if_fail (n_components >= 1, 0);
agent_lock (agent); agent_lock (agent);
stream = nice_stream_new (n_components, agent); stream = nice_stream_new (agent->next_stream_id++, n_components, agent);
agent->streams = g_slist_append (agent->streams, stream); agent->streams = g_slist_append (agent->streams, stream);
stream->id = agent->next_stream_id++;
nice_debug ("Agent %p : allocating stream id %u (%p)", agent, stream->id, stream); nice_debug ("Agent %p : allocating stream id %u (%p)", agent, stream->id, stream);
if (agent->reliable) { if (agent->reliable) {
nice_debug ("Agent %p : reliable stream", agent); nice_debug ("Agent %p : reliable stream", agent);
...@@ -4722,7 +4723,7 @@ nice_agent_send_messages_nonblocking_internal ( ...@@ -4722,7 +4723,7 @@ nice_agent_send_messages_nonblocking_internal (
if (n_sent < 0 && !g_error_matches (child_error, G_IO_ERROR, if (n_sent < 0 && !g_error_matches (child_error, G_IO_ERROR,
G_IO_ERROR_WOULD_BLOCK)) { G_IO_ERROR_WOULD_BLOCK)) {
/* Signal errors */ /* Signal errors */
priv_pseudo_tcp_error (agent, stream, component); priv_pseudo_tcp_error (agent, component);
} }
} else { } else {
g_set_error (&child_error, G_IO_ERROR, G_IO_ERROR_FAILED, g_set_error (&child_error, G_IO_ERROR, G_IO_ERROR_FAILED,
...@@ -5133,10 +5134,18 @@ component_io_cb (GSocket *gsocket, GIOCondition condition, gpointer user_data) ...@@ -5133,10 +5134,18 @@ component_io_cb (GSocket *gsocket, GIOCondition condition, gpointer user_data)
component = socket_source->component; component = socket_source->component;
agent = component->agent; agent = component->agent;
stream = component->stream;
agent_lock (agent); agent_lock (agent);
stream = agent_find_stream (agent, component->stream_id);
if (stream == NULL) {
nice_debug ("%s: stream %d destroyed", G_STRFUNC, component->stream_id);
agent_unlock (agent);
return G_SOURCE_REMOVE;
}
if (g_source_is_destroyed (g_main_current_source ())) { if (g_source_is_destroyed (g_main_current_source ())) {
/* Silently return FALSE. */ /* Silently return FALSE. */
nice_debug ("%s: source %p destroyed", G_STRFUNC, g_main_current_source ()); nice_debug ("%s: source %p destroyed", G_STRFUNC, g_main_current_source ());
...@@ -5160,7 +5169,7 @@ component_io_cb (GSocket *gsocket, GIOCondition condition, gpointer user_data) ...@@ -5160,7 +5169,7 @@ component_io_cb (GSocket *gsocket, GIOCondition condition, gpointer user_data)
stream->id, component->id, NICE_COMPONENT_STATE_FAILED); stream->id, component->id, NICE_COMPONENT_STATE_FAILED);
} }
nice_component_remove_socket (component, socket_source->socket); nice_component_remove_socket (agent, component, socket_source->socket);
agent_unlock (agent); agent_unlock (agent);
g_object_unref (agent); g_object_unref (agent);
return G_SOURCE_REMOVE; return G_SOURCE_REMOVE;
...@@ -5326,7 +5335,7 @@ component_io_cb (GSocket *gsocket, GIOCondition condition, gpointer user_data) ...@@ -5326,7 +5335,7 @@ component_io_cb (GSocket *gsocket, GIOCondition condition, gpointer user_data)
done: done:
if (remove_source) if (remove_source)
nice_component_remove_socket (component, socket_source->socket); nice_component_remove_socket (agent, component, socket_source->socket);
/* If we’re in the middle of a read, don’t emit any signals, or we could cause /* If we’re in the middle of a read, don’t emit any signals, or we could cause
* re-entrancy by (e.g.) emitting component-state-changed and having the * re-entrancy by (e.g.) emitting component-state-changed and having the
...@@ -6476,7 +6485,7 @@ nice_agent_forget_relays (NiceAgent *agent, guint stream_id, guint component_id) ...@@ -6476,7 +6485,7 @@ nice_agent_forget_relays (NiceAgent *agent, guint stream_id, guint component_id)
goto done; goto done;
} }
nice_component_clean_turn_servers (component); nice_component_clean_turn_servers (agent, component);
done: done:
agent_unlock_and_emit (agent); agent_unlock_and_emit (agent);
......
...@@ -164,9 +164,13 @@ nice_component_new (guint id, NiceAgent *agent, NiceStream *stream) ...@@ -164,9 +164,13 @@ nice_component_new (guint id, NiceAgent *agent, NiceStream *stream)
} }
void void
nice_component_remove_socket (NiceComponent *cmp, NiceSocket *nsocket) nice_component_remove_socket (NiceAgent *agent, NiceComponent *cmp,
NiceSocket *nsocket)
{ {
GSList *i; GSList *i;
NiceStream *stream;
stream = agent_find_stream (agent, cmp->stream_id);
for (i = cmp->local_candidates; i;) { for (i = cmp->local_candidates; i;) {
NiceCandidate *candidate = i->data; NiceCandidate *candidate = i->data;
...@@ -179,14 +183,14 @@ nice_component_remove_socket (NiceComponent *cmp, NiceSocket *nsocket) ...@@ -179,14 +183,14 @@ nice_component_remove_socket (NiceComponent *cmp, NiceSocket *nsocket)
if (candidate == cmp->selected_pair.local) { if (candidate == cmp->selected_pair.local) {
nice_component_clear_selected_pair (cmp); nice_component_clear_selected_pair (cmp);
agent_signal_component_state_change (cmp->agent, cmp->stream->id, agent_signal_component_state_change (cmp->agent, cmp->stream_id,
cmp->id, NICE_COMPONENT_STATE_FAILED); cmp->id, NICE_COMPONENT_STATE_FAILED);
} }
refresh_prune_candidate (cmp->agent, candidate); refresh_prune_candidate (cmp->agent, candidate);
if (candidate->sockptr != nsocket) { if (candidate->sockptr != nsocket && stream) {
discovery_prune_socket (cmp->agent, candidate->sockptr); discovery_prune_socket (cmp->agent, candidate->sockptr);
conn_check_prune_socket (cmp->agent, cmp->stream, cmp, conn_check_prune_socket (cmp->agent, stream, cmp,
candidate->sockptr); candidate->sockptr);
nice_component_detach_socket (cmp, candidate->sockptr); nice_component_detach_socket (cmp, candidate->sockptr);
} }
...@@ -198,14 +202,18 @@ nice_component_remove_socket (NiceComponent *cmp, NiceSocket *nsocket) ...@@ -198,14 +202,18 @@ nice_component_remove_socket (NiceComponent *cmp, NiceSocket *nsocket)
} }
discovery_prune_socket (cmp->agent, nsocket); discovery_prune_socket (cmp->agent, nsocket);
conn_check_prune_socket (cmp->agent, cmp->stream, cmp, nsocket); if (stream)
conn_check_prune_socket (cmp->agent, stream, cmp, nsocket);
nice_component_detach_socket (cmp, nsocket); nice_component_detach_socket (cmp, nsocket);
} }
void void
nice_component_clean_turn_servers (NiceComponent *cmp) nice_component_clean_turn_servers (NiceAgent *agent, NiceComponent *cmp)
{ {
GSList *i; GSList *i;
NiceStream *stream;
stream = agent_find_stream (agent, cmp->stream_id);
g_list_free_full (cmp->turn_servers, (GDestroyNotify) turn_server_unref); g_list_free_full (cmp->turn_servers, (GDestroyNotify) turn_server_unref);
cmp->turn_servers = NULL; cmp->turn_servers = NULL;
...@@ -232,7 +240,8 @@ nice_component_clean_turn_servers (NiceComponent *cmp) ...@@ -232,7 +240,8 @@ nice_component_clean_turn_servers (NiceComponent *cmp)
if (cmp->turn_candidate) { if (cmp->turn_candidate) {
refresh_prune_candidate (cmp->agent, cmp->turn_candidate); refresh_prune_candidate (cmp->agent, cmp->turn_candidate);
discovery_prune_socket (cmp->agent, cmp->turn_candidate->sockptr); discovery_prune_socket (cmp->agent, cmp->turn_candidate->sockptr);
conn_check_prune_socket (cmp->agent, cmp->stream, cmp, if (stream)
conn_check_prune_socket (cmp->agent, stream, cmp,
cmp->turn_candidate->sockptr); cmp->turn_candidate->sockptr);
nice_component_detach_socket (cmp, cmp->turn_candidate->sockptr); nice_component_detach_socket (cmp, cmp->turn_candidate->sockptr);
nice_candidate_free (cmp->turn_candidate); nice_candidate_free (cmp->turn_candidate);
...@@ -245,7 +254,8 @@ nice_component_clean_turn_servers (NiceComponent *cmp) ...@@ -245,7 +254,8 @@ nice_component_clean_turn_servers (NiceComponent *cmp)
} else { } else {
refresh_prune_candidate (cmp->agent, candidate); refresh_prune_candidate (cmp->agent, candidate);
discovery_prune_socket (cmp->agent, candidate->sockptr); discovery_prune_socket (cmp->agent, candidate->sockptr);
conn_check_prune_socket (cmp->agent, cmp->stream, cmp, if (stream)
conn_check_prune_socket (cmp->agent, stream, cmp,
candidate->sockptr); candidate->sockptr);
nice_component_detach_socket (cmp, candidate->sockptr); nice_component_detach_socket (cmp, candidate->sockptr);
agent_remove_local_candidate (cmp->agent, candidate); agent_remove_local_candidate (cmp->agent, candidate);
...@@ -313,7 +323,7 @@ nice_component_close (NiceComponent *cmp) ...@@ -313,7 +323,7 @@ nice_component_close (NiceComponent *cmp)
(GDestroyNotify) incoming_check_free); (GDestroyNotify) incoming_check_free);
cmp->incoming_checks = NULL; cmp->incoming_checks = NULL;
nice_component_clean_turn_servers (cmp); nice_component_clean_turn_servers (cmp->agent, cmp);
if (cmp->tcp_clock) { if (cmp->tcp_clock) {
g_source_destroy (cmp->tcp_clock); g_source_destroy (cmp->tcp_clock);
...@@ -418,8 +428,13 @@ nice_component_restart (NiceComponent *cmp) ...@@ -418,8 +428,13 @@ nice_component_restart (NiceComponent *cmp)
void void
nice_component_update_selected_pair (NiceComponent *component, const CandidatePair *pair) nice_component_update_selected_pair (NiceComponent *component, const CandidatePair *pair)
{ {
NiceStream *stream;
g_assert (component); g_assert (component);
g_assert (pair); g_assert (pair);
stream = agent_find_stream (component->agent, component->stream_id);
nice_debug ("setting SELECTED PAIR for component %u: %s:%s (prio:%" nice_debug ("setting SELECTED PAIR for component %u: %s:%s (prio:%"
G_GUINT64_FORMAT ").", component->id, pair->local->foundation, G_GUINT64_FORMAT ").", component->id, pair->local->foundation,
pair->remote->foundation, pair->priority); pair->remote->foundation, pair->priority);
...@@ -429,7 +444,8 @@ nice_component_update_selected_pair (NiceComponent *component, const CandidatePa ...@@ -429,7 +444,8 @@ nice_component_update_selected_pair (NiceComponent *component, const CandidatePa
refresh_prune_candidate (component->agent, component->turn_candidate); refresh_prune_candidate (component->agent, component->turn_candidate);
discovery_prune_socket (component->agent, discovery_prune_socket (component->agent,
component->turn_candidate->sockptr); component->turn_candidate->sockptr);
conn_check_prune_socket (component->agent, component->stream, component, if (stream)
conn_check_prune_socket (component->agent, stream, component,
component->turn_candidate->sockptr); component->turn_candidate->sockptr);
nice_component_detach_socket (component, component->turn_candidate->sockptr); nice_component_detach_socket (component, component->turn_candidate->sockptr);
nice_candidate_free (component->turn_candidate); nice_candidate_free (component->turn_candidate);
...@@ -575,7 +591,7 @@ nice_component_attach_socket (NiceComponent *component, NiceSocket *nicesock) ...@@ -575,7 +591,7 @@ nice_component_attach_socket (NiceComponent *component, NiceSocket *nicesock)
/* Create and attach a source */ /* Create and attach a source */
nice_debug ("Component %p (agent %p): Attach source (stream %u).", nice_debug ("Component %p (agent %p): Attach source (stream %u).",
component, component->agent, component->stream->id); component, component->agent, component->stream_id);
socket_source_attach (socket_source, component->ctx); socket_source_attach (socket_source, component->ctx);
} }
...@@ -797,7 +813,7 @@ emit_io_callback_cb (gpointer user_data) ...@@ -797,7 +813,7 @@ emit_io_callback_cb (gpointer user_data)
g_object_ref (agent); g_object_ref (agent);
stream_id = component->stream->id; stream_id = component->stream_id;
component_id = component->id; component_id = component->id;
g_mutex_lock (&component->io_mutex); g_mutex_lock (&component->io_mutex);
...@@ -869,7 +885,7 @@ nice_component_emit_io_callback (NiceComponent *component, ...@@ -869,7 +885,7 @@ nice_component_emit_io_callback (NiceComponent *component,
g_assert (buf_len > 0); g_assert (buf_len > 0);
agent = component->agent; agent = component->agent;
stream_id = component->stream->id; stream_id = component->stream_id;
component_id = component->id; component_id = component->id;
g_mutex_lock (&component->io_mutex); g_mutex_lock (&component->io_mutex);
...@@ -1029,7 +1045,6 @@ nice_component_init (NiceComponent *component) ...@@ -1029,7 +1045,6 @@ nice_component_init (NiceComponent *component)
component->restart_candidate = NULL; component->restart_candidate = NULL;
component->tcp = NULL; component->tcp = NULL;
component->agent = NULL; component->agent = NULL;
component->stream = NULL;
g_mutex_init (&component->io_mutex); g_mutex_init (&component->io_mutex);
g_queue_init (&component->pending_io_messages); g_queue_init (&component->pending_io_messages);
...@@ -1084,9 +1099,12 @@ nice_component_get_property (GObject *obj, ...@@ -1084,9 +1099,12 @@ nice_component_get_property (GObject *obj,
break; break;
case PROP_STREAM: case PROP_STREAM:
g_value_set_object (value, component->stream); {
NiceStream *stream = agent_find_stream (component->agent,
component->stream_id);
g_value_set_object (value, stream);
break; break;
}
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (obj, property_id, pspec);
} }
...@@ -1111,7 +1129,10 @@ nice_component_set_property (GObject *obj, ...@@ -1111,7 +1129,10 @@ nice_component_set_property (GObject *obj,
break; break;
case PROP_STREAM: case PROP_STREAM:
component->stream = g_value_get_object (value); {
NiceStream *stream = g_value_get_object (value);
component->stream_id = stream->id;
}
break; break;
default: default:
......
...@@ -69,7 +69,6 @@ typedef struct _IncomingCheck IncomingCheck; ...@@ -69,7 +69,6 @@ typedef struct _IncomingCheck IncomingCheck;
struct _CandidatePairKeepalive struct _CandidatePairKeepalive
{ {
NiceAgent *agent;
GSource *tick_source; GSource *tick_source;
guint stream_id; guint stream_id;
guint component_id; guint component_id;
...@@ -202,8 +201,7 @@ struct _NiceComponent { ...@@ -202,8 +201,7 @@ struct _NiceComponent {
NiceAgent *agent; /* unowned, immutable: can be accessed without holding the NiceAgent *agent; /* unowned, immutable: can be accessed without holding the
* agent lock */ * agent lock */
NiceStream *stream; /* unowned, immutable: can be accessed without holding guint stream_id;
* the agent lock */
StunAgent stun_agent; /* This stun agent is used to validate all stun requests */ StunAgent stun_agent; /* This stun agent is used to validate all stun requests */
...@@ -263,7 +261,8 @@ void ...@@ -263,7 +261,8 @@ void
nice_component_attach_socket (NiceComponent *component, NiceSocket *nsocket); nice_component_attach_socket (NiceComponent *component, NiceSocket *nsocket);
void void
nice_component_remove_socket (NiceComponent *component, NiceSocket *nsocket); nice_component_remove_socket (NiceAgent *agent, NiceComponent *component,
NiceSocket *nsocket);
void void
nice_component_detach_all_sockets (NiceComponent *component); nice_component_detach_all_sockets (NiceComponent *component);
...@@ -290,7 +289,7 @@ nice_component_emit_io_callback (NiceComponent *component, ...@@ -290,7 +289,7 @@ nice_component_emit_io_callback (NiceComponent *component,
gboolean gboolean
nice_component_has_io_callback (NiceComponent *component); nice_component_has_io_callback (NiceComponent *component);
void void
nice_component_clean_turn_servers (NiceComponent *component); nice_component_clean_turn_servers (NiceAgent *agent, NiceComponent *component);
TurnServer * TurnServer *
......
This diff is collapsed.
...@@ -117,7 +117,8 @@ void ...@@ -117,7 +117,8 @@ void
conn_check_prune_socket (NiceAgent *agent, NiceStream *stream, NiceComponent *component, conn_check_prune_socket (NiceAgent *agent, NiceStream *stream, NiceComponent *component,
NiceSocket *sock); NiceSocket *sock);
guint32 ensure_unique_priority (NiceComponent *component, guint32 priority); guint32 ensure_unique_priority (NiceStream *stream, NiceComponent *component,
guint32 priority);
void recalculate_pair_priorities (NiceAgent *agent); void recalculate_pair_priorities (NiceAgent *agent);
#endif /*_NICE_CONNCHECK_H */ #endif /*_NICE_CONNCHECK_H */
...@@ -111,7 +111,7 @@ void discovery_prune_stream (NiceAgent *agent, guint stream_id) ...@@ -111,7 +111,7 @@ void discovery_prune_stream (NiceAgent *agent, guint stream_id)
CandidateDiscovery *cand = i->data; CandidateDiscovery *cand = i->data;
GSList *next = i->next; GSList *next = i->next;
if (cand->stream->id == stream_id) { if (cand->stream_id == stream_id) {
agent->discovery_list = g_slist_remove (agent->discovery_list, cand); agent->discovery_list = g_slist_remove (agent->discovery_list, cand);
discovery_free_item (cand); discovery_free_item (cand);
} }
...@@ -156,9 +156,8 @@ void discovery_prune_socket (NiceAgent *agent, NiceSocket *sock) ...@@ -156,9 +156,8 @@ void discovery_prune_socket (NiceAgent *agent, NiceSocket *sock)
* Frees the CandidateDiscovery structure pointed to * Frees the CandidateDiscovery structure pointed to
* by 'user data'. Compatible with g_slist_free_full(). * by 'user data'. Compatible with g_slist_free_full().
*/ */
static void refresh_free_item (CandidateRefresh *cand) static void refresh_free_item (NiceAgent *agent, CandidateRefresh *cand)
{ {
NiceAgent *agent = cand->agent;
uint8_t *username; uint8_t *username;
gsize username_len; gsize username_len;
uint8_t *password; uint8_t *password;
...@@ -166,6 +165,8 @@ static void refresh_free_item (CandidateRefresh *cand) ...@@ -166,6 +165,8 @@ static void refresh_free_item (CandidateRefresh *cand)
size_t buffer_len = 0; size_t buffer_len = 0;
StunUsageTurnCompatibility turn_compat = agent_to_turn_compatibility (agent); StunUsageTurnCompatibility turn_compat = agent_to_turn_compatibility (agent);
agent->refresh_list = g_slist_remove (agent->refresh_list, cand);
if (cand->timer_source != NULL) { if (cand->timer_source != NULL) {
g_source_destroy (cand->timer_source); g_source_destroy (cand->timer_source);
g_source_unref (cand->timer_source); g_source_unref (cand->timer_source);
...@@ -227,8 +228,8 @@ static void refresh_free_item (CandidateRefresh *cand) ...@@ -227,8 +228,8 @@ static void refresh_free_item (CandidateRefresh *cand)
*/ */
void refresh_free (NiceAgent *agent) void refresh_free (NiceAgent *agent)
{ {
g_slist_free_full (agent->refresh_list, (GDestroyNotify) refresh_free_item); while (agent->refresh_list)
agent->refresh_list = NULL; refresh_free_item (agent, agent->refresh_list->data);
} }
/* /*
...@@ -248,9 +249,8 @@ void refresh_prune_stream (NiceAgent *agent, guint stream_id) ...@@ -248,9 +249,8 @@ void refresh_prune_stream (NiceAgent *agent, guint stream_id)
/* Don't free the candidate refresh to the currently selected local candidate /* Don't free the candidate refresh to the currently selected local candidate
* unless the whole pair is being destroyed. * unless the whole pair is being destroyed.
*/ */
if (cand->stream->id == stream_id) { if (cand->stream_id == stream_id) {
agent->refresh_list = g_slist_delete_link (agent->refresh_list, i); refresh_free_item (agent, cand);
refresh_free_item (cand);
} }
i = next; i = next;
...@@ -267,8 +267,7 @@ void refresh_prune_candidate (NiceAgent *agent, NiceCandidate *candidate) ...@@ -267,8 +267,7 @@ void refresh_prune_candidate (NiceAgent *agent, NiceCandidate *candidate)
CandidateRefresh *refresh = i->data; CandidateRefresh *refresh = i->data;
if (refresh->candidate == candidate) { if (refresh->candidate == candidate) {
agent->refresh_list = g_slist_delete_link (agent->refresh_list, i); refresh_free_item (agent, refresh);
refresh_free_item (refresh);
} }
i = next; i = next;
...@@ -284,19 +283,16 @@ void refresh_prune_socket (NiceAgent *agent, NiceSocket *sock) ...@@ -284,19 +283,16 @@ void refresh_prune_socket (NiceAgent *agent, NiceSocket *sock)
CandidateRefresh *refresh = i->data; CandidateRefresh *refresh = i->data;
if (refresh->nicesock == sock) { if (refresh->nicesock == sock) {
agent->refresh_list = g_slist_delete_link (agent->refresh_list, i); refresh_free_item (agent, refresh);
refresh_free_item (refresh);
} }
i = next; i = next;
} }
} }
void refresh_cancel (CandidateRefresh *refresh) void refresh_cancel (NiceAgent *agent, CandidateRefresh *refresh)
{ {
refresh->agent->refresh_list = g_slist_remove (refresh->agent->refresh_list, refresh_free_item (agent, refresh);
refresh);
refresh_free_item (refresh);
} }
...@@ -549,7 +545,7 @@ HostCandidateResult discovery_add_local_host_candidate ( ...@@ -549,7 +545,7 @@ HostCandidateResult discovery_add_local_host_candidate (
agent->reliable, FALSE); agent->reliable, FALSE);
} }
candidate->priority = ensure_unique_priority (component, candidate->priority = ensure_unique_priority (stream, component,
candidate->priority); candidate->priority);
priv_generate_candidate_credentials (agent, candidate); priv_generate_candidate_credentials (agent, candidate);
priv_assign_foundation (agent, candidate); priv_assign_foundation (agent, candidate);
...@@ -641,7 +637,7 @@ discovery_add_server_reflexive_candidate ( ...@@ -641,7 +637,7 @@ discovery_add_server_reflexive_candidate (
agent->reliable, nat_assisted); agent->reliable, nat_assisted);
} }
candidate->priority = ensure_unique_priority (component, candidate->priority = ensure_unique_priority (stream, component,
candidate->priority); candidate->priority);
priv_generate_candidate_credentials (agent, candidate); priv_generate_candidate_credentials (agent, candidate);
priv_assign_foundation (agent, candidate); priv_assign_foundation (agent, candidate);
...@@ -760,7 +756,7 @@ discovery_add_relay_candidate ( ...@@ -760,7 +756,7 @@ discovery_add_relay_candidate (
agent->reliable, FALSE); agent->reliable, FALSE);
} }
candidate->priority = ensure_unique_priority (component, candidate->priority = ensure_unique_priority (stream, component,
candidate->priority); candidate->priority);
priv_generate_candidate_credentials (agent, candidate); priv_generate_candidate_credentials (agent, candidate);
...@@ -842,7 +838,7 @@ discovery_add_peer_reflexive_candidate ( ...@@ -842,7 +838,7 @@ discovery_add_peer_reflexive_candidate (
agent->reliable, FALSE); agent->reliable, FALSE);
} }
candidate->priority = ensure_unique_priority (component, candidate->priority = ensure_unique_priority (stream, component,
candidate->priority); candidate->priority);
priv_assign_foundation (agent, candidate); priv_assign_foundation (agent, candidate);
...@@ -1029,12 +1025,15 @@ static gboolean priv_discovery_tick_unlocked (NiceAgent *agent) ...@@ -1029,12 +1025,15 @@ static gboolean priv_discovery_tick_unlocked (NiceAgent *agent)
if (nice_address_is_valid (&cand->server) && if (nice_address_is_valid (&cand->server) &&
(cand->type == NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE || (cand->type == NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE ||
cand->type == NICE_CANDIDATE_TYPE_RELAYED)) { cand->type == NICE_CANDIDATE_TYPE_RELAYED)) {
NiceComponent *component;
if (cand->component->state == NICE_COMPONENT_STATE_DISCONNECTED || if (agent_find_component (agent, cand->stream_id,
cand->component->state == NICE_COMPONENT_STATE_FAILED) cand->component_id, NULL, &component) &&
(component->state == NICE_COMPONENT_STATE_DISCONNECTED ||
component->state == NICE_COMPONENT_STATE_FAILED))
agent_signal_component_state_change (agent, agent_signal_component_state_change (agent,
cand->stream->id, cand->stream_id,
cand->component->id, cand->component_id,
NICE_COMPONENT_STATE_GATHERING); NICE_COMPONENT_STATE_GATHERING);
if (cand->type == NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE) { if (cand->type == NICE_CANDIDATE_TYPE_SERVER_REFLEXIVE) {
......
...@@ -46,15 +46,14 @@ ...@@ -46,15 +46,14 @@
typedef struct typedef struct
{ {
NiceAgent *agent; /* back pointer to owner */
NiceCandidateType type; /* candidate type STUN or TURN */ NiceCandidateType type; /* candidate type STUN or TURN */
NiceSocket *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 server; /* STUN/TURN server address */
GTimeVal next_tick; /* next tick timestamp */ GTimeVal next_tick; /* next tick timestamp */
gboolean pending; /* is discovery in progress? */ gboolean pending; /* is discovery in progress? */
gboolean done; /* is discovery complete? */ gboolean done; /* is discovery complete? */
NiceStream *stream; guint stream_id;
NiceComponent *component; guint component_id;
TurnServer *turn; TurnServer *turn;
StunAgent stun_agent; StunAgent stun_agent;
StunTimer timer; StunTimer timer;
...@@ -66,12 +65,11 @@ typedef struct ...@@ -66,12 +65,11 @@ typedef struct
typedef struct typedef struct
{ {
NiceAgent *agent; /* back pointer to owner */
NiceSocket *nicesock; /* existing socket to use */ NiceSocket *nicesock; /* existing socket to use */
NiceAddress server; /* STUN/TURN server address */ NiceAddress server; /* STUN/TURN server address */
NiceCandidate *candidate; /* candidate to refresh */ NiceCandidate *candidate; /* candidate to refresh */
NiceStream *stream; guint stream_id;
NiceComponent *component; guint component_id;
StunAgent stun_agent; StunAgent stun_agent;
GSource *timer_source; GSource *timer_source;
GSource *tick_source; GSource *tick_source;
...@@ -86,7 +84,7 @@ void refresh_free (NiceAgent *agent); ...@@ -86,7 +84,7 @@ void refresh_free (NiceAgent *agent);
void refresh_prune_stream (NiceAgent *agent, guint stream_id); void refresh_prune_stream (NiceAgent *agent, guint stream_id);
void refresh_prune_candidate (NiceAgent *agent, NiceCandidate *candidate); void refresh_prune_candidate (NiceAgent *agent, NiceCandidate *candidate);
void refresh_prune_socket (NiceAgent *agent, NiceSocket *sock); void refresh_prune_socket (NiceAgent *agent, NiceSocket *sock);
void refresh_cancel (CandidateRefresh *refresh); void refresh_cancel (NiceAgent *agent, CandidateRefresh *refresh);
void discovery_free (NiceAgent *agent); void discovery_free (NiceAgent *agent);
......
...@@ -58,13 +58,15 @@ nice_stream_finalize (GObject *obj); ...@@ -58,13 +58,15 @@ nice_stream_finalize (GObject *obj);
* @brief ICE stream functionality * @brief ICE stream functionality
*/ */
NiceStream * NiceStream *
nice_stream_new (guint n_components, NiceAgent *agent) nice_stream_new (guint stream_id, guint n_components, NiceAgent *agent)
{ {
NiceStream *stream = NULL; NiceStream *stream = NULL;
guint n; guint n;
stream = g_object_new (NICE_TYPE_STREAM, NULL); stream = g_object_new (NICE_TYPE_STREAM, NULL);
stream->id = stream_id;
/* Create the components. */ /* Create the components. */
for (n = 0; n < n_components; n++) { for (n = 0; n < n_components; n++) {
NiceComponent *component = NULL; NiceComponent *component = NULL;
......
...@@ -98,7 +98,7 @@ typedef struct { ...@@ -98,7 +98,7 @@ typedef struct {
GType nice_stream_get_type (void); GType nice_stream_get_type (void);
NiceStream * NiceStream *
nice_stream_new (guint n_components, NiceAgent *agent); nice_stream_new (guint stream_id, guint n_components, NiceAgent *agent);
void void
nice_stream_close (NiceStream *stream); nice_stream_close (NiceStream *stream);
......
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