fix
[oweals/gnunet.git] / src / core / core_api.c
index e9a38271bf317cce14072f629e842e521ca4fa6d..30b7eb5405ee7ce427e22f74905be57afdfbd87f 100644 (file)
@@ -346,6 +346,11 @@ struct GNUNET_CORE_TransmitHandle
    */
   uint16_t smr_id;
 
+  /**
+   * Is corking allowed?
+   */
+  int cork;
+
 };
 
 
@@ -417,7 +422,9 @@ disconnect_and_free_peer_entry (void *cls,
       pcic (pr->pcic_cls,
            &pr->peer,
            zero,
-           0, 0);
+           0, 
+           GNUNET_TIME_UNIT_FOREVER_REL,
+           0);
     }
   if (pr->timeout_task != GNUNET_SCHEDULER_NO_TASK)
     {
@@ -707,6 +714,8 @@ transmit_message (void *cls,
       sm->priority = htonl (th->priority);
       sm->deadline = GNUNET_TIME_absolute_hton (th->timeout);
       sm->peer = pr->peer;
+      sm->cork = htonl ((uint32_t) th->cork);
+      sm->reserved = htonl (0);
       ret = th->get_message (th->get_message_cls,
                             size - sizeof (struct SendMessage),
                             &sm[1]);
@@ -1245,6 +1254,7 @@ main_notify_handler (void *cls,
              &pr->peer,
              cim->bw_out,
              ntohl (cim->reserved_amount),
+             GNUNET_TIME_relative_ntoh (cim->reserve_delay),
              GNUNET_ntohll (cim->preference));
       break;
     default:
@@ -1483,6 +1493,7 @@ GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle)
  * established (and the client has been informed about this).
  *
  * @param handle connection to core service
+ * @param cork is corking allowed for this transmission?
  * @param priority how important is the message?
  * @param maxdelay how long can the message wait?
  * @param target who should receive the message,
@@ -1496,6 +1507,7 @@ GNUNET_CORE_disconnect (struct GNUNET_CORE_Handle *handle)
  */
 struct GNUNET_CORE_TransmitHandle *
 GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle,
+                                  int cork,
                                    uint32_t priority,
                                    struct GNUNET_TIME_Relative maxdelay,
                                    const struct GNUNET_PeerIdentity *target,
@@ -1530,6 +1542,7 @@ GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle,
   th->timeout = GNUNET_TIME_relative_to_absolute (maxdelay);
   th->priority = priority;
   th->msize = notify_size;
+  th->cork = cork;
   /* bound queue size */
   if (pr->queue_size == handle->queue_size)
     {
@@ -1545,7 +1558,7 @@ GNUNET_CORE_notify_transmit_ready (struct GNUNET_CORE_Handle *handle,
       if (minp == NULL) 
        {
          GNUNET_break (handle->queue_size != 0);
-         GNUNET_break (pr->queue_size == 0);
+         GNUNET_break (pr->queue_size == 1);
          GNUNET_free(th);
          return NULL;
        }
@@ -1733,8 +1746,12 @@ GNUNET_CORE_peer_request_connect (struct GNUNET_CORE_Handle *h,
 
   if (NULL != GNUNET_CONTAINER_multihashmap_get (h->peers,
                                           &peer->hashPubKey))
-    return NULL; /* Already connected, means callback should have happened already! */
-
+    {
+#if DEBUG_CORE
+      GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Peers are already connected!\n");
+#endif
+      return NULL;
+    }
   
   cm = GNUNET_malloc (sizeof (struct ControlMessage) + 
                      sizeof (struct ConnectMessage));
@@ -1744,9 +1761,9 @@ GNUNET_CORE_peer_request_connect (struct GNUNET_CORE_Handle *h,
   msg->reserved = htonl (0);
   msg->timeout = GNUNET_TIME_relative_hton (timeout);
   msg->peer = *peer;
-  GNUNET_CONTAINER_DLL_insert (h->control_pending_head,
-                              h->control_pending_tail,
-                              cm);
+  GNUNET_CONTAINER_DLL_insert_tail (h->control_pending_head,
+                                   h->control_pending_tail,
+                                   cm);
   ret = GNUNET_malloc (sizeof (struct GNUNET_CORE_PeerRequestHandle));
   ret->h = h;
   ret->cm = cm;
@@ -1795,16 +1812,6 @@ struct GNUNET_CORE_InformationRequestContext
    */
   struct GNUNET_CORE_Handle *h;
 
-  /**
-   * Function to call with the information.
-   */
-  GNUNET_CORE_PeerConfigurationInfoCallback info;
-
-  /**
-   * Closure for info.
-   */
-  void *info_cls;
-
   /**
    * Link to control message, NULL if CM was sent.
    */ 
@@ -1889,8 +1896,6 @@ GNUNET_CORE_peer_change_preference (struct GNUNET_CORE_Handle *h,
   irc = GNUNET_malloc (sizeof (struct GNUNET_CORE_InformationRequestContext));
   irc->h = h;
   irc->pr = pr;
-  irc->info = info;
-  irc->info_cls = info_cls;
   cm = GNUNET_malloc (sizeof (struct ControlMessage) +
                      sizeof (struct RequestInfoMessage));
   cm->cont = &change_preference_send_continuation;
@@ -1908,9 +1913,9 @@ GNUNET_CORE_peer_change_preference (struct GNUNET_CORE_Handle *h,
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
              "Queueing CHANGE PREFERENCE request\n");
 #endif
-  GNUNET_CONTAINER_DLL_insert (h->control_pending_head,
-                              h->control_pending_tail,
-                              cm); 
+  GNUNET_CONTAINER_DLL_insert_tail (h->control_pending_head,
+                                   h->control_pending_tail,
+                                   cm); 
   pr->pcic = info;
   pr->pcic_cls = info_cls;
   if (h->control_pending_head == cm)