File libnice-0.1.13-20160715.patch of Package libnice

commit 58fdd9b5f7e04e5f77bbc50ba2ac24f592a10b84
Author: Fabrice Bellet <fabrice@bellet.info>
Date:   Tue Apr 12 13:20:38 2016 +0200

    conncheck: invoke the debug dump in more places
    
    Differential Revision: https://phabricator.freedesktop.org/D1123

commit d63e323bb29ccd002d275d93c64a369a1bf34644
Author: Fabrice Bellet <fabrice@bellet.info>
Date:   Tue Jun 14 20:44:55 2016 +0200

    conncheck: fix pair socket assignment
    
    This patch fixes a problem when a new pair having a peer-reflexive new
    remote candidate is added while the transport type is udp. In this case
    the new pair socket really should be the socket of the local candidate,
    and not the remote (for example, the local candidate may be of relayed
    type).
    
    Differential Revision: https://phabricator.freedesktop.org/D1122

commit 2ba23c1fc10fa82ebf0f3ae83760a50c68c907d5
Author: Fabrice Bellet <fabrice@bellet.info>
Date:   Tue Jun 21 21:32:11 2016 +0200

    conncheck: fix tick counter used for debug stats
    
    The tick counter variable used to display pairs statistics should be
    per stream defined, to avoid side effects of a global variable, for
    example always having an odd or even tick counter value when the agent
    contains just two streams.
    
    Differential Revision: https://phabricator.freedesktop.org/D1113

commit 382f3eceac7ea764603648885fc236d4d508fd3a
Author: Fabrice Bellet <fabrice@bellet.info>
Date:   Tue Jun 21 21:36:28 2016 +0200

    agent: remove unused agent property
    
    Differential Revision: https://phabricator.freedesktop.org/D1112

commit 7e2eb6ad2402eee80fd4adc8b62b9d0f15905e7d
Author: Fabrice Bellet <fabrice@bellet.info>
Date:   Tue Jun 21 23:58:20 2016 +0200

    test-turn: wait for gathering done sequentially
    
    Fixes a bug in the logic of the wait loop, where only a single
    gathering done was required to exit the loop, the other was caught
    by the following assert.
    
    Differential Revision: https://phabricator.freedesktop.org/D1110

commit ea3d7e0de9568a4ec54a05e102ba4880cb825792
Author: Olivier Crête <olivier.crete@collabora.com>
Date:   Tue Jun 21 16:41:50 2016 -0400

    agent: Don't ask upnp to remove not yet allocated candidates
    
    This caused a warning in Farstream tests.

commit 6be20ef460de4235b56ad94874e9f432aa320a30
Author: Jakub Adam <jakub.adam@ktknet.cz>
Date:   Tue Jun 21 08:43:49 2016 +0000

    agent: read from the correct TCP-TURN socket
    
    fileno of UDP-TURN NiceSocket is NULL since 0a6c779f and so we need
    different means to identify the topmost socket.
    
    Differential Revision: https://phabricator.freedesktop.org/D1100

commit c7c521b7bf2c4ca0ab543f8da35d714ac63a14b0
Author: Fabrice Bellet <fabrice@bellet.info>
Date:   Tue Jun 14 20:34:52 2016 +0200

    conncheck: dump timer status in the stream check list
    
    Instead of printing the static pair priority values, it provides more
    information to dump each pair timer state, next timeout, and
    retranmission count, when debugging the whole connchecks list
    content.

commit ea946220cbcde19300a2f6647fdecf70fc6d3d82
Author: Fabrice Bellet <fabrice@bellet.info>
Date:   Tue Apr 19 20:46:34 2016 +0200

    conncheck: use strncmp instead of strcmp
    
    Differential Revision: https://phabricator.freedesktop.org/D931

commit 243610bc10bb3a31c0f3ba08fc6b46a4f897f7d9
Author: Fabrice Bellet <fabrice@bellet.info>
Date:   Thu Jun 16 20:51:19 2016 +0200

    tests: fix io-stream when built with optimizations
    
    In construct like "while (foo);" when foo is modified outside of the
    current thread, the variable should be declared volatile to suggest the
    compiler to read its value without making code optimization.

commit 7ea00f610185ebb55f49fe2b32677a0d279f2530
Author: Fabrice Bellet <fabrice@bellet.info>
Date:   Mon Feb 8 20:20:06 2016 +0100

    stun: avoid expensive call to sprintf in debug-related code

commit 8f74fa48670a927531fa362366c7ee66406e40d1
Author: Fabrice Bellet <fabrice@bellet.info>
Date:   Tue Jun 7 10:52:02 2016 +0200

    agent: rework gathering failures on auto-generated IPs
    
    This patch reworks commit fc4d3aa "ignore gathering failures on
    auto-generated IPs", that introduces a regression in the test-fullmode
    check, when turn is on and use_loopback is off. The part of the test
    that fails is when nice_agent_gather_candidates (ragent...) should
    return false when the port range for the second component is already
    busy, line 385.
    
    In this case, agent->local_address is null, so the code path added by
    commit fc4d3aa is taken, and the function will return true, even when
    not local address has been gathered.
    
    The proper fix is to swap the inner and outer loops (on components, and
    on local addresses), and to go to error when all local addresses of a
    given component have failed, and to return false only in this case.

commit 8b1fa8467fc6e6113ab08bb4edc233e597544728
Author: Fabrice Bellet <fabrice@bellet.info>
Date:   Mon Jun 6 22:35:36 2016 +0200

    conncheck: state is connected when a pair is nominated
    
    This patch fixes is bug introduced in commit 1ab9d7c "conncheck:
    Separate valid and succeded states", with the introduction of the valid
    flag. The agent really should go to connected state when we have a
    nominated pair, and not just a valid one.

commit de17deeda1ebfc27ca9a8ced93832a010329ff99
Author: Fabrice Bellet <fabrice@bellet.info>
Date:   Thu Jun 16 20:58:41 2016 +0200

    test-send-recv: reduce deadlock timeout

commit 328d081db0370c6e8dc72a57d899d26d08c46f88
Author: Fabrice Bellet <fabrice@bellet.info>
Date:   Fri Jun 17 00:31:48 2016 +0200

    pseudotcp-fuzzy: fix this test
    
    The header size should be 24 bytes only, if we don't want to fuzz the
    payload too.  Moreover, the default lambda parameter is decreased to
    one, to not fuzz the header too heavily, and consequently increase too
    much the time for the test to complete, due to exponential
    retransmission timeout when packets are corrupted.

commit 6b106b7a4a5451ecae953add1f29636d4ec03e50
Author: Fabrice Bellet <fabrice@bellet.info>
Date:   Fri Jun 17 00:28:16 2016 +0200

    pseudotcp: accept several FIN segments
    
    This modification allows to gracefully recover from a first
    corrupted FIN segment.

commit 24eb9cbb30f0d77dba31e9a54b971678700f0ef2
Author: Fabrice Bellet <fabrice@bellet.info>
Date:   Tue Apr 19 20:41:27 2016 +0200

    build: fix build in alternate builddir
    
    Differential Revision: https://phabricator.freedesktop.org/D930
diff --git a/Makefile.am b/Makefile.am
index 896c751..7466ac4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -47,6 +47,7 @@ dist_check_SCRIPTS = \
 # but not Linux, for no particular reason. They can’t be removed without
 # breaking ABI. FIXME: Remove them when we next break ABI.
 win32/vs9/libnice.def: nice/libnice.sym
+	$(MKDIR_P) $(dir $@)
 	$(AM_V_GEN)(echo "LIBRARY libnice"; \
 	            echo ""; \
 	            echo "EXPORTS"; \
diff --git a/agent/agent-priv.h b/agent/agent-priv.h
index d66a9ef..4d8c9b8 100644
--- a/agent/agent-priv.h
+++ b/agent/agent-priv.h
@@ -119,7 +119,6 @@ struct _NiceAgent
   GObject parent;                 /* gobject pointer */
 
   gboolean full_mode;             /* property: full-mode */
-  GTimeVal next_check_tv;         /* property: next conncheck timestamp */
   gchar *stun_server_ip;          /* property: STUN server IP */
   guint stun_server_port;         /* property: STUN server port */
   gchar *proxy_ip;                /* property: Proxy server IP */
diff --git a/agent/agent.c b/agent/agent.c
index f6c7a36..d819d27 100644
--- a/agent/agent.c
+++ b/agent/agent.c
@@ -2742,29 +2742,30 @@ nice_agent_gather_candidates (
     }
   }
 
-  /* generate a local host candidate for each local address */
-  for (i = local_addresses; i; i = i->next) {
-    NiceAddress *addr = i->data;
-    NiceCandidate *host_candidate;
+  for (cid = 1; cid <= stream->n_components; cid++) {
+    NiceComponent *component = nice_stream_find_component_by_id (stream, cid);
+    gboolean found_local_address = FALSE;
+    enum {
+      ADD_HOST_MIN = 0,
+      ADD_HOST_UDP = ADD_HOST_MIN,
+      ADD_HOST_TCP_ACTIVE,
+      ADD_HOST_TCP_PASSIVE,
+      ADD_HOST_MAX = ADD_HOST_TCP_PASSIVE
+    } add_type;
+
+    if (component == NULL)
+      continue;
+
+    /* generate a local host candidate for each local address */
+    for (i = local_addresses; i; i = i->next) {
+      NiceAddress *addr = i->data;
+      NiceCandidate *host_candidate;
 
 #ifdef HAVE_GUPNP
-    gchar local_ip[NICE_ADDRESS_STRING_LEN];
-    nice_address_to_string (addr, local_ip);
+      gchar local_ip[NICE_ADDRESS_STRING_LEN];
+      nice_address_to_string (addr, local_ip);
 #endif
 
-    for (cid = 1; cid <= stream->n_components; cid++) {
-      NiceComponent *component = nice_stream_find_component_by_id (stream, cid);
-      enum {
-        ADD_HOST_MIN = 0,
-        ADD_HOST_UDP = ADD_HOST_MIN,
-        ADD_HOST_TCP_ACTIVE,
-        ADD_HOST_TCP_PASSIVE,
-        ADD_HOST_MAX = ADD_HOST_TCP_PASSIVE
-      } add_type;
-
-      if (component == NULL)
-        continue;
-
       for (add_type = ADD_HOST_MIN; add_type <= ADD_HOST_MAX; add_type++) {
         NiceCandidateTransport transport;
         guint current_port;
@@ -2814,8 +2815,7 @@ nice_agent_gather_candidates (
         } else if (res == HOST_CANDIDATE_FAILED) {
           nice_debug ("Agent %p: Could ot retrieive component %d/%d", agent,
               stream->id, cid);
-          ret = FALSE;
-          goto error;
+          continue;
         } else if (res == HOST_CANDIDATE_CANT_CREATE_SOCKET) {
           if (nice_debug_is_enabled ()) {
             gchar ip[NICE_ADDRESS_STRING_LEN];
@@ -2824,14 +2824,10 @@ nice_agent_gather_candidates (
                 " s%d:%d. Invalid interface?", agent, ip, stream->id,
                 component->id);
           }
-          if (agent->local_addresses == NULL) {
-            /* Ignore when an auto-generated address fails. */
-            continue;
-          }
-          ret = FALSE;
-          goto error;
+          continue;
         }
 
+        found_local_address = TRUE;
         nice_address_set_port (addr, 0);
 
 
@@ -2888,6 +2884,13 @@ nice_agent_gather_candidates (
         }
       }
     }
+    /* Go to error if we could not find a local address for a given
+     * component
+     */
+    if (!found_local_address) {
+      ret = FALSE;
+      goto error;
+    }
   }
 
   stream->gathering = TRUE;
@@ -2962,6 +2965,9 @@ void agent_remove_local_candidate (NiceAgent *agent, NiceCandidate *candidate)
   if (candidate->type != NICE_CANDIDATE_TYPE_HOST)
     return;
 
+  if (nice_address_get_port (&candidate->addr) == 0)
+    return;
+
   nice_address_to_string (&candidate->addr, local_ip);
 
   gupnp_simple_igd_remove_port_local (GUPNP_SIMPLE_IGD (agent->upnp), "UDP",
@@ -3445,7 +3451,7 @@ agent_recv_message_unlocked (
         if (cand->type == NICE_CANDIDATE_TYPE_RELAYED &&
             cand->stream_id == stream->id &&
             cand->component_id == component->id &&
-            ((NiceSocket *)cand->sockptr)->fileno == nicesock->fileno) {
+            nice_socket_is_based_on(cand->sockptr, nicesock)) {
           nice_debug ("Agent %p : Packet received from a TURN socket.",
               agent);
           nicesock = cand->sockptr;
diff --git a/agent/conncheck.c b/agent/conncheck.c
index 7e03985..e913153 100644
--- a/agent/conncheck.c
+++ b/agent/conncheck.c
@@ -145,31 +145,22 @@ priv_print_conn_check_lists (NiceAgent *agent, const gchar *where, const gchar *
       for (k = stream->conncheck_list; k ; k = k->next) {
         CandidateCheckPair *pair = k->data;
         if (pair->component_id == j) {
-          gchar priority[PRIORITY_LEN];
-          guint p1, p2, p3;
           gchar local_addr[INET6_ADDRSTRLEN];
           gchar remote_addr[INET6_ADDRSTRLEN];
-
-          p1 = (pair->priority >> 32);
-          p2 = (pair->priority >> 1) & 0x7fffffff;
-          p3 = (pair->priority & 1);
-
-          g_snprintf (priority, PRIORITY_LEN,
-            "%02x:%04x:%02x:%02x:%04x:%02x:%1x",
-            (p1 >> 24) & 0x7f, (p1 >> 8) & 0xffff, (p1 & 0xff),
-            (p2 >> 24) & 0x7f, (p2 >> 8) & 0xffff, (p2 & 0xff),
-            p3);
+          StunTimer *timer = &pair->timer;
 
           nice_address_to_string (&pair->local->addr, local_addr);
           nice_address_to_string (&pair->remote->addr, remote_addr);
 
           nice_debug ("Agent %p : *** sc=%d/%d : pair %p : "
-              "f=%s t=%s:%s p=%s [%s]:%u > [%s]:%u state=%c%s%s%s",
+              "f=%s t=%s:%s timer=%d/%d %d/%dms "
+              "[%s]:%u > [%s]:%u state=%c%s%s%s",
               agent, pair->stream_id, pair->component_id, pair,
               pair->foundation,
               priv_candidate_type_to_string (pair->local->type),
               priv_candidate_type_to_string (pair->remote->type),
-              priority,
+              timer->retransmissions, timer->max_retransmissions,
+              timer->delay - stun_timer_remainder (timer), timer->delay,
               local_addr, nice_address_get_port (&pair->local->addr),
               remote_addr, nice_address_get_port (&pair->remote->addr),
               priv_state_to_gchar (pair->state),
@@ -273,6 +264,8 @@ static gboolean priv_conn_check_unfreeze_next (NiceAgent *agent)
    *     priority)
    */
 
+  priv_print_conn_check_lists (agent, G_STRFUNC, NULL);
+
   for (i = agent->streams; i; i = i->next) {
     NiceStream *stream = i->data;
     guint64 max_frozen_priority = 0;
@@ -327,13 +320,16 @@ static void priv_conn_check_unfreeze_related (NiceAgent *agent, NiceStream *stre
   g_assert (stream);
   g_assert (stream->id == ok_check->stream_id);
 
+  priv_print_conn_check_lists (agent, G_STRFUNC, NULL);
+
   /* step: perform the step (1) of 'Updating Pair States' */
   for (i = stream->conncheck_list; i ; i = i->next) {
     CandidateCheckPair *p = i->data;
    
     if (p->stream_id == ok_check->stream_id) {
       if (p->state == NICE_CHECK_FROZEN &&
-	  strcmp (p->foundation, ok_check->foundation) == 0) {
+          strncmp (p->foundation, ok_check->foundation,
+              NICE_CANDIDATE_PAIR_MAX_FOUNDATION) == 0) {
 	nice_debug ("Agent %p : Unfreezing check %p (after successful check %p).", agent, p, ok_check);
 	p->state = NICE_CHECK_WAITING;
         nice_debug ("Agent %p : pair %p state WAITING", agent, p);
@@ -409,8 +405,6 @@ static gboolean priv_conn_check_tick_stream (NiceStream *stream, NiceAgent *agen
   guint frozen = 0, waiting = 0;
   GSList *i, *k;
 
-  priv_print_conn_check_lists (agent, G_STRFUNC, NULL);
-
   for (i = stream->conncheck_list; i ; i = i->next) {
     CandidateCheckPair *p = i->data;
 
@@ -432,6 +426,8 @@ static gboolean priv_conn_check_tick_stream (NiceStream *stream, NiceAgent *agen
                   tmpbuf1, nice_address_get_port (&p->local->addr),
                   tmpbuf2, nice_address_get_port (&p->remote->addr));
               candidate_check_pair_fail (stream, agent, p);
+              priv_print_conn_check_lists (agent, G_STRFUNC,
+                  ", retransmission failed");
 
               break;
             }
@@ -525,15 +521,12 @@ static gboolean priv_conn_check_tick_stream (NiceStream *stream, NiceAgent *agen
       }
     }
   }
-    {
-    static int tick_counter = 0;
-    if (tick_counter++ % 50 == 0 || keep_timer_going != TRUE)
-      nice_debug ("Agent %p : stream %u: timer tick #%u: %u frozen, %u in-progress, "
-          "%u waiting, %u succeeded, %u discovered, %u nominated, "
-          "%u waiting-for-nom, %u valid.", agent, stream->id,
-          tick_counter, frozen, s_inprogress, waiting, s_succeeded,
-          s_discovered, s_nominated, s_waiting_for_nomination, s_valid);
-  }
+  if (stream->tick_counter++ % 50 == 0)
+    nice_debug ("Agent %p : stream %u: timer tick #%u: %u frozen, %u in-progress, "
+        "%u waiting, %u succeeded, %u discovered, %u nominated, "
+        "%u waiting-for-nom, %u valid.", agent, stream->id,
+        stream->tick_counter, frozen, s_inprogress, waiting, s_succeeded,
+        s_discovered, s_nominated, s_waiting_for_nomination, s_valid);
 
   return keep_timer_going;
 
@@ -588,6 +581,8 @@ static gboolean priv_conn_check_tick_unlocked (NiceAgent *agent)
   pair = priv_get_pair_from_triggered_check_queue (agent);
 
   if (pair) {
+    priv_print_conn_check_lists (agent, G_STRFUNC,
+        ", got a pair from triggered check list");
     priv_conn_check_initiate (agent, pair);
     return TRUE;
   }
@@ -639,6 +634,9 @@ static gboolean priv_conn_check_tick_unlocked (NiceAgent *agent)
       }
     }
 
+    priv_print_conn_check_lists (agent, G_STRFUNC,
+        ", conncheck timer stopped");
+
     /* Stopping the timer so destroy the source.. this will allow
        the timer to be reset if we get a set_remote_candidates after this
        point */
@@ -1493,7 +1491,7 @@ static void priv_update_check_list_state_for_ready (NiceAgent *agent, NiceStream
     }
   }
 
-  if (valid > 0) {
+  if (nominated > 0) {
     /* Only go to READY if no checks are left in progress. If there are
      * any that are kept, then this function will be called again when the
      * conncheck tick timer finishes them all */
@@ -1602,7 +1600,11 @@ static CandidateCheckPair *priv_add_new_check_pair (NiceAgent *agent,
   pair->component_id = component->id;;
   pair->local = local;
   pair->remote = remote;
-  if (remote->type == NICE_CANDIDATE_TYPE_PEER_REFLEXIVE)
+  /* note: we use the remote sockptr only in the case
+   * of TCP transport
+   */
+  if (local->transport == NICE_CANDIDATE_TRANSPORT_TCP_PASSIVE &&
+      remote->type == NICE_CANDIDATE_TYPE_PEER_REFLEXIVE)
     pair->sockptr = (NiceSocket *) remote->sockptr;
   else
     pair->sockptr = (NiceSocket *) local->sockptr;
@@ -2697,6 +2699,8 @@ static gboolean priv_map_reply_to_conn_check_request (NiceAgent *agent, NiceStre
              Nominated Flag" (ID-19) */
           if (ok_pair->nominated == TRUE) {
             priv_update_selected_pair (agent, component, ok_pair);
+            priv_print_conn_check_lists (agent, G_STRFUNC,
+                ", got a nominated pair");
 
             /* Do not step down to CONNECTED if we're already at state READY*/
             if (component->state != NICE_COMPONENT_STATE_READY) {
@@ -2707,8 +2711,6 @@ static gboolean priv_map_reply_to_conn_check_request (NiceAgent *agent, NiceStre
             }
           }
 
-          priv_print_conn_check_lists (agent, G_STRFUNC, NULL);
-
           /* step: update pair states (ICE 7.1.2.2.3 "Updating pair
              states" and 8.1.2 "Updating States", ID-19) */
           priv_update_check_list_state_for_ready (agent, stream, component);
diff --git a/agent/pseudotcp.c b/agent/pseudotcp.c
index 3160c34..d57808e 100644
--- a/agent/pseudotcp.c
+++ b/agent/pseudotcp.c
@@ -1829,12 +1829,9 @@ process(PseudoTcpSocket *self, Segment *seg)
     /* @received_fin is set when, and only when, all segments preceding the FIN
      * have been acknowledged. This is to handle the case where the FIN arrives
      * out of order with a preceding data segment. */
-    if (seg->flags & FLAG_FIN && priv->rcv_fin == 0) {
+    if (seg->flags & FLAG_FIN) {
       priv->rcv_fin = seg->seq;
       DEBUG (PSEUDO_TCP_DEBUG_NORMAL, "Setting rcv_fin = %u", priv->rcv_fin);
-    } else if (seg->flags & FLAG_FIN && seg->seq != priv->rcv_fin) {
-      DEBUG (PSEUDO_TCP_DEBUG_NORMAL, "Second FIN segment received; ignored");
-      return FALSE;
     }
 
     /* For the moment, FIN segments must not contain data. */
diff --git a/agent/stream.h b/agent/stream.h
index e524f62..f9188cb 100644
--- a/agent/stream.h
+++ b/agent/stream.h
@@ -88,6 +88,7 @@ struct _NiceStream {
   gboolean gathering;
   gboolean gathering_started;
   gint tos;
+  guint tick_counter;
 };
 
 typedef struct {
diff --git a/stun/debug.c b/stun/debug.c
index 8efb576..9d3d59b 100644
--- a/stun/debug.c
+++ b/stun/debug.c
@@ -89,6 +89,9 @@ void stun_debug_bytes (const char *prefix, const void *data, size_t len)
   size_t i;
   size_t prefix_len = strlen (prefix);
   char *bytes;
+  char *j;
+  unsigned char k;
+  const char *hex = "0123456789abcdef";
 
   if (!debug_enabled)
     return;
@@ -98,9 +101,14 @@ void stun_debug_bytes (const char *prefix, const void *data, size_t len)
   strcpy (bytes, prefix);
   strcpy (bytes + prefix_len, "0x");
 
-  for (i = 0; i < len; i++)
-    sprintf (bytes + prefix_len + 2 + (i * 2), "%02x", ((const unsigned char *)data)[i]);
-
+  j = bytes + prefix_len + 2;
+  for (i = 0; i < len; i++) {
+    k = ((const unsigned char *)data)[i];
+    j[0] = hex[(k & 0xf0) >> 4];
+    j[1] = hex[k & 0xf];
+    j = j + 2;
+  }
+  j[0] = 0;
   stun_debug ("%s", bytes);
   free (bytes);
 }
diff --git a/tests/test-io-stream-common.c b/tests/test-io-stream-common.c
index efa6160..b34748d 100644
--- a/tests/test-io-stream-common.c
+++ b/tests/test-io-stream-common.c
@@ -500,7 +500,7 @@ run_io_stream_test (guint deadlock_timeout, gboolean reliable,
  * This must only be called from the read thread implementation. */
 void
 check_for_termination (TestIOStreamThreadData *data, gsize *recv_count,
-    gsize *other_recv_count, gsize *send_count, gsize expected_recv_count)
+    gsize *other_recv_count, volatile gsize *send_count, gsize expected_recv_count)
 {
   guint stream_id;
   gpointer tmp;
diff --git a/tests/test-io-stream-common.h b/tests/test-io-stream-common.h
index 8f7bac1..1e37954 100644
--- a/tests/test-io-stream-common.h
+++ b/tests/test-io-stream-common.h
@@ -102,6 +102,6 @@ void run_io_stream_test (guint deadlock_timeout, gboolean reliable,
     gpointer l_user_data, GDestroyNotify l_user_data_free,
     gpointer r_user_data, GDestroyNotify r_user_data_free);
 void check_for_termination (TestIOStreamThreadData *data, gsize *recv_count,
-    gsize *other_recv_count, gsize *send_count, gsize expected_recv_count);
+    gsize *other_recv_count, volatile gsize *send_count, gsize expected_recv_count);
 
 void stop_main_loop (GMainLoop *loop);
diff --git a/tests/test-pseudotcp-fuzzy.c b/tests/test-pseudotcp-fuzzy.c
index 4211248..4a714e6 100644
--- a/tests/test-pseudotcp-fuzzy.c
+++ b/tests/test-pseudotcp-fuzzy.c
@@ -98,7 +98,7 @@ guint32 right_stream_pos = 0;
 /* Configuration options. */
 gint64 seed = 0;
 guint32 fuzz_start_pos = 1;  /* bytes into stream payload; after the SYN-ACKs */
-guint n_changes_lambda = 2;  /* lambda parameter for a Poisson distribution
+guint n_changes_lambda = 1;  /* lambda parameter for a Poisson distribution
                               * controlling the number of mutations made to each
                               * packet */
 
@@ -270,7 +270,7 @@ fuzz_packet (guint8 *buf, guint32 len, guint32 stream_pos)
 {
   guint32 i;
   guint n_changes;
-#define TCP_HEADER_LENGTH 32 /* bytes; or thereabouts (include some options) */
+#define HEADER_LENGTH 24 /* bytes; or thereabouts (include some options) */
 
   /* Do we want to fuzz this packet? */
   if (stream_pos < fuzz_start_pos) {
@@ -285,7 +285,7 @@ fuzz_packet (guint8 *buf, guint32 len, guint32 stream_pos)
       n_changes, stream_pos);
 
   for (i = 0; i < n_changes; i++) {
-    guint32 pos = g_rand_int_range (prng, 0, MIN (len, TCP_HEADER_LENGTH));
+    guint32 pos = g_rand_int_range (prng, 0, MIN (len, HEADER_LENGTH));
     g_debug (" • Changing byte %u.", stream_pos + pos);
     buf[pos] = g_rand_int_range (prng, 0, G_MAXUINT8 + 1);
   }
diff --git a/tests/test-send-recv.c b/tests/test-send-recv.c
index 5841639..d853036 100644
--- a/tests/test-send-recv.c
+++ b/tests/test-send-recv.c
@@ -1138,7 +1138,7 @@ guint32 option_transmit_seed = 0;
 guint32 option_receive_seed = 0;
 gsize option_n_bytes = 10000;
 guint option_n_messages = 50;
-guint option_timeout = 1200;  /* seconds */
+guint option_timeout = 15;  /* seconds */
 gboolean option_long_mode = FALSE;
 
 static GOptionEntry entries[] = {
@@ -1151,7 +1151,7 @@ static GOptionEntry entries[] = {
   { "n-messages", 'm', 0, G_OPTION_ARG_INT64, &option_n_messages,
     "Number of messages to send in each test (default 50)", "M" },
   { "timeout", 't', 0, G_OPTION_ARG_INT, &option_timeout,
-    "Deadlock detection timeout length, in seconds (default: 1200)", "S" },
+    "Deadlock detection timeout length, in seconds (default: 15)", "S" },
   { "long-mode", 'l', 0, G_OPTION_ARG_NONE, &option_long_mode,
     "Enable all tests, rather than a fast subset", NULL },
   { NULL },
diff --git a/tests/test-turn.c b/tests/test-turn.c
index 46d1bf2..c466261 100644
--- a/tests/test-turn.c
+++ b/tests/test-turn.c
@@ -224,9 +224,11 @@ run_test(guint turn_port, gboolean is_ipv6,
   g_assert (global_lagent_gathering_done == FALSE);
   g_assert (global_ragent_gathering_done == FALSE);
   g_debug ("test-turn: Added streams, running context until 'candidate-gathering-done'...");
-  while (!global_lagent_gathering_done && !global_ragent_gathering_done)
+  while (!global_lagent_gathering_done)
     g_main_context_iteration (NULL, TRUE);
   g_assert (global_lagent_gathering_done == TRUE);
+  while (!global_ragent_gathering_done)
+    g_main_context_iteration (NULL, TRUE);
   g_assert (global_ragent_gathering_done == TRUE);
 
   set_credentials (lagent, ls_id, ragent, rs_id);