discovery: Don't start STUN/TURN disco on errorneous socket
authorJakub Adam <jakub.adam@collabora.com>
Tue, 16 Jul 2019 09:55:32 +0000 (11:55 +0200)
committerOlivier CrĂȘte <olivier.crete@ocrete.ca>
Mon, 22 Jul 2019 17:22:46 +0000 (17:22 +0000)
If the initial attempt at sending discovery message returns a socket
error, don't start the retransmit timer and immediately mark such
discovery item as done. This is to quickly eliminate clearly
non-functioning items from the discovery process.

Particularly improves times to finish discovery on Windows, where
sending data from a link-local (169.254.0.0/16) IP to a destination not
on the same subnet leads to "A socket operation was attempted to an
unreachable network" error. Pointless retransmissions on those sockets
prolonged discovery in the order of seconds.

agent/discovery.c

index d8c4e9d..e16c76f 100644 (file)
@@ -1160,7 +1160,10 @@ static gboolean priv_discovery_tick_unlocked (NiceAgent *agent)
               turn_compat);
         }
 
-       if (buffer_len > 0) {
+        if (buffer_len > 0 &&
+            agent_socket_send (cand->nicesock, &cand->server, buffer_len,
+                (gchar *)cand->stun_buffer) >= 0) {
+          /* case: success, start waiting for the result */
           if (nice_socket_is_reliable (cand->nicesock)) {
             stun_timer_start_reliable (&cand->timer, agent->stun_reliable_timeout);
           } else {
@@ -1169,20 +1172,16 @@ static gboolean priv_discovery_tick_unlocked (NiceAgent *agent)
                 agent->stun_max_retransmissions);
           }
 
-          /* send the conncheck */
-          agent_socket_send (cand->nicesock, &cand->server,
-              buffer_len, (gchar *)cand->stun_buffer);
-
-         /* case: success, start waiting for the result */
-         g_get_current_time (&cand->next_tick);
-
-       } else {
-         /* case: error in starting discovery, start the next discovery */
-         cand->done = TRUE;
-         cand->stun_message.buffer = NULL;
-         cand->stun_message.buffer_len = 0;
-         continue;
-       }
+          g_get_current_time (&cand->next_tick);
+        } else {
+          /* case: error in starting discovery, start the next discovery */
+          nice_debug ("Agent %p : Error starting discovery, skipping the item.",
+              agent);
+          cand->done = TRUE;
+          cand->stun_message.buffer = NULL;
+          cand->stun_message.buffer_len = 0;
+          continue;
+        }
       }
       else
        /* allocate relayed candidates */