gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r34112 - gnunet/src/dht


From: gnunet
Subject: [GNUnet-SVN] r34112 - gnunet/src/dht
Date: Tue, 5 Aug 2014 15:24:54 +0200

Author: supriti
Date: 2014-08-05 15:24:53 +0200 (Tue, 05 Aug 2014)
New Revision: 34112

Modified:
   gnunet/src/dht/gnunet-service-xdht_neighbours.c
   gnunet/src/dht/gnunet-service-xdht_routing.c
Log:
Exponential backoff for find_finger_trail_task


Modified: gnunet/src/dht/gnunet-service-xdht_neighbours.c
===================================================================
--- gnunet/src/dht/gnunet-service-xdht_neighbours.c     2014-08-05 13:17:57 UTC 
(rev 34111)
+++ gnunet/src/dht/gnunet-service-xdht_neighbours.c     2014-08-05 13:24:53 UTC 
(rev 34112)
@@ -1514,12 +1514,9 @@
   adm->source_peer = source_peer;
   adm->destination_peer = destination_peer;
   adm->trail_id = trail_id;
-
-  if (trail_length > 0)
-  {
-    peer_list = (struct GNUNET_PeerIdentity *)&adm[1];
-    memcpy (peer_list, trail, sizeof (struct GNUNET_PeerIdentity) * 
trail_length);
-  }
+  peer_list = (struct GNUNET_PeerIdentity *)&adm[1];
+  memcpy (peer_list, trail, sizeof (struct GNUNET_PeerIdentity) * 
trail_length);
+  
   /* Send the message to chosen friend. */
   GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, 
pending);
   target_friend->pending_count++;
@@ -1590,16 +1587,14 @@
                  int trail_length)
 {
   int i;
-  int lowest_index = -1;
 
   for (i = 0; i < trail_length; i++)
   {
     if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &trail[i]))
-      //lowest_index = i;
       return i;
   }
 
-  return lowest_index;
+  return -1;
 }
 
 
@@ -2491,6 +2486,7 @@
   }
 }
 
+static struct GNUNET_TIME_Relative next_send_time;
 
 /*
  * Choose a random friend. Calculate the next finger identity to search,from
@@ -2505,19 +2501,16 @@
                                 const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct FriendInfo *target_friend;
-  struct GNUNET_TIME_Relative next_send_time;
+  //struct GNUNET_TIME_Relative next_send_time;
   struct GNUNET_HashCode trail_id;
   struct GNUNET_HashCode intermediate_trail_id;
   unsigned int is_predecessor;
   uint64_t finger_id_value;
-
+  
   /* Schedule another send_find_finger_trail_message task. */
-  next_send_time.rel_value_us =
-      DHT_FIND_FINGER_TRAIL_INTERVAL.rel_value_us +
-      GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
-                                DHT_FIND_FINGER_TRAIL_INTERVAL.rel_value_us);
   find_finger_trail_task =
-      GNUNET_SCHEDULER_add_delayed (next_send_time, 
&send_find_finger_trail_message,
+      GNUNET_SCHEDULER_add_delayed (next_send_time,
+                                    &send_find_finger_trail_message,
                                     NULL);
 
    /* No space in my routing table. (Source and destination peers also store 
entries
@@ -3066,7 +3059,6 @@
         i++;
       }
       *new_trail_length = j+1;
-      GNUNET_assert((j+1) == (trail_length - 1)); //FIXME: remove it 
afterwards.
       return new_trail;
     }
   }
@@ -3375,12 +3367,16 @@
                                               &successor->finger_identity))
     {
       current_search_finger_index = 0;
+      /* We slow down the find_finger_trail_task as we have completed the 
circle. */
+      next_send_time = GNUNET_TIME_STD_BACKOFF(next_send_time);
+     
       return;
     }
-    struct FingerInfo *prev_finger;
-    prev_finger = &finger_table[finger_table_index - 1];
+    
+    struct FingerInfo prev_finger;
+    prev_finger = finger_table[finger_table_index - 1];
     if (0 == GNUNET_CRYPTO_cmp_peer_identity (&finger_identity,
-                                              &prev_finger->finger_identity))
+                                              &prev_finger.finger_identity))
     {
        current_search_finger_index--;
        return;
@@ -3904,6 +3900,41 @@
   return peer;
 }
 
+#if 0
+/**
+ * Check if peer is already present in the trail. 
+ * @param peer
+ * @param trail
+ * @param trail_length
+ * @return 
+ */
+static struct GNUNET_PeerIdentity *
+check_for_duplicate_entries (const struct GNUNET_PeerIdentity *trail, 
+                             unsigned int trail_length,
+                             unsigned int *updated_trail_length)
+{
+  struct GNUNET_PeerIdentity *updated_trail;
+  unsigned int i;
+  unsigned int j;
+  
+  /* It may happen that there are more than one peer present twice. 
+   but we don't want to*/
+  for(i = 0;i < trail_length; i++)
+  {
+    for(j = i+1; j < trail_length; j++)
+    {
+      if(0 != GNUNET_CRYPTO_cmp_peer_identity (&trail[i],&trail[j]))
+        continue;
+      
+      /* If you found a duplicate entry in the trail, then you should
+       * have the entry at i should point to next of entry stored at j*/
+      
+      /* In case j = (trail_length - 1), then it should NULL. */
+      
+    }
+  }
+}
+#endif
 
 /*
  * Core handle for PeerTrailSetupMessage.
@@ -3926,6 +3957,7 @@
   struct GNUNET_HashCode trail_id;
   unsigned int is_predecessor;
   uint32_t trail_length;
+  unsigned int i;
   size_t msize;
 
   msize = ntohs (message->size);
@@ -3954,6 +3986,14 @@
   is_predecessor = ntohl (trail_setup->is_predecessor);
   intermediate_trail_id = trail_setup->intermediate_trail_id;
 
+  /* Did the friend insert its ID in the trail list? */
+  if (trail_length > 0 &&
+      0 != memcmp (&trail_peer_list[trail_length-1], peer, sizeof (*peer)))
+  {
+    GNUNET_break_op (0);
+    return GNUNET_SYSERR;
+  }
+  
    /* If I was the source and got the message back, then set trail length to 
0.*/
   if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &source))
   {
@@ -3971,14 +4011,21 @@
     trail_length = 0;
   }
 
-  /* Did the friend insert its ID in the trail list? */
-  if (trail_length > 0 &&
-      0 != memcmp (&trail_peer_list[trail_length-1], peer, sizeof (*peer)))
+  /* Check if you are present in the trail seen so far? */
+  if(trail_length > 0)
   {
-    GNUNET_break_op (0);
-    return GNUNET_SYSERR;
+    for (i = 0; i < trail_length ; i++)
+    {
+      if(0 == 
GNUNET_CRYPTO_cmp_peer_identity(&trail_peer_list[i],&my_identity))
+      {
+        //Here if you already were present in the trail. then you
+        // shoudl trail length to i + 1
+        trail_length = i+1;
+        break;
+      }
+    }
   }
-
+  
   /* Is my routing table full?  */
   if (GNUNET_YES == GDS_ROUTING_threshold_reached())
   {
@@ -4208,6 +4255,9 @@
   }
 #endif
 
+  /*TODO:URGENT Check if I am already present in the trail. If yes then its an 
error,
+   as in trail setup we ensure that it should never happen. */
+
   /* Am I the one who initiated the query? */
   if (0 == (GNUNET_CRYPTO_cmp_peer_identity (&querying_peer, &my_identity)))
   {
@@ -4646,9 +4696,9 @@
                                              &source_peer)))
   {
     trail_src_to_curr_pred = get_trail_src_to_curr_pred (source_peer,
-                                                         trail,
-                                                         trail_length,
-                                                         
&trail_src_to_curr_pred_len);
+                                            trail,
+                                            trail_length,
+                                            &trail_src_to_curr_pred_len);
   }
   else
   {
@@ -4819,6 +4869,8 @@
   /* Remove the existing successor. */
   remove_existing_finger (current_successor, 0);
 
+  /* TODO URGENT: Check if any peer is present more than once, if yes then 
shorten
+   the trail. before sending it across the network. */
    /* Generate a new trail id to reach to your new successor. */
   GNUNET_CRYPTO_random_block (GNUNET_CRYPTO_QUALITY_STRONG,
                               &trail_id, sizeof (trail_id));
@@ -5319,6 +5371,7 @@
   msize = ntohs (message->size);
   /* In this message we pass the whole trail from source to destination as we
    * are adding that trail.*/
+  //FIXME: failed when run with 1000 pears. check why.
   if (msize < sizeof (struct PeerAddTrailMessage))
   {
     GNUNET_break_op (0);
@@ -5627,7 +5680,13 @@
 
   /* got a first connection, good time to start with FIND FINGER TRAIL 
requests...*/
   if (GNUNET_SCHEDULER_NO_TASK == find_finger_trail_task)
+  {
+    next_send_time.rel_value_us =
+      DHT_FIND_FINGER_TRAIL_INTERVAL.rel_value_us +
+      GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
+                                DHT_FIND_FINGER_TRAIL_INTERVAL.rel_value_us);
     find_finger_trail_task = GNUNET_SCHEDULER_add_now 
(&send_find_finger_trail_message, NULL);
+  }
 }
 
 

Modified: gnunet/src/dht/gnunet-service-xdht_routing.c
===================================================================
--- gnunet/src/dht/gnunet-service-xdht_routing.c        2014-08-05 13:17:57 UTC 
(rev 34111)
+++ gnunet/src/dht/gnunet-service-xdht_routing.c        2014-08-05 13:24:53 UTC 
(rev 34112)
@@ -320,8 +320,8 @@
   
   
   ret = GNUNET_CONTAINER_multihashmap_put (routing_table,
-                                            &new_trail_id, new_entry,
-                                            
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+                                           &new_trail_id, new_entry,
+                                           
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
   //GNUNET_assert(ret == GNUNET_OK);
   return ret;
 }




reply via email to

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