From e2f46325dec56d006767c05941b6749f8023adac Mon Sep 17 00:00:00 2001 From: Youness Alaoui Date: Fri, 27 Mar 2009 17:59:08 -0400 Subject: [PATCH] Call stun_agent_forget_transaction when a transaction times out to avoid using all the saved id slots in the stun agent --- agent/conncheck.c | 59 +++++++++++++++++++++++++++++++++++++++---------------- agent/discovery.c | 27 +++++++++++++++++++------ socket/turn.c | 22 ++++++++++++++------- 3 files changed, 78 insertions(+), 30 deletions(-) diff --git a/agent/conncheck.c b/agent/conncheck.c index 548ff47..92d6c93 100644 --- a/agent/conncheck.c +++ b/agent/conncheck.c @@ -265,13 +265,23 @@ static gboolean priv_conn_check_tick_stream (Stream *stream, NiceAgent *agent, G } else if (priv_timer_expired (&p->next_tick, now)) { switch (stun_timer_refresh (&p->timer)) { case STUN_USAGE_TIMER_RETURN_TIMEOUT: - /* case: error, abort processing */ - nice_debug ("Agent %p : Retransmissions failed, giving up on connectivity check %p", agent, p); - p->state = NICE_CHECK_FAILED; - nice_debug ("Agent %p : pair %p state FAILED", agent, p); - p->stun_message.buffer = NULL; - p->stun_message.buffer_len = 0; - break; + { + /* case: error, abort processing */ + StunTransactionId id; + + nice_debug ("Agent %p : Retransmissions failed, giving up on connectivity check %p", agent, p); + p->state = NICE_CHECK_FAILED; + nice_debug ("Agent %p : pair %p state FAILED", agent, p); + + stun_message_id (&p->stun_message, id); + stun_agent_forget_transaction (&agent->stun_agent, id); + + p->stun_message.buffer = NULL; + p->stun_message.buffer_len = 0; + + + break; + } case STUN_USAGE_TIMER_RETURN_RETRANSMIT: { /* case: not ready, so schedule a new timeout */ @@ -471,13 +481,21 @@ static gboolean priv_conn_keepalive_retransmissions_tick (gpointer pointer) switch (stun_timer_refresh (&pair->keepalive.timer)) { case STUN_USAGE_TIMER_RETURN_TIMEOUT: - /* Time out */ - nice_debug ("Agent %p : Keepalive conncheck timed out!! " - "peer probably lost connection", pair->keepalive.agent); - agent_signal_component_state_change (pair->keepalive.agent, - pair->keepalive.stream_id, pair->keepalive.component_id, - NICE_COMPONENT_STATE_FAILED); - break; + { + /* Time out */ + StunTransactionId id; + + + stun_message_id (&pair->keepalive.stun_message, id); + stun_agent_forget_transaction (&pair->keepalive.agent->stun_agent, id); + + nice_debug ("Agent %p : Keepalive conncheck timed out!! " + "peer probably lost connection", pair->keepalive.agent); + agent_signal_component_state_change (pair->keepalive.agent, + pair->keepalive.stream_id, pair->keepalive.component_id, + NICE_COMPONENT_STATE_FAILED); + break; + } case STUN_USAGE_TIMER_RETURN_RETRANSMIT: /* Retransmit */ nice_socket_send (pair->local->sockptr, &pair->remote->addr, @@ -676,9 +694,16 @@ static gboolean priv_turn_allocate_refresh_retransmissions_tick (gpointer pointe switch (stun_timer_refresh (&cand->timer)) { case STUN_USAGE_TIMER_RETURN_TIMEOUT: - /* Time out */ - refresh_cancel (cand); - break; + { + /* Time out */ + StunTransactionId id; + + stun_message_id (&cand->stun_message, id); + stun_agent_forget_transaction (&cand->stun_agent, id); + + refresh_cancel (cand); + break; + } case STUN_USAGE_TIMER_RETURN_RETRANSMIT: /* Retransmit */ nice_socket_send (cand->nicesock, &cand->server, diff --git a/agent/discovery.c b/agent/discovery.c index abfbe7b..2fcdb8c 100644 --- a/agent/discovery.c +++ b/agent/discovery.c @@ -173,6 +173,13 @@ void refresh_free_item (gpointer data, gpointer user_data) agent_to_turn_compatibility (agent)); if (buffer_len > 0) { + StunTransactionId id; + + /* forget the transaction since we don't care about the result and + * we don't implement retransmissions/timeout */ + stun_message_id (&cand->stun_message, id); + stun_agent_forget_transaction (&cand->stun_agent, id); + /* send the refresh twice since we won't do retransmissions */ nice_socket_send (cand->nicesock, &cand->server, buffer_len, (gchar *)cand->stun_buffer); @@ -895,12 +902,20 @@ static gboolean priv_discovery_tick_unlocked (gpointer pointer) else if (priv_timer_expired (&cand->next_tick, &now)) { switch (stun_timer_refresh (&cand->timer)) { case STUN_USAGE_TIMER_RETURN_TIMEOUT: - /* case: error, abort processing */ - cand->done = TRUE; - cand->stun_message.buffer = NULL; - cand->stun_message.buffer_len = 0; - nice_debug ("Agent %p : bind discovery timed out, aborting discovery item.", agent); - break; + { + /* Time out */ + /* case: error, abort processing */ + StunTransactionId id; + + stun_message_id (&cand->stun_message, id); + stun_agent_forget_transaction (&cand->stun_agent, id); + + cand->done = TRUE; + cand->stun_message.buffer = NULL; + cand->stun_message.buffer_len = 0; + nice_debug ("Agent %p : bind discovery timed out, aborting discovery item.", agent); + break; + } case STUN_USAGE_TIMER_RETURN_RETRANSMIT: { /* case: not ready complete, so schedule next timeout */ diff --git a/socket/turn.c b/socket/turn.c index 744fc74..90c7207 100644 --- a/socket/turn.c +++ b/socket/turn.c @@ -517,13 +517,21 @@ priv_retransmissions_tick_unlocked (TurnPriv *priv) if (priv->current_binding_msg) { switch (stun_timer_refresh (&priv->current_binding_msg->timer)) { case STUN_USAGE_TIMER_RETURN_TIMEOUT: - /* Time out */ - g_free (priv->current_binding); - priv->current_binding = NULL; - g_free (priv->current_binding_msg); - priv->current_binding_msg = NULL; - priv_process_pending_bindings (priv); - break; + { + /* Time out */ + StunTransactionId id; + + g_free (priv->current_binding); + priv->current_binding = NULL; + g_free (priv->current_binding_msg); + priv->current_binding_msg = NULL; + + stun_message_id (&priv->current_binding_msg->message, id); + stun_agent_forget_transaction (&priv->agent, id); + + priv_process_pending_bindings (priv); + break; + } case STUN_USAGE_TIMER_RETURN_RETRANSMIT: /* Retransmit */ nice_socket_send (priv->base_socket, &priv->server_addr, -- 2.11.4.GIT