gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r33262 - gnunet/src/dht
Date: Tue, 13 May 2014 17:02:42 +0200

Author: supriti
Date: 2014-05-13 17:02:42 +0200 (Tue, 13 May 2014)
New Revision: 33262

Modified:
   gnunet/src/dht/gnunet-service-xdht_clients.c
   gnunet/src/dht/gnunet-service-xdht_datacache.c
   gnunet/src/dht/gnunet-service-xdht_neighbours.c
Log:
Handling the correct return type from find_successor() in get,put,get_result 
functions. 


Modified: gnunet/src/dht/gnunet-service-xdht_clients.c
===================================================================
--- gnunet/src/dht/gnunet-service-xdht_clients.c        2014-05-13 14:54:00 UTC 
(rev 33261)
+++ gnunet/src/dht/gnunet-service-xdht_clients.c        2014-05-13 15:02:42 UTC 
(rev 33262)
@@ -918,7 +918,7 @@
   struct PendingMessage *pm;
   struct GNUNET_DHT_ClientPutConfirmationMessage *conf;
   uint16_t size;
-  FPRINTF (stderr,_("\nSUPU %s, %s, %d"),__FILE__, __func__,__LINE__);
+
   size = ntohs (message->size);
   if (size < sizeof (struct GNUNET_DHT_ClientPutMessage))
   {
@@ -931,7 +931,7 @@
                             ("# PUT requests received from clients"), 1,
                             GNUNET_NO);
   put_msg = (const struct GNUNET_DHT_ClientPutMessage *) message;
-  LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, "R5N CLIENT-PUT %s\n",
+  LOG_TRAFFIC (GNUNET_ERROR_TYPE_DEBUG, "X-VINE DHT CLIENT-PUT %s\n",
                GNUNET_h2s_full (&put_msg->key));
   /* give to local clients */
   LOG (GNUNET_ERROR_TYPE_DEBUG,
@@ -949,14 +949,8 @@
                             &put_msg->key, 0, NULL, ntohl (put_msg->type),
                             size - sizeof (struct GNUNET_DHT_ClientPutMessage),
                             &put_msg[1]);
-  
-  /* FIXME: Is it correct to pass your identity as default current_destination
-   * and current_source. also is it correct to copy your identity into a new
-   * address and then pass this address. address at which your identity is 
-   * stored should be const or else you may overwrite it and you lose your
-   * identity value.  */
-  struct GNUNET_PeerIdentity my_identity;
-  my_identity = GDS_NEIGHBOURS_get_my_id();
+ 
+  struct GNUNET_PeerIdentity my_identity =  GDS_NEIGHBOURS_get_my_id();
   GDS_NEIGHBOURS_send_put (&put_msg->key, &put_msg[1],
                            size - sizeof (struct GNUNET_DHT_ClientPutMessage),
                            ntohl (put_msg->type), ntohl (put_msg->options),

Modified: gnunet/src/dht/gnunet-service-xdht_datacache.c
===================================================================
--- gnunet/src/dht/gnunet-service-xdht_datacache.c      2014-05-13 14:54:00 UTC 
(rev 33261)
+++ gnunet/src/dht/gnunet-service-xdht_datacache.c      2014-05-13 15:02:42 UTC 
(rev 33262)
@@ -310,16 +310,19 @@
  
   /* FIXME: add the get path into ctx and then call gds_neighbours_handle_get*/
   int i = 0;
-  while (i < get_path_length)
+  if(get_path != NULL)
   {
-    struct GetPath *element;
-    element = GNUNET_malloc (sizeof (struct GetPath));
-    element->next = NULL;
-    element->prev = NULL;
+    while (i < get_path_length)
+    {
+      struct GetPath *element;
+      element = GNUNET_malloc (sizeof (struct GetPath));
+      element->next = NULL;
+      element->prev = NULL;
     
-    memcpy (&(element->peer), &get_path[i], sizeof(struct 
GNUNET_PeerIdentity));
-    GNUNET_CONTAINER_DLL_insert_tail(ctx.head, ctx.tail, element);
-    i++;
+      memcpy (&(element->peer), &get_path[i], sizeof(struct 
GNUNET_PeerIdentity));
+      GNUNET_CONTAINER_DLL_insert_tail(ctx.head, ctx.tail, element);
+      i++;
+    }
   }
   
   r = GNUNET_DATACACHE_get (datacache, key, type, &datacache_get_iterator,

Modified: gnunet/src/dht/gnunet-service-xdht_neighbours.c
===================================================================
--- gnunet/src/dht/gnunet-service-xdht_neighbours.c     2014-05-13 14:54:00 UTC 
(rev 33261)
+++ gnunet/src/dht/gnunet-service-xdht_neighbours.c     2014-05-13 15:02:42 UTC 
(rev 33262)
@@ -1607,7 +1607,7 @@
 {
   int i;
   struct FriendInfo *target_friend;
-  
+
   /* If finger is my friend, then send a trail teardown message and then set
    * trail_length = 0; */
   if (GNUNET_CONTAINER_multipeermap_get (friend_peermap, finger))
@@ -1677,7 +1677,7 @@
 free_finger (struct FingerInfo *finger)
 {
   struct TrailPeerList *peer;
- 
+
   if(finger->first_trail_head != NULL)
   {
     while (NULL != (peer = finger->first_trail_head))
@@ -1715,7 +1715,6 @@
  int removed_finger_trail_length = removed_finger->first_trail_length;
  int i = 0;
 
- 
  if (removed_finger->first_trail_length == 0)
     return;
  finger_trail = removed_finger->first_trail_head;
@@ -2114,6 +2113,7 @@
   memcpy (&(new_finger_entry->finger_identity), peer, sizeof (struct 
GNUNET_PeerIdentity));
   new_finger_entry->finger_map_index = PREDECESSOR_FINGER_ID;
   new_finger_entry->first_trail_length = trail_length;
+  new_finger_entry->trail_count = 1;
   
   if (trail != NULL) /* finger_trail is NULL in case I am my own finger 
identity. */
   {
@@ -2357,6 +2357,7 @@
     current_search_finger_index = current_search_finger_index - 1;
   }
   
+
   return new_entry_added;
 }
  
@@ -2494,9 +2495,7 @@
 }
 
 
-/** FIXME: by default I keep current_source, and destination as my own id.
- * in case we find a finger then we update current_source in the 
- * find_successor message. 
+/**
  * Construct a Put message and send it to target_peer. 
  * @param key Key for the content  
  * @param data Content to store
@@ -2553,18 +2552,11 @@
   {
     uint64_t key_value;
     struct GNUNET_PeerIdentity *next_hop;
+   
     memcpy (&key_value, key, sizeof (uint64_t));
-    struct GNUNET_PeerIdentity curr_dest;
-    struct GNUNET_PeerIdentity curr_src;
-    memcpy (&curr_dest, &current_destination, sizeof (struct 
GNUNET_PeerIdentity));
-    memcpy (&curr_src, &current_source, sizeof (struct GNUNET_PeerIdentity));
-    next_hop = find_successor (key_value, &curr_dest, &curr_src);
-    /* FIXME: I am copying back current_destination and current_source. but I 
am not 
-     sure, if its correct. I am doing so just to remove the code from client 
file.*/
-    memcpy (&current_destination, &curr_dest, sizeof (struct 
GNUNET_PeerIdentity));
-    memcpy (&current_source, &curr_src, sizeof (struct GNUNET_PeerIdentity));
-    
-    if (0 == 
GNUNET_CRYPTO_cmp_peer_identity(&my_identity,&current_destination)) /* I am the 
destination do datacache_put */
+    next_hop = find_successor (key_value, &current_destination, 
&current_source);
+
+    if (0 == GNUNET_CRYPTO_cmp_peer_identity(next_hop, &current_destination)) 
/* I am the destination do datacache_put */
     {
       GDS_DATACACHE_handle_put (expiration_time, key, put_path_length, 
put_path,
                                 block_type, data_size, data);
@@ -2604,9 +2596,7 @@
 
 
 
-/** FIXME: by default I keep current_source, and destination as my own id.
- * in case we find a finger then we update current_source in the 
- * find_successor message. 
+/** 
  * Construct a Get message and send it to target_peer. 
  * @param key Key for the content  
  * @param block_type Type of the block
@@ -2652,18 +2642,12 @@
     /* This is the first call from client file, we need to search for 
next_hop*/
     struct GNUNET_PeerIdentity *next_hop;
     uint64_t key_value;
-    struct GNUNET_PeerIdentity curr_dest;
-    struct GNUNET_PeerIdentity curr_src;
-    memcpy (&curr_dest, &current_destination, sizeof (struct 
GNUNET_PeerIdentity));
-    memcpy (&curr_src, &current_source, sizeof (struct GNUNET_PeerIdentity));
+    
     memcpy (&key_value, key, sizeof (uint64_t));
        // FIXME: endianess of key_value!?
-    next_hop = find_successor (key_value, &curr_dest, &curr_src);
-    /* FIXME: Again I am copying back value of current_destination, 
current_source,
-     Think of a better solution. */
-    memcpy (&current_destination, &curr_dest, sizeof (struct 
GNUNET_PeerIdentity));
-    memcpy (&current_source, &curr_src, sizeof (struct GNUNET_PeerIdentity));
-    if (NULL == next_hop) /* I am the destination do datacache_put */
+    next_hop = find_successor (key_value, &current_destination, 
&current_source);
+   
+    if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity,next_hop)) /* I am 
the destination do datacache_put */
     {
       GDS_DATACACHE_handle_get (key,block_type, NULL, 0, 
                                 NULL, 0, 1, &my_identity, NULL,&my_identity);
@@ -2687,8 +2671,11 @@
   pgm->current_source = current_source;
   pgm->hop_count = htonl (hop_count + 1);
   
-  gp = (struct GNUNET_PeerIdentity *) &pgm[1];
-  memcpy (gp, get_path, get_path_length * sizeof (struct GNUNET_PeerIdentity));
+  if (get_path != 0)
+  {
+    gp = (struct GNUNET_PeerIdentity *) &pgm[1];
+    memcpy (gp, get_path, get_path_length * sizeof (struct 
GNUNET_PeerIdentity));
+  }
   GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, 
pending);
   target_friend->pending_count++;
   process_friend_queue (target_friend);
@@ -2739,13 +2726,18 @@
   }
   
   current_path_index = search_my_index(get_path, get_path_length);
-  /* FIXME: handle the case when current_path_index = GNUNET_SYSERR;*/
+  if (GNUNET_SYSERR == current_path_index)
+  {
+    GNUNET_break (0);
+    return;
+  }
   if (0 == current_path_index)
   {
     GDS_CLIENTS_handle_reply (expiration, key, get_path_length, get_path, 
put_path_length,
                               put_path, type, data_size, data);
     return;
   }
+  
   pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
   pending->importance = 0;   
   get_result = (struct PeerGetResultMessage *)&pending[1];
@@ -2756,14 +2748,20 @@
   memcpy (&(get_result->source_peer), source_peer, sizeof (struct 
GNUNET_PeerIdentity));
   get_result->expiration_time = expiration;
   
-  get_result_path = (struct GNUNET_PeerIdentity *)&get_result[1];
-  memcpy (get_result_path, get_path,
-          sizeof (struct GNUNET_PeerIdentity) * get_path_length);
+  if (get_path_length != 0)
+  {
+    get_result_path = (struct GNUNET_PeerIdentity *)&get_result[1];
+    memcpy (get_result_path, get_path,
+            sizeof (struct GNUNET_PeerIdentity) * get_path_length);
+  }
   memcpy (&get_result_path[get_path_length], data, data_size);
+  
   /* FIXME: Is this correct? */
-  pp = (struct GNUNET_PeerIdentity *)&get_result_path[1];
-  memcpy (pp, put_path,sizeof (struct GNUNET_PeerIdentity) * put_path_length);
-  
+  if (put_path_length != 0)
+  {
+    pp = (struct GNUNET_PeerIdentity *)&get_result_path[1];
+    memcpy (pp, put_path,sizeof (struct GNUNET_PeerIdentity) * 
put_path_length);
+  }
   target_friend = GNUNET_CONTAINER_multipeermap_get (friend_peermap, next_hop);
   GNUNET_CONTAINER_DLL_insert_tail (target_friend->head, target_friend->tail, 
pending);
   target_friend->pending_count++;
@@ -2960,7 +2958,7 @@
     next_hop = find_successor (key_value, &current_destination, 
&current_source); 
   }
   
-  if (NULL == next_hop) /* I am the final destination */
+  if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, next_hop)) /* I am 
the final destination */
   {
     GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put->expiration_time),
                               &(put->key),putlen, pp, ntohl (put->block_type), 
@@ -3036,6 +3034,7 @@
     GNUNET_break_op (0);
     return GNUNET_YES; 
   }
+
   /* Add sender to get path */
   struct GNUNET_PeerIdentity gp[get_length + 1];
   memcpy (gp, get_path, get_length * sizeof (struct GNUNET_PeerIdentity));
@@ -3053,21 +3052,22 @@
   }
   else
   {
-    next_hop = find_successor (key_value, &current_destination, 
&current_source); 
+    next_hop = find_successor (key_value, &current_destination, 
&current_source);  
   }
   
-  if (NULL == next_hop)
+  if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, next_hop))
   {
-    /* FIXME: Try to make this code also short and remove useless variables. */
+    /* I am the destination.*/
     struct GNUNET_PeerIdentity final_get_path[get_length+1];
+    struct GNUNET_PeerIdentity next_hop;
+
     memcpy (final_get_path, gp, get_length * sizeof (struct 
GNUNET_PeerIdentity));
     memcpy (&final_get_path[get_length+1], &my_identity, sizeof (struct 
GNUNET_PeerIdentity));
     get_length = get_length + 1;
-    struct GNUNET_PeerIdentity *next_hop;
-    next_hop = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
-    memcpy (next_hop, &final_get_path[get_length-2], sizeof (struct 
GNUNET_PeerIdentity));
+    memcpy (&next_hop, &final_get_path[get_length-2], sizeof (struct 
GNUNET_PeerIdentity));
+   
     GDS_DATACACHE_handle_get (&(get->key),(get->block_type), NULL, 0, NULL, 0,
-                              get_length, final_get_path,next_hop, 
&my_identity);
+                              get_length, final_get_path,&next_hop, 
&my_identity);
 
     return GNUNET_YES;
   }
@@ -3076,13 +3076,12 @@
     GDS_NEIGHBOURS_send_get (&(get->key), get->block_type, get->options, 
                              
get->desired_replication_level,current_destination,
                              current_source, next_hop, 0,
-                             get_length, gp);
+                             get_length, gp);  
   }
   return GNUNET_SYSERR;
 }
 
 
-
 /**
  * FIXME: In case of trail, we don't have source and destination part of the 
trail,
  * Check if we follow the same in case of get/put/get_result. Also, in case of 
@@ -3289,7 +3288,7 @@
     {
        /* FIXME: Is this correct assumption? A peer which think I am its 
predecessor,
           then I am not its predecessor. */
-       compare_and_update_predecessor (&source, trail_peer_list, trail_length 
);
+      compare_and_update_predecessor (&source, trail_peer_list, trail_length );
     }
     GDS_NEIGHBOURS_send_trail_setup_result (&source,
                                             &(my_identity),
@@ -3475,7 +3474,8 @@
     GNUNET_break_op (0);
     return GNUNET_YES;
   }
-  trail_peer_list = (const struct GNUNET_PeerIdentity *)&vsm[1];
+  if (trail_length > 0)
+    trail_peer_list = (const struct GNUNET_PeerIdentity *)&vsm[1];
   memcpy (&source_peer, &(vsm->source_peer), sizeof(struct 
GNUNET_PeerIdentity));
   
   if(0 == (GNUNET_CRYPTO_cmp_peer_identity (&(vsm->successor),&my_identity)))
@@ -3518,7 +3518,7 @@
       struct TrailPeerList *iterator;
       int new_trail_length;
       int i;
-     
+
       new_trail_length = trail_length + my_predecessor->first_trail_length + 1;
       new_successor_trail = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity) 
* new_trail_length);
       if (trail_length > 0)
@@ -3538,7 +3538,6 @@
           i++;
         }
       }
-
       GDS_NEIGHBOURS_send_verify_successor_result (&source_peer,
                                                    &(my_identity),
                                                    
&(my_predecessor->finger_identity),




reply via email to

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