gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet] 161/164: Fixed smal bug in propabilistic algo


From: gnunet
Subject: [gnunet] 161/164: Fixed smal bug in propabilistic algo
Date: Fri, 30 Jul 2021 15:33:47 +0200

This is an automated email from the git hooks/post-receive script.

grothoff pushed a commit to branch master
in repository gnunet.

commit 278c5f02f2f8a78948a8d13ab5fdc88cb84c174e
Author: Elias Summermatter <elias.summermatter@seccom.ch>
AuthorDate: Thu Jun 17 09:40:45 2021 +0200

    Fixed smal bug in propabilistic algo
---
 src/setu/gnunet-service-setu.c | 140 +++++++++++++++++++++++------------------
 src/setu/ibf.c                 |   7 ++-
 2 files changed, 82 insertions(+), 65 deletions(-)

diff --git a/src/setu/gnunet-service-setu.c b/src/setu/gnunet-service-setu.c
index 508434057..e5e7d7591 100644
--- a/src/setu/gnunet-service-setu.c
+++ b/src/setu/gnunet-service-setu.c
@@ -528,7 +528,7 @@ struct Operation
   /**
    *
    */
-   bool active_passive_switch_required;
+  bool active_passive_switch_required;
 };
 
 
@@ -949,7 +949,8 @@ calculate_perf_store ()
                                                        
GNUNET_SETU_ElementMessage),
                                                 perf_store.element);
   // bytes_transmitted += 
sum_sent_received_bytes(sizeof(GNUNET_MESSAGE_TYPE_SETU_P2P_OPERATION_REQUEST), 
perf_store.operation_request);
-  bytes_transmitted += sum_sent_received_bytes (sizeof(struct 
StrataEstimatorMessage),
+  bytes_transmitted += sum_sent_received_bytes (sizeof(struct
+                                                       StrataEstimatorMessage),
                                                 perf_store.se);
   bytes_transmitted += sum_sent_received_bytes (4, perf_store.full_done);
   bytes_transmitted += sum_sent_received_bytes (sizeof(struct IBFMessage),
@@ -1078,7 +1079,7 @@ estimate_best_mode_of_operation (uint64_t 
avg_element_size,
     ibf_bucket_count = IBF_MIN_SIZE;
   }
   uint64_t ibf_message_count = ceil ( ((float) ibf_bucket_count)
-                                     / MAX_BUCKETS_PER_MESSAGE);
+                                      / MAX_BUCKETS_PER_MESSAGE);
 
   uint64_t estimated_counter_size = ceil (
     MIN (2 * log2l ((float) local_set_size / ibf_bucket_count), log2l (
@@ -1186,29 +1187,33 @@ update_message_control_flow (struct 
GNUNET_CONTAINER_MultiHashMap *hash_map,
   enum MESSAGE_CONTROL_FLOW_STATE *mcfs;
 
   cfe = GNUNET_CONTAINER_multihashmap_get (hash_map, hash_code);
-  if((ELEMENT_MESSAGE == mt) && (cfe != NULL)) {
-      if ((new_mcfs != MSG_CFS_SENT) && (MSG_CFS_RECEIVED != cfe->offer))
-      {
-          LOG (GNUNET_ERROR_TYPE_ERROR,
-               "Received an element without sent offer!\n");
-          return GNUNET_NO;
-      }
-      /* Check that only requested elements are received! */
-      if ((ELEMENT_MESSAGE == mt) && (new_mcfs != MSG_CFS_SENT) && 
(cfe->demand != MSG_CFS_SENT)) {
-          LOG (GNUNET_ERROR_TYPE_ERROR,
-               "Received an element that was not demanded\n");
-          return GNUNET_NO;
-      }
+  if ((ELEMENT_MESSAGE == mt) && (cfe != NULL))
+  {
+    if ((new_mcfs != MSG_CFS_SENT) && (MSG_CFS_RECEIVED != cfe->offer))
+    {
+      LOG (GNUNET_ERROR_TYPE_ERROR,
+           "Received an element without sent offer!\n");
+      return GNUNET_NO;
+    }
+    /* Check that only requested elements are received! */
+    if ((ELEMENT_MESSAGE == mt) && (new_mcfs != MSG_CFS_SENT) && (cfe->demand 
!=
+                                                                  
MSG_CFS_SENT))
+    {
+      LOG (GNUNET_ERROR_TYPE_ERROR,
+           "Received an element that was not demanded\n");
+      return GNUNET_NO;
+    }
   }
 
   if (NULL == cfe)
   {
     cfe = GNUNET_new (struct messageControlFlowElement);
-    if( GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (hash_map, 
hash_code,cfe,
-                                         
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
+    if (GNUNET_SYSERR == GNUNET_CONTAINER_multihashmap_put (hash_map, 
hash_code,
+                                                            cfe,
+                                                            
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY))
     {
-        GNUNET_free(cfe);
-        return GNUNET_SYSERR;
+      GNUNET_free (cfe);
+      return GNUNET_SYSERR;
     }
   }
 
@@ -1258,21 +1263,28 @@ is_message_in_message_control_flow (struct
 
   cfe = GNUNET_CONTAINER_multihashmap_get (hash_map, hash_code);
 
-  if(cfe != NULL) {
-      if (OFFER_MESSAGE == mt)
-      {
-          mcfs = &cfe->offer;
-      }
-      else if (DEMAND_MESSAGE == mt) {
-          mcfs = &cfe->demand;
-      } else if (ELEMENT_MESSAGE == mt) {
-          mcfs = &cfe->element;
-      } else {
-          return GNUNET_SYSERR;
-      }
-      if (*mcfs != MSG_CFS_UNINITIALIZED) {
-          return GNUNET_YES;
-      }
+  if (cfe != NULL)
+  {
+    if (OFFER_MESSAGE == mt)
+    {
+      mcfs = &cfe->offer;
+    }
+    else if (DEMAND_MESSAGE == mt)
+    {
+      mcfs = &cfe->demand;
+    }
+    else if (ELEMENT_MESSAGE == mt)
+    {
+      mcfs = &cfe->element;
+    }
+    else
+    {
+      return GNUNET_SYSERR;
+    }
+    if (*mcfs != MSG_CFS_UNINITIALIZED)
+    {
+      return GNUNET_YES;
+    }
   }
   return GNUNET_NO;
 }
@@ -1641,8 +1653,8 @@ fail_union_operation (struct Operation *op)
 static void
 full_sync_plausibility_check (struct Operation *op)
 {
-  if(GNUNET_YES != op->byzantine)
-      return;
+  if (GNUNET_YES != op->byzantine)
+    return;
 
   int security_level_lb = -1 * SECURITY_LEVEL;
   uint64_t duplicates = op->received_fresh - op->received_total;
@@ -1685,7 +1697,7 @@ full_sync_plausibility_check (struct Operation *op)
                                                                            
double)
                                                                         op->
                                                                         
remote_set_diff)));
-    long double value = exponent * (log2l(base)/log2l(2));
+    long double value = exponent * (log2l (base) / log2l (2));
     if ((value < security_level_lb) || (value > SECURITY_LEVEL) )
     {
       LOG (GNUNET_ERROR_TYPE_ERROR,
@@ -1707,8 +1719,10 @@ full_sync_plausibility_check (struct Operation *op)
 static void
 check_max_differential_rounds (struct Operation *op)
 {
-  long double probability = op->differential_sync_iterations * 
(log2l(PROBABILITY_FOR_NEW_ROUND)/log2l(2));
-  if ((long double) 1 / (SECURITY_LEVEL) > probability)
+  double probability = op->differential_sync_iterations * (log2l (
+                                                             
PROBABILITY_FOR_NEW_ROUND)
+                                                           / log2l (2));
+  if ((-1 * SECURITY_LEVEL) > probability)
   {
     LOG (GNUNET_ERROR_TYPE_ERROR,
          "PROTOCOL VIOLATION: Other peer violated probabilistic rule for to 
many active passive "
@@ -2131,8 +2145,8 @@ get_next_ibf_size (float ibf_bucket_number_factor, 
unsigned int
   unsigned int next_size = (unsigned int) ((last_ibf_size * 2)
                                            - (ibf_bucket_number_factor
                                               * decoded_elements));
-   /** Make ibf estimation size odd reasoning can be found in BSc Thesis of
-   * Elias Summermatter (2021) in section 3.11 **/
+  /** Make ibf estimation size odd reasoning can be found in BSc Thesis of
+  * Elias Summermatter (2021) in section 3.11 **/
   return next_size | 1;
 }
 
@@ -2528,9 +2542,10 @@ send_offers_iterator (void *cls,
   struct GNUNET_MessageHeader *mh;
 
   /* Detect 32-bit key collision for the 64-bit IBF keys. */
-  if (ke->ibf_key.key_val != sec->ibf_key.key_val) {
-      op->active_passive_switch_required = true;
-      return GNUNET_YES;
+  if (ke->ibf_key.key_val != sec->ibf_key.key_val)
+  {
+    op->active_passive_switch_required = true;
+    return GNUNET_YES;
   }
 
   /* Prevent implementation from sending a offer multiple times in case of 
roll switch */
@@ -3834,13 +3849,13 @@ handle_union_p2p_demand (void *cls,
   {
     ee = GNUNET_CONTAINER_multihashmap_get (op->set->content->elements,
                                             hash);
-      if (NULL == ee)
-      {
-          /* Demand for non-existing element. */
-          GNUNET_break_op (0);
-          fail_union_operation (op);
-          return;
-      }
+    if (NULL == ee)
+    {
+      /* Demand for non-existing element. */
+      GNUNET_break_op (0);
+      fail_union_operation (op);
+      return;
+    }
 
     /* Save send demand message for message control */
     if (GNUNET_YES !=
@@ -4030,7 +4045,7 @@ handle_union_p2p_offer (void *cls,
           DEMAND_MESSAGE)
         )
     {
-      //GNUNET_free (ev);
+      // GNUNET_free (ev);
       LOG (GNUNET_ERROR_TYPE_ERROR,
            "Double demand message sent found!\n");
       GNUNET_break (0);
@@ -4048,7 +4063,7 @@ handle_union_p2p_offer (void *cls,
           OFFER_MESSAGE)
         )
     {
-      //GNUNET_free (ev);
+      // GNUNET_free (ev);
       LOG (GNUNET_ERROR_TYPE_ERROR,
            "Double offer message received found!\n");
       GNUNET_break (0);
@@ -4066,7 +4081,7 @@ handle_union_p2p_offer (void *cls,
           ELEMENT_MESSAGE)
         )
     {
-      //GNUNET_free (ev);
+      // GNUNET_free (ev);
       LOG (GNUNET_ERROR_TYPE_ERROR,
            "Element already expected!\n");
       GNUNET_break (0);
@@ -4109,13 +4124,14 @@ handle_union_p2p_done (void *cls,
     return;
   }
 
-    if(op->active_passive_switch_required) {
-        LOG (GNUNET_ERROR_TYPE_ERROR,
-             "PROTOCOL VIOLATION: Received done but role change is 
necessary\n");
-        GNUNET_break (0);
-        fail_union_operation (op);
-        return;
-    }
+  if (op->active_passive_switch_required)
+  {
+    LOG (GNUNET_ERROR_TYPE_ERROR,
+         "PROTOCOL VIOLATION: Received done but role change is necessary\n");
+    GNUNET_break (0);
+    fail_union_operation (op);
+    return;
+  }
 
 #if MEASURE_PERFORMANCE
   perf_store.done.received += 1;
diff --git a/src/setu/ibf.c b/src/setu/ibf.c
index c72d075e0..628b00e96 100644
--- a/src/setu/ibf.c
+++ b/src/setu/ibf.c
@@ -428,9 +428,10 @@ pack_counter (const struct InvertibleBloomFilter *ibf,
     }
     i++;
   }
-  if(store_size > 0) {
-      buf[byte_ctr] = store << (8 - store_size);
-      byte_ctr++;
+  if (store_size > 0)
+  {
+    buf[byte_ctr] = store << (8 - store_size);
+    byte_ctr++;
   }
 
 }

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]