summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYouness Alaoui <youness.alaoui@collabora.co.uk>2009-06-09 19:39:25 -0400
committerYouness Alaoui <youness.alaoui@collabora.co.uk>2009-06-09 19:40:29 -0400
commit471708b20adc1d03be4d9ddce80840627f3a30e9 (patch)
tree575094d5724ce09066f10c6d0182b0986e4cab8f
parent0fe5f7c2df38d1c9a26b4dffc84537380ffcfd48 (diff)
downloadlibnice-471708b20adc1d03be4d9ddce80840627f3a30e9.tar.gz
fix keepalive issue when there is network/cpu bottleneck
-rw-r--r--agent/agent-priv.h1
-rw-r--r--agent/agent.c3
-rw-r--r--agent/conncheck.c26
3 files changed, 25 insertions, 5 deletions
diff --git a/agent/agent-priv.h b/agent/agent-priv.h
index cdc2698..b041e34 100644
--- a/agent/agent-priv.h
+++ b/agent/agent-priv.h
@@ -112,6 +112,7 @@ struct _NiceAgent
GStaticRecMutex mutex; /* Mutex used for thread-safe lib */
NiceCompatibility compatibility; /* property: Compatibility mode */
StunAgent stun_agent; /* STUN agent */
+ gboolean media_after_tick; /* Received media after keepalive tick */
#ifdef HAVE_GUPNP
GUPnPSimpleIgdThread* upnp; /* GUPnP Single IGD agent */
gboolean upnp_enabled; /* whether UPnP discovery is enabled */
diff --git a/agent/agent.c b/agent/agent.c
index 905cd79..9bdba8a 100644
--- a/agent/agent.c
+++ b/agent/agent.c
@@ -537,6 +537,7 @@ nice_agent_init (NiceAgent *agent)
agent->conncheck_timer_source = NULL;
agent->keepalive_timer_source = NULL;
agent->refresh_list = NULL;
+ agent->media_after_tick = FALSE;
agent->compatibility = NICE_COMPATIBILITY_DRAFT19;
@@ -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 the retval is no 0, its not a valid stun packet, probably data */
return len;
diff --git a/agent/conncheck.c b/agent/conncheck.c
index a0382bb..8e919b2 100644
--- a/agent/conncheck.c
+++ b/agent/conncheck.c
@@ -489,11 +489,25 @@ static gboolean priv_conn_keepalive_retransmissions_tick (gpointer pointer)
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);
+ 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!! "
+ "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:
@@ -589,6 +603,8 @@ static gboolean priv_conn_keepalive_tick_unlocked (NiceAgent *agent)
if (buf_len > 0) {
stun_timer_start (&p->keepalive.timer);
+ agent->media_after_tick = FALSE;
+
/* send the conncheck */
nice_socket_send (p->local->sockptr, &p->remote->addr,
buf_len, (gchar *)p->keepalive.stun_buffer);