agent: stay in aggressive mode after stun requests have been sent
authorFabrice Bellet <fabrice@bellet.info>
Thu, 23 Apr 2020 15:12:41 +0000 (17:12 +0200)
committerFabrice Bellet <fabrice@bellet.info>
Fri, 8 May 2020 15:24:29 +0000 (17:24 +0200)
This patch updates the previous commit "agent: stay in aggressive mode
after conncheck has started", by accepting to switch from aggressive to
regular mode, while no stun request has been sent. It gives the agent
some extra delay to still accept remote tcp candidates, after its state
already changed from gathering to connecting.

agent/agent.c
agent/conncheck.c
agent/conncheck.h

index 5d3fbb4..110d242 100644 (file)
@@ -3733,11 +3733,7 @@ static gboolean priv_add_remote_candidate (
       if (agent->controlling_mode &&
           agent->nomination_mode == NICE_NOMINATION_MODE_AGGRESSIVE &&
           transport != NICE_CANDIDATE_TRANSPORT_UDP) {
-        if (component->state < NICE_COMPONENT_STATE_CONNECTING) {
-          nice_debug ("Agent %p : we have a TCP candidate, switching back "
-              "to regular nomination mode", agent);
-          agent->nomination_mode = NICE_NOMINATION_MODE_REGULAR;
-        } else {
+        if (conn_check_stun_transactions_count (agent) > 0) {
           /* changing nomination mode from aggressive to regular while
            * conncheck is ongoing may cause unexpected results (inflight
            * aggressive stun requests may nominate a pair unilaterally)
@@ -3745,6 +3741,10 @@ static gboolean priv_add_remote_candidate (
           nice_debug ("Agent %p : we have a TCP candidate, but conncheck "
               "has started already in aggressive mode, ignore it", agent);
           goto errors;
+        } else {
+          nice_debug ("Agent %p : we have a TCP candidate, switching back "
+              "to regular nomination mode", agent);
+          agent->nomination_mode = NICE_NOMINATION_MODE_REGULAR;
         }
       }
     }
index fc4b3eb..927a402 100644 (file)
@@ -536,6 +536,24 @@ priv_conn_check_unfreeze_maybe (NiceAgent *agent, CandidateCheckPair *pair)
   }
 }
 
+guint
+conn_check_stun_transactions_count (NiceAgent *agent)
+{
+  GSList *i, *j;
+  guint count = 0;
+
+  for (i = agent->streams; i ; i = i->next) {
+    NiceStream *s = i->data;
+    for (j = s->conncheck_list; j ; j = j->next) {
+      CandidateCheckPair *p = j->data;
+
+      if (p->stun_transactions)
+        count += g_slist_length (p->stun_transactions);
+    }
+  }
+  return count;
+}
+
 /*
  * Create a new STUN transaction and add it to the list
  * of ongoing stun transactions of a pair.
index 7b11743..50fa0b1 100644 (file)
@@ -124,6 +124,7 @@ void conn_check_update_selected_pair (NiceAgent *agent,
 void conn_check_update_check_list_state_for_ready (NiceAgent *agent,
     NiceStream *stream, NiceComponent *component);
 void conn_check_unfreeze_related (NiceAgent *agent, CandidateCheckPair *pair);
+guint conn_check_stun_transactions_count (NiceAgent *agent);
 
 
 #endif /*_NICE_CONNCHECK_H */