more error checks
authorChristian Grothoff <christian@grothoff.org>
Fri, 17 Jun 2011 15:39:23 +0000 (15:39 +0000)
committerChristian Grothoff <christian@grothoff.org>
Fri, 17 Jun 2011 15:39:23 +0000 (15:39 +0000)
src/core/core_api.c
src/core/gnunet-service-core.c
src/core/test_core_api_preferences.c

index 5b90a11ede28eb86d453d07f40b2c18d114f69c1..af46c6e63464b9fdef2a5a40651e07c1d826a59d 100644 (file)
@@ -417,17 +417,6 @@ disconnect_and_free_peer_entry (void *cls,
   GNUNET_CORE_PeerConfigurationInfoCallback pcic;
   void *pcic_cls;
 
-  if (NULL != (pcic = pr->pcic))
-    {
-      pcic_cls = pr->pcic_cls;
-      GNUNET_CORE_peer_change_preference_cancel (pr->pcic_ptr);
-      pcic (pcic_cls,
-           &pr->peer,
-           zero,
-           0, 
-           GNUNET_TIME_UNIT_FOREVER_REL,
-           0);
-    }
   if (pr->timeout_task != GNUNET_SCHEDULER_NO_TASK)
     {
       GNUNET_SCHEDULER_cancel (pr->timeout_task);
@@ -449,6 +438,18 @@ disconnect_and_free_peer_entry (void *cls,
                    &pr->peer);
   /* all requests should have been cancelled, clean up anyway, just in case */
   GNUNET_break (pr->queue_size == 0);
+  if (NULL != (pcic = pr->pcic))
+    {
+      GNUNET_break (0);
+      pcic_cls = pr->pcic_cls;
+      GNUNET_CORE_peer_change_preference_cancel (pr->pcic_ptr);
+      pcic (pcic_cls,
+           &pr->peer,
+           zero,
+           0, 
+           GNUNET_TIME_UNIT_FOREVER_REL,
+           0);
+    }
   while (NULL != (th = pr->pending_head))
     {
       GNUNET_break (0);
@@ -460,6 +461,7 @@ disconnect_and_free_peer_entry (void *cls,
        th->cm->th = NULL;
       GNUNET_free (th);
     }
+  /* done with 'voluntary' cleanups, now on to normal freeing */
   GNUNET_assert (GNUNET_YES ==
                 GNUNET_CONTAINER_multihashmap_remove (h->peers,
                                                       key,
@@ -1512,6 +1514,7 @@ GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle)
       handle->reconnect_task = GNUNET_SCHEDULER_NO_TASK;
     }
   GNUNET_CONTAINER_multihashmap_destroy (handle->peers);
+  handle->peers = NULL;
   GNUNET_break (handle->ready_peer_head == NULL);
   GNUNET_free (handle);
 }
@@ -1942,7 +1945,7 @@ GNUNET_CORE_peer_change_preference (struct GNUNET_CORE_Handle *h,
   if (NULL == pr)
     {
       /* attempt to change preference on peer that is not connected */
-      GNUNET_break (0);
+      GNUNET_assert (0);
       return NULL;
     }
   if (pr->pcic != NULL)
index 1b0a93d6a9363dc901862f4f67609e902e4b7bc1..7a444847c9a86d972698be73f026d787666f44bd 100644 (file)
@@ -3883,6 +3883,7 @@ send_p2p_message_to_client (struct Neighbour *sender,
   struct NotifyTrafficMessage *ntm;
   struct GNUNET_TRANSPORT_ATS_Information *ats;
 
+  GNUNET_assert (GNUNET_YES == sender->is_connected);
   if (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
     {
       GNUNET_break (0);
index b0b23776f935ef6d6c9d3c7720fd12a9a4fecd53..c725543b0f3d7165e51634240e64f9a57c6ef160 100644 (file)
@@ -66,6 +66,8 @@ static int ok;
 
 static struct GNUNET_CORE_InformationRequestContext *irc;
 
+static struct GNUNET_CORE_TransmitHandle *th;
+
 static GNUNET_SCHEDULER_TaskIdentifier irc_task;
 
 static GNUNET_SCHEDULER_TaskIdentifier ask_task;
@@ -99,9 +101,15 @@ terminate_task_error (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 #endif
   GNUNET_break (0);
   if (NULL != irc)
-    GNUNET_CORE_peer_change_preference_cancel (irc);
+    {
+      GNUNET_CORE_peer_change_preference_cancel (irc);
+      irc = NULL;
+    }
   if (GNUNET_SCHEDULER_NO_TASK != irc_task)
-    GNUNET_SCHEDULER_cancel (irc_task);
+    {
+      GNUNET_SCHEDULER_cancel (irc_task);
+      irc_task = GNUNET_SCHEDULER_NO_TASK;
+    }
   if (GNUNET_SCHEDULER_NO_TASK != ask_task)
     {
       GNUNET_SCHEDULER_cancel (ask_task);
@@ -121,6 +129,7 @@ transmit_ready (void *cls, size_t size, void *buf)
   struct PeerContext *p = cls;
   struct GNUNET_MessageHeader *m;
 
+  th = NULL;
   GNUNET_assert (ok == 4);
   OKPP;
   GNUNET_assert (p == &p1);
@@ -203,13 +212,13 @@ preference_cb (void *cls,
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Asking core (1) for transmission to peer `%4s'\n",
              GNUNET_i2s (&p2.id));
-  if (NULL == GNUNET_CORE_notify_transmit_ready (p1.ch,
-                                                GNUNET_YES,
-                                                0,
-                                                GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 45),
-                                                &p2.id,
-                                                sizeof (struct GNUNET_MessageHeader),
-                                                &transmit_ready, &p1))
+  if (NULL == (th = GNUNET_CORE_notify_transmit_ready (p1.ch,
+                                                      GNUNET_YES,
+                                                      0,
+                                                      GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 45),
+                                                      &p2.id,
+                                                      sizeof (struct GNUNET_MessageHeader),
+                                                      &transmit_ready, &p1)))
     {
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
                  "RECEIVED NULL when asking core (1) for transmission to peer `%4s'\n",
@@ -261,8 +270,27 @@ disconnect_notify (void *cls,
                   sizeof (struct GNUNET_PeerIdentity)))
     return;
   pc->connect_status = 0;
+  if (GNUNET_SCHEDULER_NO_TASK != irc_task)
+    {
+      GNUNET_SCHEDULER_cancel (irc_task);
+      irc_task = GNUNET_SCHEDULER_NO_TASK;
+    }
+  if (0 == memcmp (peer, &p1.id, sizeof (struct GNUNET_PeerIdentity)))
+    {
+      if (irc != NULL) 
+       {
+         GNUNET_CORE_peer_change_preference_cancel (irc);
+         irc = NULL;
+       }
+      if (th != NULL)
+       {
+         GNUNET_CORE_notify_transmit_ready_cancel (th);
+         th = NULL;
+       }
+    }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-              "Encrypted connection to `%4s' cut\n", GNUNET_i2s (peer));
+              "Encrypted connection to `%4s' cut\n", 
+             GNUNET_i2s (peer));
 }