-fix assertion failure
[oweals/gnunet.git] / src / transport / gnunet-service-transport_neighbours.c
index e478090c3f7730758385d8b32e721c57f9959732..47e2713870609e97b384ba20ac990aae32df1f7f 100644 (file)
@@ -847,10 +847,11 @@ set_address (struct NeighbourAddress *na,
  * Free a neighbour map entry.
  *
  * @param n entry to free
- * @param terminate tell plugin to terminate sessions
+ * @param keep_sessions GNUNET_NO to tell plugin to terminate sessions,
+ *                      GNUNET_YES to keep all sessions
  */
 static void
-free_neighbour (struct NeighbourMapEntry *n, int terminate)
+free_neighbour (struct NeighbourMapEntry *n, int keep_sessions)
 {
   struct MessageQueue *mq;
   struct GNUNET_TRANSPORT_PluginFunctions *papi;
@@ -885,7 +886,7 @@ free_neighbour (struct NeighbourMapEntry *n, int terminate)
      API gives us not even the means to selectively kill only one of
      them! Killing all sessions like this seems to be very, very
      wrong. */
-  if ((GNUNET_YES == terminate) &&
+  if ((GNUNET_NO == keep_sessions) &&
       (NULL != n->primary_address.address) &&
       (NULL != (papi = GST_plugins_find (n->primary_address.address->transport_name))))
     papi->disconnect (papi->cls, &n->id);
@@ -985,7 +986,8 @@ send_disconnect_cont (void *cls, const struct GNUNET_PeerIdentity *target,
   if (S_DISCONNECT != n->state)
     return; /* have created a fresh entry since */
   n->state = S_DISCONNECT;
-  GNUNET_SCHEDULER_cancel (n->task);
+  if (GNUNET_SCHEDULER_NO_TASK != n->task)
+    GNUNET_SCHEDULER_cancel (n->task);
   n->task = GNUNET_SCHEDULER_add_now (&master_task, n);
 }
 
@@ -1132,7 +1134,8 @@ transmit_send_continuation (void *cls,
     /* this is still "our" neighbour, remove us from its queue
        and allow it to send the next message now */
     n->is_active = NULL;
-    GNUNET_SCHEDULER_cancel (n->task);
+    if (GNUNET_SCHEDULER_NO_TASK != n->task)
+      GNUNET_SCHEDULER_cancel (n->task);
     n->task = GNUNET_SCHEDULER_add_now (&master_task, n);    
   }
   GNUNET_assert (bytes_in_send_queue >= mq->message_buf_size);
@@ -1486,7 +1489,8 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg,
   if ( (NULL != n->is_active) ||
        ( (NULL == n->primary_address.session) && (NULL == n->primary_address.address)) )
     return;
-  GNUNET_SCHEDULER_cancel (n->task);
+  if (GNUNET_SCHEDULER_NO_TASK != n->task)
+    GNUNET_SCHEDULER_cancel (n->task);
   n->task = GNUNET_SCHEDULER_add_now (&master_task, n);
 }
 
@@ -2198,7 +2202,7 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
     /* ATS asks us to switch a life connection; see if we can get
        a CONNECT_ACK on it before we actually do this! */
     set_address (&n->alternative_address,
-                address, session, bandwidth_in, bandwidth_out, GNUNET_YES);
+                address, session, bandwidth_in, bandwidth_out, GNUNET_NO);
     n->state = S_CONNECTED_SWITCHING_BLACKLIST;
     check_blacklist (&n->id,
                     GNUNET_TIME_absolute_get (),
@@ -2244,7 +2248,7 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
     }
     /* ATS asks us to switch a life connection, update blacklist check */
     set_address (&n->alternative_address,
-                address, session, bandwidth_in, bandwidth_out, GNUNET_YES);
+                address, session, bandwidth_in, bandwidth_out, GNUNET_NO);
     check_blacklist (&n->id,
                     GNUNET_TIME_absolute_get (),
                     address, session, ats, ats_count);
@@ -2259,7 +2263,7 @@ GST_neighbours_switch_to_address (const struct GNUNET_PeerIdentity *peer,
     }
     /* ATS asks us to switch a life connection, update blacklist check */
     set_address (&n->alternative_address,
-                address, session, bandwidth_in, bandwidth_out, GNUNET_YES);
+                address, session, bandwidth_in, bandwidth_out, GNUNET_NO);
     n->state = S_CONNECTED_SWITCHING_BLACKLIST;
     check_blacklist (&n->id,
                     GNUNET_TIME_absolute_get (),
@@ -2452,10 +2456,10 @@ master_task (void *cls,
   }
   delay = GNUNET_TIME_relative_min (GNUNET_TIME_absolute_get_remaining (n->keep_alive_time),
                                    delay);
-  GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == n->task);
-  n->task = GNUNET_SCHEDULER_add_delayed (delay,
-                                         &master_task,
-                                         n);
+  if (GNUNET_SCHEDULER_NO_TASK == n->task)
+    n->task = GNUNET_SCHEDULER_add_delayed (delay,
+                                           &master_task,
+                                           n);
 }
 
 
@@ -2587,7 +2591,7 @@ GST_neighbours_handle_connect_ack (const struct GNUNET_MessageHeader *message,
     /* new address worked; adopt it and go back to connected! */
     n->state = S_CONNECTED;
     n->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
-    GNUNET_assert (GNUNET_NO == n->alternative_address.ats_active);
+    GNUNET_break (GNUNET_NO == n->alternative_address.ats_active);
     set_address (&n->primary_address,
                 n->alternative_address.address,
                 n->alternative_address.session,