gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r34340 - gnunet/src/dht
Date: Sun, 5 Oct 2014 13:34:32 +0200

Author: grothoff
Date: 2014-10-05 13:34:32 +0200 (Sun, 05 Oct 2014)
New Revision: 34340

Modified:
   gnunet/src/dht/gnunet-service-xdht_neighbours.c
   gnunet/src/dht/gnunet-service-xdht_neighbours.h
   gnunet/src/dht/gnunet-service-xdht_routing.c
Log:
-remove superflous semicolon causing branch to be always taken and significant 
logic to be omitted; pass pointers to HashCode and PeerIdentities instead of 
making copies

Modified: gnunet/src/dht/gnunet-service-xdht_neighbours.c
===================================================================
--- gnunet/src/dht/gnunet-service-xdht_neighbours.c     2014-10-05 11:29:50 UTC 
(rev 34339)
+++ gnunet/src/dht/gnunet-service-xdht_neighbours.c     2014-10-05 11:34:32 UTC 
(rev 34340)
@@ -1398,14 +1398,15 @@
  * the pointer to friend in routing table rather than gnunet_peeridentity.
  * if yes then we should keep friend info in.h  andmake lot of changes.
  * Construct a trail teardown message and forward it to target friend.
+ *
  * @param trail_id Unique identifier of the trail.
  * @param trail_direction Direction of trail.
  * @param target_friend Friend to get this message.
  */
 void
-GDS_NEIGHBOURS_send_trail_teardown (struct GNUNET_HashCode trail_id,
+GDS_NEIGHBOURS_send_trail_teardown (const struct GNUNET_HashCode *trail_id,
                                     unsigned int trail_direction,
-                                    struct GNUNET_PeerIdentity peer)
+                                    const struct GNUNET_PeerIdentity *peer)
 {
   struct PeerTrailTearDownMessage *ttdm;
   struct P2PPendingMessage *pending;
@@ -1413,17 +1414,19 @@
   size_t msize;
 
   msize = sizeof (struct PeerTrailTearDownMessage);
-
   if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE)
   {
     GNUNET_break (0);
     return;
   }
 
-  /*FIXME:In what case friend can be null. ?*/
   if (NULL == (target_friend =
-                 GNUNET_CONTAINER_multipeermap_get (friend_peermap, &peer)));
-  return;
+               GNUNET_CONTAINER_multipeermap_get (friend_peermap, peer)))
+  {
+    /* FIXME: In what case friend can be null. ?*/
+    GNUNET_break (0);
+    return;
+  }
 
   if (target_friend->pending_count >= MAXIMUM_PENDING_PER_FRIEND)
   {
@@ -1438,7 +1441,7 @@
   pending->msg = &ttdm->header;
   ttdm->header.size = htons (msize);
   ttdm->header.type = htons (GNUNET_MESSAGE_TYPE_XDHT_P2P_TRAIL_TEARDOWN);
-  ttdm->trail_id = trail_id;
+  ttdm->trail_id = *trail_id;
   ttdm->trail_direction = htonl (trail_direction);
 
   /* Send the message to chosen friend. */
@@ -2765,9 +2768,9 @@
   {
     next_hop = GDS_ROUTING_get_next_hop (new_trail_id, 
GDS_ROUTING_SRC_TO_DEST);
     GDS_ROUTING_remove_trail (new_trail_id);
-    GDS_NEIGHBOURS_send_trail_teardown (new_trail_id,
+    GDS_NEIGHBOURS_send_trail_teardown (&new_trail_id,
                                         GDS_ROUTING_SRC_TO_DEST,
-                                        *next_hop);
+                                        next_hop);
     return;
   }
 
@@ -2775,9 +2778,9 @@
   struct Trail *replace_trail = &finger->trail_list[largest_trail_index];
   next_hop = GDS_ROUTING_get_next_hop (replace_trail->trail_id, 
GDS_ROUTING_SRC_TO_DEST);
   GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail 
(replace_trail->trail_id));
-  GDS_NEIGHBOURS_send_trail_teardown (replace_trail->trail_id,
+  GDS_NEIGHBOURS_send_trail_teardown (&replace_trail->trail_id,
                                       GDS_ROUTING_SRC_TO_DEST,
-                                      *next_hop);
+                                      next_hop);
 
   /* Free the trail. */
   while (NULL != (trail_element = replace_trail->trail_head))
@@ -3042,9 +3045,9 @@
   }
   GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (trail->trail_id));
   friend->trails_count--;
-  GDS_NEIGHBOURS_send_trail_teardown (trail->trail_id,
+  GDS_NEIGHBOURS_send_trail_teardown (&trail->trail_id,
                                       GDS_ROUTING_SRC_TO_DEST,
-                                      friend->id);
+                                      &friend->id);
 }
 
 
@@ -3597,13 +3600,13 @@
       if (0 != GNUNET_CRYPTO_cmp_peer_identity (&finger_identity, 
&my_identity))
       {
         if (finger_trail_length > 0)
-          GDS_NEIGHBOURS_send_trail_teardown (finger_trail_id,
+          GDS_NEIGHBOURS_send_trail_teardown (&finger_trail_id,
                                               GDS_ROUTING_SRC_TO_DEST,
-                                              finger_trail[0]);
+                                              &finger_trail[0]);
         else
-          GDS_NEIGHBOURS_send_trail_teardown (finger_trail_id,
+          GDS_NEIGHBOURS_send_trail_teardown (&finger_trail_id,
                                               GDS_ROUTING_SRC_TO_DEST,
-                                              finger_identity);
+                                              &finger_identity);
       }
     }
   }
@@ -5786,7 +5789,7 @@
     /* If not final destination, then send a trail teardown message to next 
hop.*/
     GNUNET_assert (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, 
next_hop));
     GNUNET_assert (GNUNET_YES == GDS_ROUTING_remove_trail (trail_id));
-    GDS_NEIGHBOURS_send_trail_teardown (trail_id, trail_direction, *next_hop);
+    GDS_NEIGHBOURS_send_trail_teardown (&trail_id, trail_direction, next_hop);
   }
 
   return GNUNET_OK;

Modified: gnunet/src/dht/gnunet-service-xdht_neighbours.h
===================================================================
--- gnunet/src/dht/gnunet-service-xdht_neighbours.h     2014-10-05 11:29:50 UTC 
(rev 34339)
+++ gnunet/src/dht/gnunet-service-xdht_neighbours.h     2014-10-05 11:34:32 UTC 
(rev 34340)
@@ -42,7 +42,7 @@
 #endif
 
 /**
- * Handle the put request from the client. 
+ * Handle the put request from the client.
  * @param key Key for the content
  * @param block_type Type of the block
  * @param options Routing options
@@ -60,15 +60,15 @@
                            const void *data, size_t data_size);
 
 /**
- * Handle the get request from the client file. If I am destination do 
+ * Handle the get request from the client file. If I am destination do
  * datacache put and return. Else find the target friend and forward message
- * to it. 
+ * to it.
  * @param key Key for the content
  * @param block_type Type of the block
  * @param options Routing options
  * @param desired_replication_level Desired replication count
  */
-void 
+void
 GDS_NEIGHBOURS_handle_get(const struct GNUNET_HashCode *key,
                           enum GNUNET_BLOCK_Type block_type,
                           enum GNUNET_DHT_RouteOption options,
@@ -101,15 +101,15 @@
                                 const void *data, size_t data_size);
 
 /**
- * Construct a trail teardown message and forward it to target friend. 
+ * Construct a trail teardown message and forward it to target friend.
  * @param trail_id Unique identifier of the trail.
  * @param trail_direction Direction of trail.
  * @param target_friend Friend to get this message.
  */
 void
-GDS_NEIGHBOURS_send_trail_teardown (struct GNUNET_HashCode trail_id,
+GDS_NEIGHBOURS_send_trail_teardown (const struct GNUNET_HashCode *trail_id,
                                     unsigned int trail_direction,
-                                    struct GNUNET_PeerIdentity peer);
+                                    const struct GNUNET_PeerIdentity *peer);
 
 /**
  * Return friend corresponding to peer.
@@ -121,7 +121,7 @@
 /**
  * Initialize neighbours subsystem.
  *
- * @return #GNUNET_OK on success, 
+ * @return #GNUNET_OK on success,
  *         #GNUNET_SYSERR on error
  */
 int
@@ -140,7 +140,7 @@
  *
  * @return my identity
  */
-struct GNUNET_PeerIdentity 
+struct GNUNET_PeerIdentity
 GDS_NEIGHBOURS_get_my_id (void);
 
 #endif

Modified: gnunet/src/dht/gnunet-service-xdht_routing.c
===================================================================
--- gnunet/src/dht/gnunet-service-xdht_routing.c        2014-10-05 11:29:50 UTC 
(rev 34339)
+++ gnunet/src/dht/gnunet-service-xdht_routing.c        2014-10-05 11:34:32 UTC 
(rev 34340)
@@ -31,7 +31,7 @@
 
 /**
  * FIXME: Check if its better to store pointer to friend rather than storing
- * peer identity next_hop or prev_hop. 
+ * peer identity next_hop or prev_hop.
  * keep entries in destnation and source peer also. so when we send the trail
  * teardown message then we don't know the source but if source gets the 
message
  * then it shold remove that trail id from its finger table. But how does
@@ -39,8 +39,8 @@
  * will do a lookup in routing table and if no trail id present the remove
  * that trail of the finger and if only one trail then remove the finger.
  * because of this use case of trail teardown I think trail compression
- * and trail teardown should not be merged. 
- * 2. store a pointer to friendInfo in place o peer identity. 
+ * and trail teardown should not be merged.
+ * 2. store a pointer to friendInfo in place o peer identity.
  */
 /**
  * Maximum number of entries in routing table.
@@ -48,7 +48,7 @@
 #define ROUTING_TABLE_THRESHOLD 80000
 
 /**
- * FIXME: Store friend pointer instead of peer identifier. 
+ * FIXME: Store friend pointer instead of peer identifier.
  * Routing table entry .
  */
 struct RoutingTrail
@@ -61,12 +61,12 @@
   /**
    * The peer to which this request should be passed to.
    */
-  struct GNUNET_PeerIdentity next_hop; 
+  struct GNUNET_PeerIdentity next_hop;
 
   /**
    * Peer just before next hop in the trail.
    */
-  struct GNUNET_PeerIdentity prev_hop;  
+  struct GNUNET_PeerIdentity prev_hop;
 };
 
 /**
@@ -100,7 +100,7 @@
 /**
  * Update the next hop of the trail. Call made by trail compression where
  * if you are source of the trail and now you have a new first friend, then
- * you should update the trail. 
+ * you should update the trail.
  * @param trail_id
  * @return #GNUNET_OK success
  *         #GNUNET_SYSERR in case no matching entry found in routing table.
@@ -114,7 +114,7 @@
   trail = GNUNET_CONTAINER_multihashmap_get (routing_table, &trail_id);
 
   if (NULL == trail)
-  
+
     return GNUNET_SYSERR;
 
   trail->next_hop = next_hop;
@@ -167,7 +167,7 @@
   remove_entry = GNUNET_CONTAINER_multihashmap_get (routing_table, 
&remove_trail_id);
   if (NULL == remove_entry)
     return GNUNET_NO;
-  
+
   if (GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove (routing_table,
                                                           &remove_trail_id,
                                                           remove_entry))
@@ -175,14 +175,14 @@
     GNUNET_free (remove_entry);
     return GNUNET_YES;
   }
- 
+
   return GNUNET_NO;
 }
 
 
 /**
  * Iterate over routing table and remove entries with value as part of any 
trail.
- * 
+ *
  * @param cls closure
  * @param key current public key
  * @param value value in the hash map
@@ -197,35 +197,35 @@
   struct GNUNET_PeerIdentity *disconnected_peer = cls;
   struct GNUNET_HashCode trail_id = *key;
   struct GNUNET_PeerIdentity my_identity;
-  
+
   /* If disconnected_peer is next_hop, then send a trail teardown message 
through
    * prev_hop in direction from destination to source. */
-  if (0 == GNUNET_CRYPTO_cmp_peer_identity (&remove_trail->next_hop, 
-                                            disconnected_peer)) 
+  if (0 == GNUNET_CRYPTO_cmp_peer_identity (&remove_trail->next_hop,
+                                            disconnected_peer))
   {
     my_identity = GDS_NEIGHBOURS_get_my_id ();
-    if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, 
+    if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity,
                                               &remove_trail->prev_hop))
     {
-      GDS_NEIGHBOURS_send_trail_teardown (trail_id, 
+      GDS_NEIGHBOURS_send_trail_teardown (&trail_id,
                                           GDS_ROUTING_DEST_TO_SRC,
-                                          remove_trail->prev_hop);
+                                          &remove_trail->prev_hop);
     }
   }
-  
+
   /* If disconnected_peer is prev_hop, then send a trail teardown through
    * next_hop in direction from Source to Destination. */
-  if (0 == GNUNET_CRYPTO_cmp_peer_identity (&remove_trail->prev_hop, 
+  if (0 == GNUNET_CRYPTO_cmp_peer_identity (&remove_trail->prev_hop,
                                             disconnected_peer))
   {
     my_identity = GDS_NEIGHBOURS_get_my_id ();
 
-    if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity, 
+    if (0 != GNUNET_CRYPTO_cmp_peer_identity (&my_identity,
                                               &remove_trail->next_hop))
     {
-      GDS_NEIGHBOURS_send_trail_teardown (trail_id, 
+      GDS_NEIGHBOURS_send_trail_teardown (&trail_id,
                                           GDS_ROUTING_SRC_TO_DEST,
-                                          remove_trail->next_hop);
+                                          &remove_trail->next_hop);
     }
   }
 
@@ -240,9 +240,9 @@
 #if 0
 /**
  * TEST FUNCTION
- * Remove after using. 
+ * Remove after using.
  */
-void 
+void
 GDS_ROUTING_test_print (void)
 {
   struct GNUNET_CONTAINER_MultiHashMapIterator *iter;
@@ -250,7 +250,7 @@
   struct GNUNET_PeerIdentity print_peer;
   struct GNUNET_HashCode key_ret;
   int i;
-  
+
   struct GNUNET_PeerIdentity my_identity = GDS_NEIGHBOURS_get_my_id();
   print_peer = my_identity;
    FPRINTF (stderr,_("\nSUPU ***PRINTING ROUTING TABLE ***** of 
=%s"),GNUNET_i2s(&print_peer));
@@ -275,7 +275,7 @@
 #endif
 
 /**
- * Remove every trail where peer is either next_hop or prev_hop. Also send a 
+ * Remove every trail where peer is either next_hop or prev_hop. Also send a
  * trail teardown message in direction of hop which is not disconnected.
  * @param peer Peer identity. Trail containing this peer should be removed.
  */
@@ -283,12 +283,12 @@
 GDS_ROUTING_remove_trail_by_peer (const struct GNUNET_PeerIdentity *peer)
 {
   int ret;
-  
-  
+
+
   /* No entries in my routing table. */
   if (0 == GNUNET_CONTAINER_multihashmap_size(routing_table))
     return GNUNET_YES;
-  
+
   ret = GNUNET_CONTAINER_multihashmap_iterate (routing_table,
                                                &remove_matching_trails,
                                                (void *)peer);
@@ -311,13 +311,13 @@
                  struct GNUNET_PeerIdentity next_hop)
 {
   struct RoutingTrail *new_entry;
-  
+
   new_entry = GNUNET_new (struct RoutingTrail);
   new_entry->trail_id = new_trail_id;
   new_entry->next_hop = next_hop;
   new_entry->prev_hop = prev_hop;
-  
-  
+
+
   return GNUNET_CONTAINER_multihashmap_put (routing_table,
                                             &new_trail_id, new_entry,
                                             
GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);




reply via email to

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