-indentation, code cleanup
[oweals/gnunet.git] / src / set / gnunet-service-set_intersection.c
index d654f33e8f10d9245824a5107bfc36430d6eb2ec..3082f94b57b10ef695bee70cbc84a9eba60f4564 100644 (file)
@@ -4,7 +4,7 @@
 
       GNUnet is free software; you can redistribute it and/or modify
       it under the terms of the GNU General Public License as published
-      by the Free Software Foundation; either version 2, or (at your
+      by the Free Software Foundation; either version 3, or (at your
       option) any later version.
 
       GNUnet is distributed in the hope that it will be useful, but
@@ -124,10 +124,9 @@ struct IntersectionEvaluateOperation
   struct GNUNET_MessageHeader *context_msg;
 
   /**
-   * Tunnel context for the peer we
-   * evaluate the union operation with.
+   * Tunnel to the other peer.
    */
-  struct TunnelContext *tc;
+  struct GNUNET_MESH_Tunnel *tunnel;
 
   /**
    * Request ID to multiplex set operations to
@@ -176,13 +175,13 @@ struct IntersectionEvaluateOperation
    * was created.
    */
   unsigned int generation_created;
-  
+
   /**
    * Evaluate operations are held in
    * a linked list.
    */
   struct IntersectionEvaluateOperation *next;
-  
+
    /**
    * Evaluate operations are held in
    * a linked list.
@@ -225,7 +224,7 @@ struct ElementEntry
   int removed;
 
   /**
-   * Generation the element was removed by the client. 
+   * Generation the element was removed by the client.
    * Operations of later generations will not consider the element.
    * Only valid if is_removed is GNUNET_YES.
    */
@@ -277,7 +276,7 @@ struct SendElementClosure
    * Operation for which the elements
    * should be sent.
    */
-  struct UnionEvaluateOperation *eo;
+  struct IntersectionEvaluateOperation *eo;
 };
 
 
@@ -303,13 +302,13 @@ struct IntersectionState
    * Evaluate operations are held in
    * a linked list.
    */
-  struct UnionEvaluateOperation *ops_head;
+  struct IntersectionEvaluateOperation *ops_head;
 
   /**
    * Evaluate operations are held in
    * a linked list.
    */
-  struct UnionEvaluateOperation *ops_tail;
+  struct IntersectionEvaluateOperation *ops_tail;
 
   /**
    * Current generation, that is, number of
@@ -375,7 +374,7 @@ destroy_key_to_element_iter (void *cls,
                              void *value)
 {
   struct KeyEntry *k = value;
-  
+
   while (NULL != k)
   {
     struct KeyEntry *k_tmp = k;
@@ -396,13 +395,12 @@ void
 _GSS_union_operation_destroy (struct UnionEvaluateOperation *eo)
 {
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "destroying union op\n");
-  
-  if (NULL != eo->tc)
+
+  if (NULL != eo->tunnel)
   {
-    GNUNET_MQ_destroy (eo->tc->mq);
-    GNUNET_MESH_tunnel_destroy (eo->tc->tunnel);
-    GNUNET_free (eo->tc);
-    eo->tc = NULL;
+    GNUNET_MESH_tunnel_destroy (eo->tunnel);
+    /* wait for the final destruction by the tunnel cleaner */
+    return;
   }
 
   if (NULL != eo->remote_ibf)
@@ -432,10 +430,8 @@ _GSS_union_operation_destroy (struct UnionEvaluateOperation *eo)
                                eo);
   GNUNET_free (eo);
 
-
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "destroying union op done\n");
 
-
   /* FIXME: do a garbage collection of the set generations */
 }
 
@@ -461,7 +457,7 @@ fail_union_operation (struct UnionEvaluateOperation *eo)
 
 
 /**
- * Derive the IBF key from a hash code and 
+ * Derive the IBF key from a hash code and
  * a salt.
  *
  * @param src the hash code
@@ -488,7 +484,7 @@ get_ibf_key (struct GNUNET_HashCode *src, uint16_t salt)
  * @param eo operation with the other peer
  */
 static void
-send_operation_request (struct UnionEvaluateOperation *eo)
+send_operation_request (struct IntersectionEvaluateOperation *eo)
 {
   struct GNUNET_MQ_Envelope *mqm;
   struct OperationRequestMessage *msg;
@@ -502,7 +498,7 @@ send_operation_request (struct UnionEvaluateOperation *eo)
     GNUNET_SERVER_client_disconnect (eo->set->client);
     return;
   }
-  msg->operation = htons (GNUNET_SET_OPERATION_UNION);
+  msg->operation = htons (GNUNET_SET_OPERATION_INTERSECTION);
   msg->app_id = eo->app_id;
   GNUNET_MQ_send (eo->tc->mq, mqm);
 
@@ -705,7 +701,7 @@ send_ibf (struct UnionEvaluateOperation *eo, uint16_t ibf_order)
  * @param eo the union operation with the remote peer
  */
 static void
-send_strata_estimator (struct UnionEvaluateOperation *eo)
+send_strata_estimator (struct IntersectionEvaluateOperation *eo)
 {
   struct GNUNET_MQ_Envelope *mqm;
   struct GNUNET_MessageHeader *strata_msg;
@@ -713,7 +709,7 @@ send_strata_estimator (struct UnionEvaluateOperation *eo)
   mqm = GNUNET_MQ_msg_header_extra (strata_msg,
                                     SE_STRATA_COUNT * IBF_BUCKET_SIZE * SE_IBF_SIZE,
                                     GNUNET_MESSAGE_TYPE_SET_P2P_SE);
-  strata_estimator_write (eo->set->state.u->se, &strata_msg[1]);
+  strata_estimator_write (eo->set->state.i->se, &strata_msg[1]);
   GNUNET_MQ_send (eo->tc->mq, mqm);
   eo->phase = PHASE_EXPECT_IBF;
 }
@@ -867,14 +863,14 @@ decode_and_send (struct UnionEvaluateOperation *eo)
       next_order++;
       if (next_order <= MAX_IBF_ORDER)
       {
-        GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 
+        GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                    "decoding failed, sending larger ibf (size %u)\n",
                     1<<next_order);
         send_ibf (eo, next_order);
       }
       else
       {
-        GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                    "set union failed: reached ibf limit\n");
       }
       break;
@@ -954,7 +950,7 @@ handle_p2p_ibf (void *cls, const struct GNUNET_MessageHeader *mh)
     fail_union_operation (eo);
     return;
   }
-  
+
   ibf_read_slice (&msg[1], eo->ibf_buckets_received, buckets_in_message, eo->remote_ibf);
   eo->ibf_buckets_received += buckets_in_message;
 
@@ -1043,7 +1039,7 @@ handle_p2p_elements (void *cls, const struct GNUNET_MessageHeader *mh)
     return;
   }
   element_size = ntohs (mh->size) - sizeof (struct GNUNET_MessageHeader);
-  ee = GNUNET_malloc (sizeof *eo + element_size);
+  ee = GNUNET_malloc (sizeof *ee + element_size);
   memcpy (&ee[1], &mh[1], element_size);
   ee->element.data = &ee[1];
   ee->remote = GNUNET_YES;
@@ -1110,7 +1106,7 @@ peer_done_sent_cb (void *cls)
 
 /**
  * Handle a done message from a remote peer
- * 
+ *
  * @param cls the union operation
  * @param mh the message
  */
@@ -1151,7 +1147,7 @@ handle_p2p_done (void *cls, const struct GNUNET_MessageHeader *mh)
  * @param set the set to evaluate the operation with
  */
 void
-_GSS_union_evaluate (struct GNUNET_SET_EvaluateMessage *m, struct Set *set)
+_GSS_intersection_evaluate (struct GNUNET_SET_EvaluateMessage *m, struct Set *set)
 {
   struct IntersectionEvaluateOperation *eo;
   struct GNUNET_MessageHeader *context_msg;
@@ -1164,15 +1160,15 @@ _GSS_union_evaluate (struct GNUNET_SET_EvaluateMessage *m, struct Set *set)
   eo->se = strata_estimator_dup (set->state.i->se);
   eo->salt = ntohs (m->salt);
   eo->app_id = m->app_id;
-  
+
   context_msg = GNUNET_MQ_extract_nested_mh (m);
   if (NULL != context_msg)
   {
     eo->context_msg = GNUNET_copy_message (context_msg);
   }
 
-  GNUNET_log (GNUNET_ERROR_TYPE_INFO, 
-             "evaluating intersection operation, (app %s)\n", 
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+             "evaluating intersection operation, (app %s)\n",
               GNUNET_h2s (&eo->app_id));
 
   eo->tc = GNUNET_new (struct TunnelContext);
@@ -1200,24 +1196,24 @@ _GSS_union_evaluate (struct GNUNET_SET_EvaluateMessage *m, struct Set *set)
  * @param incoming information about the requesting remote peer
  */
 void
-_GSS_union_accept (struct GNUNET_SET_AcceptRejectMessage *m, struct Set *set,
+_GSS_intersection_accept (struct GNUNET_SET_AcceptRejectMessage *m, struct Set *set,
                    struct Incoming *incoming)
 {
-  struct UnionEvaluateOperation *eo;
+  struct IntersectionEvaluateOperation *eo;
 
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "accepting set union operation\n");
 
-  eo = GNUNET_new (struct UnionEvaluateOperation);
+  eo = GNUNET_new (struct IntersectionEvaluateOperation);
   eo->tc = incoming->tc;
-  eo->generation_created = set->state.u->current_generation++;
+  eo->generation_created = set->state.i->current_generation++;
   eo->set = set;
   eo->salt = ntohs (incoming->salt);
   GNUNET_assert (0 != ntohl (m->request_id));
   eo->request_id = ntohl (m->request_id);
-  eo->se = strata_estimator_dup (set->state.u->se);
+  eo->se = strata_estimator_dup (set->state.i->se);
   /* transfer ownership of mq and socket from incoming to eo */
-  GNUNET_CONTAINER_DLL_insert (eo->set->state.u->ops_head,
-                               eo->set->state.u->ops_tail,
+  GNUNET_CONTAINER_DLL_insert (eo->set->state.i->ops_head,
+                               eo->set->state.i->ops_tail,
                                eo);
   /* kick off the operation */
   send_strata_estimator (eo);
@@ -1235,7 +1231,7 @@ _GSS_intersection_set_create (void)
   struct Set *set;
 
   GNUNET_log (GNUNET_ERROR_TYPE_INFO, "intersection set created\n");
-  
+
   set = GNUNET_malloc (sizeof (struct Set) + sizeof (struct IntersectionState));
   set->state.i = (struct IntersectionState *) &set[1];
   set->operation = GNUNET_SET_OPERATION_INTERSECTION;
@@ -1243,7 +1239,7 @@ _GSS_intersection_set_create (void)
    * want the hash map to copy them */
   set->state.i->elements = GNUNET_CONTAINER_multihashmap_create (1, GNUNET_YES);
   set->state.i->se = strata_estimator_create (SE_STRATA_COUNT,
-                                              SE_IBF_SIZE, SE_IBF_HASH_NUM);  
+                                              SE_IBF_SIZE, SE_IBF_HASH_NUM);
   return set;
 }
 
@@ -1287,7 +1283,7 @@ _GSS_intersection_add (struct GNUNET_SET_ElementMessage *m, struct Set *set)
 /**
  * Destroy a set that supports the union operation
  *
- * @param the set to destroy, must be of type GNUNET_SET_OPERATION_UNION
+ * @param set the set to destroy, must be of type GNUNET_SET_OPERATION_UNION
  */
 void
 _GSS_union_set_destroy (struct Set *set)
@@ -1355,7 +1351,6 @@ _GSS_intersection_remove (struct GNUNET_SET_ElementMessage *m, struct Set *set)
  * @param cls closure
  * @param tunnel mesh tunnel
  * @param tunnel_ctx tunnel context
- * @param sender ???
  * @param mh message to process
  * @return ???
  */
@@ -1363,7 +1358,6 @@ int
 _GSS_union_handle_p2p_message (void *cls,
                                struct GNUNET_MESH_Tunnel *tunnel,
                                void **tunnel_ctx,
-                               const struct GNUNET_PeerIdentity *sender,
                                const struct GNUNET_MessageHeader *mh)
 {
   struct TunnelContext *tc = *tunnel_ctx;
@@ -1371,7 +1365,6 @@ _GSS_union_handle_p2p_message (void *cls,
 
   if (CONTEXT_OPERATION_UNION != tc->type)
   {
-    /* FIXME: kill the tunnel */
     /* never kill mesh */
     return GNUNET_OK;
   }