Commit 471708b2 authored by Youness Alaoui's avatar Youness Alaoui

fix keepalive issue when there is network/cpu bottleneck

parent 0fe5f7c2
...@@ -112,6 +112,7 @@ struct _NiceAgent ...@@ -112,6 +112,7 @@ struct _NiceAgent
GStaticRecMutex mutex; /* Mutex used for thread-safe lib */ GStaticRecMutex mutex; /* Mutex used for thread-safe lib */
NiceCompatibility compatibility; /* property: Compatibility mode */ NiceCompatibility compatibility; /* property: Compatibility mode */
StunAgent stun_agent; /* STUN agent */ StunAgent stun_agent; /* STUN agent */
gboolean media_after_tick; /* Received media after keepalive tick */
#ifdef HAVE_GUPNP #ifdef HAVE_GUPNP
GUPnPSimpleIgdThread* upnp; /* GUPnP Single IGD agent */ GUPnPSimpleIgdThread* upnp; /* GUPnP Single IGD agent */
gboolean upnp_enabled; /* whether UPnP discovery is enabled */ gboolean upnp_enabled; /* whether UPnP discovery is enabled */
......
...@@ -537,6 +537,7 @@ nice_agent_init (NiceAgent *agent) ...@@ -537,6 +537,7 @@ nice_agent_init (NiceAgent *agent)
agent->conncheck_timer_source = NULL; agent->conncheck_timer_source = NULL;
agent->keepalive_timer_source = NULL; agent->keepalive_timer_source = NULL;
agent->refresh_list = NULL; agent->refresh_list = NULL;
agent->media_after_tick = FALSE;
agent->compatibility = NICE_COMPATIBILITY_DRAFT19; agent->compatibility = NICE_COMPATIBILITY_DRAFT19;
...@@ -1790,6 +1791,8 @@ _nice_agent_recv ( ...@@ -1790,6 +1791,8 @@ _nice_agent_recv (
} }
} }
agent->media_after_tick = TRUE;
if (stun_message_validate_buffer_length ((uint8_t *) buf, (size_t) len) != len) if (stun_message_validate_buffer_length ((uint8_t *) buf, (size_t) len) != len)
/* If the retval is no 0, its not a valid stun packet, probably data */ /* If the retval is no 0, its not a valid stun packet, probably data */
return len; return len;
......
...@@ -489,11 +489,25 @@ static gboolean priv_conn_keepalive_retransmissions_tick (gpointer pointer) ...@@ -489,11 +489,25 @@ static gboolean priv_conn_keepalive_retransmissions_tick (gpointer pointer)
stun_message_id (&pair->keepalive.stun_message, id); stun_message_id (&pair->keepalive.stun_message, id);
stun_agent_forget_transaction (&pair->keepalive.agent->stun_agent, id); stun_agent_forget_transaction (&pair->keepalive.agent->stun_agent, id);
if (pair->keepalive.agent->media_after_tick) {
nice_debug ("Agent %p : Keepalive conncheck timed out!! "
"but media was received. Suspecting keepalive lost because of "
"network bottleneck", pair->keepalive.agent);
if (pair->keepalive.tick_source) {
g_source_destroy (pair->keepalive.tick_source);
g_source_unref (pair->keepalive.tick_source);
pair->keepalive.tick_source = NULL;
}
pair->keepalive.stun_message.buffer = NULL;
} else {
nice_debug ("Agent %p : Keepalive conncheck timed out!! " nice_debug ("Agent %p : Keepalive conncheck timed out!! "
"peer probably lost connection", pair->keepalive.agent); "peer probably lost connection", pair->keepalive.agent);
agent_signal_component_state_change (pair->keepalive.agent, agent_signal_component_state_change (pair->keepalive.agent,
pair->keepalive.stream_id, pair->keepalive.component_id, pair->keepalive.stream_id, pair->keepalive.component_id,
NICE_COMPONENT_STATE_FAILED); NICE_COMPONENT_STATE_FAILED);
}
break; break;
} }
case STUN_USAGE_TIMER_RETURN_RETRANSMIT: case STUN_USAGE_TIMER_RETURN_RETRANSMIT:
...@@ -589,6 +603,8 @@ static gboolean priv_conn_keepalive_tick_unlocked (NiceAgent *agent) ...@@ -589,6 +603,8 @@ static gboolean priv_conn_keepalive_tick_unlocked (NiceAgent *agent)
if (buf_len > 0) { if (buf_len > 0) {
stun_timer_start (&p->keepalive.timer); stun_timer_start (&p->keepalive.timer);
agent->media_after_tick = FALSE;
/* send the conncheck */ /* send the conncheck */
nice_socket_send (p->local->sockptr, &p->remote->addr, nice_socket_send (p->local->sockptr, &p->remote->addr,
buf_len, (gchar *)p->keepalive.stun_buffer); buf_len, (gchar *)p->keepalive.stun_buffer);
......
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