adding Ludo's gnunet-download-manager.scm back to SVN HEAD
[oweals/gnunet.git] / src / core / core_api.c
index 0de64869b1953d35c9aa0f933220b0f05f422056..66df134fb1acaf7c5ace5f77f1f02c79a954bf14 100644 (file)
@@ -421,7 +421,7 @@ disconnect_and_free_peer_entry (void *cls, const GNUNET_HashCode * key,
                  GNUNET_CONTAINER_multihashmap_remove (h->peers, key, pr));
   GNUNET_assert (pr->pending_head == NULL);
   GNUNET_assert (pr->pending_tail == NULL);
-  GNUNET_assert (pr->ch = h);
+  GNUNET_assert (pr->ch == h);
   GNUNET_assert (pr->queue_size == 0);
   GNUNET_assert (pr->timeout_task == GNUNET_SCHEDULER_NO_TASK);
   GNUNET_assert (pr->ntr_task == GNUNET_SCHEDULER_NO_TASK);
@@ -781,6 +781,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
   const struct GNUNET_MessageHeader *em;
   const struct SendMessageReady *smr;
   const struct GNUNET_CORE_MessageHandler *mh;
+  const struct GNUNET_ATS_Information *ats;
   GNUNET_CORE_StartupCallback init;
   struct PeerRecord *pr;
   struct GNUNET_CORE_TransmitHandle *th;
@@ -851,7 +852,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
                                                       &h->me.hashPubKey, pr,
                                                       GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
     if (NULL != h->connects)
-      h->connects (h->cls, &h->me, NULL);
+      h->connects (h->cls, &h->me, NULL, 0);
     break;
   case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT:
     if (msize < sizeof (struct ConnectNotifyMessage))
@@ -862,11 +863,9 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
     }
     cnm = (const struct ConnectNotifyMessage *) msg;
     ats_count = ntohl (cnm->ats_count);
-    if ((msize !=
-         sizeof (struct ConnectNotifyMessage) +
-         ats_count * sizeof (struct GNUNET_ATS_Information)) ||
-        (GNUNET_ATS_ARRAY_TERMINATOR !=
-         ntohl ((&cnm->ats)[ats_count].type)))
+    if (msize !=
+        sizeof (struct ConnectNotifyMessage) +
+        ats_count * sizeof (struct GNUNET_ATS_Information))
     {
       GNUNET_break (0);
       reconnect_later (h);
@@ -897,8 +896,9 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
                    GNUNET_CONTAINER_multihashmap_put (h->peers,
                                                       &cnm->peer.hashPubKey, pr,
                                                       GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST));
+    ats = (const struct GNUNET_ATS_Information *) &cnm[1];
     if (NULL != h->connects)
-      h->connects (h->cls, &cnm->peer, &cnm->ats);
+      h->connects (h->cls, &cnm->peer, ats, ats_count);
     break;
   case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_DISCONNECT:
     if (msize != sizeof (struct DisconnectNotifyMessage))
@@ -947,8 +947,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
          sizeof (struct NotifyTrafficMessage) +
          ats_count * sizeof (struct GNUNET_ATS_Information) +
          sizeof (struct GNUNET_MessageHeader)) ||
-        (GNUNET_ATS_ARRAY_TERMINATOR !=
-         ntohl ((&ntm->ats)[ats_count].type)))
+        (GNUNET_ATS_ARRAY_TERMINATOR != ntohl ((&ntm->ats)[ats_count].type)))
     {
       GNUNET_break (0);
       reconnect_later (h);
@@ -984,18 +983,22 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
         continue;
       if ((mh->expected_size != ntohs (em->size)) && (mh->expected_size != 0))
       {
-        GNUNET_break (0);
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                    "Unexpected message size %u for message of type %u from peer `%4s'\n",
+                    htons (em->size), mh->type, GNUNET_i2s (&ntm->peer));
+        GNUNET_break_op (0);
         continue;
       }
       if (GNUNET_OK !=
-          h->handlers[hpos].callback (h->cls, &ntm->peer, em, &ntm->ats))
+          h->handlers[hpos].callback (h->cls, &ntm->peer, em, &ntm->ats,
+                                      ats_count))
       {
         /* error in processing, do not process other messages! */
         break;
       }
     }
     if (NULL != h->inbound_notify)
-      h->inbound_notify (h->cls, &ntm->peer, em, &ntm->ats);
+      h->inbound_notify (h->cls, &ntm->peer, em, &ntm->ats, ats_count);
     break;
   case GNUNET_MESSAGE_TYPE_CORE_NOTIFY_OUTBOUND:
     if (msize < sizeof (struct NotifyTrafficMessage))
@@ -1016,8 +1019,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
          sizeof (struct NotifyTrafficMessage) +
          ats_count * sizeof (struct GNUNET_ATS_Information) +
          sizeof (struct GNUNET_MessageHeader)) ||
-        (GNUNET_ATS_ARRAY_TERMINATOR !=
-         ntohl ((&ntm->ats)[ats_count].type)))
+        (GNUNET_ATS_ARRAY_TERMINATOR != ntohl ((&ntm->ats)[ats_count].type)))
     {
       GNUNET_break (0);
       reconnect_later (h);
@@ -1050,7 +1052,7 @@ main_notify_handler (void *cls, const struct GNUNET_MessageHeader *msg)
       GNUNET_break (0);
       break;
     }
-    h->outbound_notify (h->cls, &ntm->peer, em, &ntm->ats);
+    h->outbound_notify (h->cls, &ntm->peer, em, &ntm->ats, ats_count);
     break;
   case GNUNET_MESSAGE_TYPE_CORE_SEND_READY:
     if (msize != sizeof (struct SendMessageReady))
@@ -1168,7 +1170,7 @@ reconnect (struct GNUNET_CORE_Handle *h)
   init = (struct InitMessage *) &cm[1];
   init->header.type = htons (GNUNET_MESSAGE_TYPE_CORE_INIT);
   init->header.size = htons (msize);
-  opt = GNUNET_CORE_OPTION_SEND_CONNECT | GNUNET_CORE_OPTION_SEND_DISCONNECT;
+  opt = 0;
   if (h->inbound_notify != NULL)
   {
     if (h->inbound_hdr_only)
@@ -1421,15 +1423,12 @@ GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle, int cork,
     GNUNET_free (minp);
   }
 
-  /* Order entries by deadline, but SKIP 'HEAD' if
-   * we're in the 'ready_peer_*' DLL */
+  /* Order entries by deadline, but SKIP 'HEAD' (as we may have transmitted
+   * that request already or might even already be approved to transmit that
+   * message to core) */
   pos = pr->pending_head;
-  if ((pr->prev != NULL) || (pr->next != NULL) ||
-      (pr == handle->ready_peer_head))
-  {
-    GNUNET_assert (pos != NULL);
+  if (pos != NULL)
     pos = pos->next;            /* skip head */
-  }
 
   /* insertion sort */
   prev = pos;