- clean up gns rest api
[oweals/gnunet.git] / src / fs / gnunet-service-fs_pe.c
index 21f028a2dced3647d4f2e6f02811020a434771cf..d9b8f9576de4c3dba9ffc8ed186720c1090d9b19 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2011 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2011 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -54,10 +54,10 @@ struct PeerPlan;
  * a particular pending request.
  *
  * The corresponding head and tail of the "PE" MDLL
- * are stored in a 'struct GSF_RequestPlan'. (We need
+ * are stored in a `struct GSF_RequestPlan`. (We need
  * to be able to lookup all pending requests corresponding
  * to a given plan entry.)
- * 
+ *
  * Similarly head and tail of the "PR" MDLL are stored
  * with the 'struct GSF_PendingRequest'.  (We need
  * to be able to lookup all plan entries corresponding
@@ -196,14 +196,14 @@ struct PeerPlan
   /**
    * Current task for executing the plan.
    */
-  GNUNET_SCHEDULER_TaskIdentifier task;
+  struct GNUNET_SCHEDULER_Task * task;
 };
 
 
 /**
  * Hash map from peer identities to PeerPlans.
  */
-static struct GNUNET_CONTAINER_MultiHashMap *plans;
+static struct GNUNET_CONTAINER_MultiPeerMap *plans;
 
 /**
  * Sum of all transmission counters (equals total delay for all plan entries).
@@ -238,7 +238,7 @@ get_rp_key (struct GSF_RequestPlan *rp)
 /**
  * Figure out when and how to transmit to the given peer.
  *
- * @param cls the 'struct GSF_ConnectedPeer' for transmission
+ * @param cls the `struct GSF_ConnectedPeer` for transmission
  * @param tc scheduler context
  */
 static void
@@ -337,7 +337,7 @@ plan (struct PeerPlan *pp, struct GSF_RequestPlan *rp)
                  GNUNET_CONTAINER_multihashmap_contains_value (pp->plan_map,
                                                                get_rp_key (rp),
                                                                rp));
-  if (GNUNET_SCHEDULER_NO_TASK != pp->task)
+  if (NULL != pp->task)
     GNUNET_SCHEDULER_cancel (pp->task);
   pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp);
 #undef N
@@ -360,7 +360,7 @@ get_latest (const struct GSF_RequestPlan *rp)
   if (NULL == bi)
     return NULL; /* should never happen */
   ret = bi->pr;
-  bi = bi->next_PE; 
+  bi = bi->next_PE;
   while (NULL != bi)
   {
     if (GSF_pending_request_get_data_ (bi->pr)->ttl.abs_value_us >
@@ -376,7 +376,7 @@ get_latest (const struct GSF_RequestPlan *rp)
  * Function called to get a message for transmission.
  *
  * @param cls closure
- * @param buf_size number of bytes available in buf
+ * @param buf_size number of bytes available in @a buf
  * @param buf where to copy the message, NULL on error (peer disconnect)
  * @return number of bytes copied to 'buf', can be 0 (without indicating an error)
  */
@@ -391,7 +391,7 @@ transmit_message_callback (void *cls, size_t buf_size, void *buf)
   if (NULL == buf)
   {
     /* failed, try again... */
-    if (GNUNET_SCHEDULER_NO_TASK != pp->task)
+    if (NULL != pp->task)
       GNUNET_SCHEDULER_cancel (pp->task);
 
     pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp);
@@ -404,7 +404,7 @@ transmit_message_callback (void *cls, size_t buf_size, void *buf)
   rp = GNUNET_CONTAINER_heap_peek (pp->priority_heap);
   if (NULL == rp)
   {
-    if (GNUNET_SCHEDULER_NO_TASK != pp->task)
+    if (NULL != pp->task)
       GNUNET_SCHEDULER_cancel (pp->task);
     pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp);
     return 0;
@@ -412,7 +412,7 @@ transmit_message_callback (void *cls, size_t buf_size, void *buf)
   msize = GSF_pending_request_get_message_ (get_latest (rp), buf_size, buf);
   if (msize > buf_size)
   {
-    if (GNUNET_SCHEDULER_NO_TASK != pp->task)
+    if (NULL != pp->task)
       GNUNET_SCHEDULER_cancel (pp->task);
     /* buffer to small (message changed), try again */
     pp->task = GNUNET_SCHEDULER_add_now (&schedule_peer_transmission, pp);
@@ -439,7 +439,7 @@ transmit_message_callback (void *cls, size_t buf_size, void *buf)
 /**
  * Figure out when and how to transmit to the given peer.
  *
- * @param cls the 'struct PeerPlan'
+ * @param cls the `struct PeerPlan`
  * @param tc scheduler context
  */
 static void
@@ -451,7 +451,7 @@ schedule_peer_transmission (void *cls,
   size_t msize;
   struct GNUNET_TIME_Relative delay;
 
-  pp->task = GNUNET_SCHEDULER_NO_TASK;
+  pp->task = NULL;
   if (NULL != pp->pth)
   {
     GSF_peer_transmit_cancel_ (pp->pth);
@@ -506,7 +506,7 @@ schedule_peer_transmission (void *cls,
 
 
 /**
- * Closure for 'merge_pr'.
+ * Closure for merge_pr().
  */
 struct MergeContext
 {
@@ -525,8 +525,8 @@ struct MergeContext
  * @param cls closure
  * @param query the query
  * @param element request plan stored at the node
- * @return GNUNET_YES if we should continue to iterate,
- *         GNUNET_NO if not (merge success)
+ * @return #GNUNET_YES if we should continue to iterate,
+ *         #GNUNET_NO if not (merge success)
  */
 static int
 merge_pr (void *cls, const struct GNUNET_HashCode * query, void *element)
@@ -573,7 +573,8 @@ merge_pr (void *cls, const struct GNUNET_HashCode * query, void *element)
  * @param pr request with the entry
  */
 void
-GSF_plan_add_ (struct GSF_ConnectedPeer *cp, struct GSF_PendingRequest *pr)
+GSF_plan_add_ (struct GSF_ConnectedPeer *cp,
+               struct GSF_PendingRequest *pr)
 {
   const struct GNUNET_PeerIdentity *id;
   struct PeerPlan *pp;
@@ -584,7 +585,7 @@ GSF_plan_add_ (struct GSF_ConnectedPeer *cp, struct GSF_PendingRequest *pr)
 
   GNUNET_assert (NULL != cp);
   id = GSF_connected_peer_get_identity2_ (cp);
-  pp = GNUNET_CONTAINER_multihashmap_get (plans, &id->hashPubKey);
+  pp = GNUNET_CONTAINER_multipeermap_get (plans, id);
   if (NULL == pp)
   {
     pp = GNUNET_new (struct PeerPlan);
@@ -594,15 +595,16 @@ GSF_plan_add_ (struct GSF_ConnectedPeer *cp, struct GSF_PendingRequest *pr)
     pp->delay_heap =
         GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
     pp->cp = cp;
-    GNUNET_CONTAINER_multihashmap_put (plans, 
-                                      &id->hashPubKey, pp,
-                                       GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+    GNUNET_assert (GNUNET_OK ==
+                   GNUNET_CONTAINER_multipeermap_put (plans,
+                                                      id, pp,
+                                                      GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
   }
   mpc.merged = GNUNET_NO;
   mpc.pr = pr;
   GNUNET_CONTAINER_multihashmap_get_multiple (pp->plan_map,
                                               &GSF_pending_request_get_data_
-                                              (pr)->query, &merge_pr, &mpc); // 8 MB in 'merge_pr'
+                                              (pr)->query, &merge_pr, &mpc);
   if (GNUNET_NO != mpc.merged)
     return;
   GNUNET_CONTAINER_multihashmap_get_multiple (pp->plan_map,
@@ -617,7 +619,7 @@ GSF_plan_add_ (struct GSF_ConnectedPeer *cp, struct GSF_PendingRequest *pr)
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               "Planning transmission of query `%s' to peer `%s'\n",
               GNUNET_h2s (&prd->query), GNUNET_i2s (id));
-  rp = GNUNET_new (struct GSF_RequestPlan); // 8 MB
+  rp = GNUNET_new (struct GSF_RequestPlan);
   bi = GNUNET_new (struct GSF_PendingRequestPlanBijection);
   bi->rp = rp;
   bi->pr = pr;
@@ -627,8 +629,8 @@ GSF_plan_add_ (struct GSF_ConnectedPeer *cp, struct GSF_PendingRequest *pr)
   GNUNET_assert (GNUNET_YES ==
                  GNUNET_CONTAINER_multihashmap_put (pp->plan_map,
                                                     get_rp_key (rp), rp,
-                                                    GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE)); // 8 MB
-  plan (pp, rp); // +5 MB (plan/heap-insert)
+                                                    GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+  plan (pp, rp);
 }
 
 
@@ -648,21 +650,21 @@ GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp)
   struct GSF_PendingRequestPlanBijection *bi;
 
   id = GSF_connected_peer_get_identity2_ (cp);
-  pp = GNUNET_CONTAINER_multihashmap_get (plans, &id->hashPubKey);
+  pp = GNUNET_CONTAINER_multipeermap_get (plans, id);
   if (NULL == pp)
     return;                     /* nothing was ever planned for this peer */
   GNUNET_assert (GNUNET_YES ==
-                 GNUNET_CONTAINER_multihashmap_remove (plans, &id->hashPubKey,
+                 GNUNET_CONTAINER_multipeermap_remove (plans, id,
                                                        pp));
   if (NULL != pp->pth)
   {
     GSF_peer_transmit_cancel_ (pp->pth);
     pp->pth = NULL;
   }
-  if (GNUNET_SCHEDULER_NO_TASK != pp->task)
+  if (NULL != pp->task)
   {
     GNUNET_SCHEDULER_cancel (pp->task);
-    pp->task = GNUNET_SCHEDULER_NO_TASK;
+    pp->task = NULL;
   }
   while (NULL != (rp = GNUNET_CONTAINER_heap_remove_root (pp->priority_heap)))
   {
@@ -705,17 +707,17 @@ GSF_plan_notify_peer_disconnect_ (const struct GSF_ConnectedPeer *cp)
 
 /**
  * Get the last transmission attempt time for the request plan list
- * referenced by 'pr_head', that was sent to 'sender'
+ * referenced by @a pr_head, that was sent to @a sender
  *
  * @param pr_head request plan reference list to check.
  * @param sender the peer that we've sent the request to.
- * @param result the timestamp to fill, set to "FOREVER" if never transmitted
- * @return GNUNET_YES if 'result' was changed, GNUNET_NO otherwise.
+ * @param result the timestamp to fill, set to #GNUNET_TIME_UNIT_FOREVER_ABS if never transmitted
+ * @return #GNUNET_YES if @a result was changed, #GNUNET_NO otherwise.
  */
 int
-GSF_request_plan_reference_get_last_transmission_ (
-    struct GSF_PendingRequestPlanBijection *pr_head, struct GSF_ConnectedPeer *sender,
-    struct GNUNET_TIME_Absolute *result)
+GSF_request_plan_reference_get_last_transmission_ (struct GSF_PendingRequestPlanBijection *pr_head,
+                                                   struct GSF_ConnectedPeer *sender,
+                                                   struct GNUNET_TIME_Absolute *result)
 {
   struct GSF_PendingRequestPlanBijection *bi;
 
@@ -777,7 +779,7 @@ GSF_plan_notify_request_done_ (struct GSF_PendingRequest *pr)
 void
 GSF_plan_init ()
 {
-  plans = GNUNET_CONTAINER_multihashmap_create (256, GNUNET_YES);
+  plans = GNUNET_CONTAINER_multipeermap_create (256, GNUNET_YES);
 }
 
 
@@ -787,8 +789,8 @@ GSF_plan_init ()
 void
 GSF_plan_done ()
 {
-  GNUNET_assert (0 == GNUNET_CONTAINER_multihashmap_size (plans));
-  GNUNET_CONTAINER_multihashmap_destroy (plans);
+  GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (plans));
+  GNUNET_CONTAINER_multipeermap_destroy (plans);
 }