use c99
[oweals/gnunet.git] / src / set / gnunet-service-set_union.c
index af1aaeb81b95c787306d88120059d749af78c6d0..aeb706ec3d4c3b96cd9271e47de7de30ca1af46e 100644 (file)
@@ -1,6 +1,6 @@
 /*
       This file is part of GNUnet
-      Copyright (C) 2013-2015 Christian Grothoff (and other contributing authors)
+      Copyright (C) 2013-2015 GNUnet e.V.
 
       GNUnet is free software; you can redistribute it and/or modify
       it under the terms of the GNU General Public License as published
@@ -18,7 +18,7 @@
       Boston, MA 02110-1301, USA.
 */
 /**
- * @file set/gnunet-service-set_union.c    msg->salt = htonl (op->state->salt_send);
+ * @file set/gnunet-service-set_union.c
 
  * @brief two-peer set operations
  * @author Florian Dold
@@ -61,7 +61,7 @@
  * Choose this value so that computing the IBF is still cheaper
  * than transmitting all values.
  */
-#define MAX_IBF_ORDER (18)
+#define MAX_IBF_ORDER (20)
 
 /**
  * Number of buckets used in the ibf per estimated
@@ -454,6 +454,7 @@ salt_key (const struct IBF_Key *k_in,
 {
   int s = salt % 64;
   uint64_t x = k_in->key_val;
+  /* rotate ibf key */
   x = (x >> s) | (x << (64 - s));
   k_out->key_val = x;
 }
@@ -464,9 +465,9 @@ unsalt_key (const struct IBF_Key *k_in,
             uint32_t salt, 
             struct IBF_Key *k_out)
 {
-  int s = -(salt % 64);
+  int s = salt % 64;
   uint64_t x = k_in->key_val;
-  x = (x >> s) | (x << (64 - s));
+  x = (x << s) | (x >> (64 - s));
   k_out->key_val = x;
 }
 
@@ -614,9 +615,10 @@ send_ibf (struct Operation *op,
     ev = GNUNET_MQ_msg_extra (msg,
                               buckets_in_message * IBF_BUCKET_SIZE,
                               GNUNET_MESSAGE_TYPE_SET_UNION_P2P_IBF);
-    msg->reserved = 0;
+    msg->reserved1 = 0;
+    msg->reserved2 = 0;
     msg->order = ibf_order;
-    msg->offset = htons (buckets_sent);
+    msg->offset = htonl (buckets_sent);
     msg->salt = htonl (op->state->salt_send);
     ibf_write_slice (ibf, buckets_sent,
                      buckets_in_message, &msg[1]);
@@ -855,6 +857,7 @@ decode_and_send (struct Operation *op)
   if (GNUNET_OK !=
       prepare_ibf (op, op->state->remote_ibf->size))
   {
+    GNUNET_break (0);
     /* allocation failed */
     return GNUNET_SYSERR;
   }
@@ -1023,6 +1026,7 @@ handle_p2p_ibf (void *cls,
          1 << msg->order);
     op->state->remote_ibf = ibf_create (1<<msg->order, SE_IBF_HASH_NUM);
     op->state->salt_receive = ntohl (msg->salt);
+    LOG (GNUNET_ERROR_TYPE_DEBUG, "Receiving new IBF with salt %u\n", op->state->salt_receive);
     if (NULL == op->state->remote_ibf)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
@@ -1031,7 +1035,7 @@ handle_p2p_ibf (void *cls,
       return GNUNET_SYSERR;
     }
     op->state->ibf_buckets_received = 0;
-    if (0 != ntohs (msg->offset))
+    if (0 != ntohl (msg->offset))
     {
       GNUNET_break_op (0);
       fail_union_operation (op);
@@ -1040,9 +1044,19 @@ handle_p2p_ibf (void *cls,
   }
   else if (op->state->phase == PHASE_EXPECT_IBF_CONT)
   {
-    if ( (ntohs (msg->offset) != op->state->ibf_buckets_received) ||
-         (1<<msg->order != op->state->remote_ibf->size) ||
-         (ntohl (msg->salt) != op->state->salt_receive))
+    if (ntohl (msg->offset) != op->state->ibf_buckets_received)
+    {
+      GNUNET_break_op (0);
+      fail_union_operation (op);
+      return GNUNET_SYSERR;
+    }
+    if (1<<msg->order != op->state->remote_ibf->size)
+    {
+      GNUNET_break_op (0);
+      fail_union_operation (op);
+      return GNUNET_SYSERR;
+    }
+    if (ntohl (msg->salt) != op->state->salt_receive)
     {
       GNUNET_break_op (0);
       fail_union_operation (op);