- verify successor result
[oweals/gnunet.git] / src / dht / gnunet-service-xdht_routing.c
index 6d14ce0295295978df00062e80349147de12031f..5830dc9f8c4eac5f7045100fad56a8d815b2bc7b 100644 (file)
@@ -44,6 +44,7 @@
 
 
 /**
+ * FIXME: Do we need a field prev_hop
  * Routing table entry .
  */
 struct RoutingTrail
@@ -58,11 +59,6 @@ struct RoutingTrail
    */
   struct GNUNET_PeerIdentity *destination;
 
-  /**
-   * The peer this request was received from.
-   */
-  struct GNUNET_PeerIdentity *previous_hop;
-
   /**
    * The peer to which this request should be passed to.
    */
@@ -80,30 +76,37 @@ static struct GNUNET_CONTAINER_MultiPeerMap *routing_table;
 /**
  * FIXME: Change the name of variable. 
  * Ensure that everywhere in this file you are using destination as the key.
+ * Do we need prev field in routing table?
  * Add a new entry to our routing table.
  * @param source peer
  * @param destintation
- * @param prev_hop
  * @param next_hop
  */
 void
 GDS_ROUTING_add (struct GNUNET_PeerIdentity *source,
                  struct GNUNET_PeerIdentity *dest,
-                 struct GNUNET_PeerIdentity *prev_hop,
                  struct GNUNET_PeerIdentity *next_hop)
 {
-    struct RoutingTrail *new_routing_entry;
-    
-    new_routing_entry = GNUNET_malloc (sizeof (struct RoutingTrail));
-    new_routing_entry->source = source;
-    new_routing_entry->previous_hop = prev_hop;
-    new_routing_entry->next_hop = next_hop;
-    new_routing_entry->destination = dest;
+  struct RoutingTrail *new_routing_entry;
     
-    GNUNET_assert (GNUNET_OK ==
-                 GNUNET_CONTAINER_multipeermap_put (routing_table,
-                                                    dest, new_routing_entry,
-                                                    GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+  /* If dest is already present in the routing table, then exit.*/
+  if (GNUNET_YES ==
+    GNUNET_CONTAINER_multipeermap_contains (routing_table,
+                                              dest))
+  {
+    GNUNET_break (0);
+    return;
+  }
+  
+  new_routing_entry = GNUNET_malloc (sizeof (struct RoutingTrail));
+  new_routing_entry->source = source;
+  new_routing_entry->next_hop = next_hop;
+  new_routing_entry->destination = dest;
+  
+  GNUNET_assert (GNUNET_OK ==
+    GNUNET_CONTAINER_multipeermap_put (routing_table,
+                                       dest, new_routing_entry,
+                                       GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
 }
 
 
@@ -112,17 +115,16 @@ GDS_ROUTING_add (struct GNUNET_PeerIdentity *source,
  * @return next hop peer id
  */
 struct GNUNET_PeerIdentity *
-GDS_Routing_search(struct GNUNET_PeerIdentity *source_peer,
-                   struct GNUNET_PeerIdentity *destination_peer,
-                   struct GNUNET_PeerIdentity *prev_hop)
+GDS_ROUTING_search(struct GNUNET_PeerIdentity *source_peer,
+                   struct GNUNET_PeerIdentity *destination_peer)
 {
-    struct RoutingTrail *trail;
-    trail = (struct RoutingTrail *)(GNUNET_CONTAINER_multipeermap_get(routing_table,destination_peer));
+  struct RoutingTrail *trail;
+  trail = (struct RoutingTrail *)(GNUNET_CONTAINER_multipeermap_get(routing_table,destination_peer));
     
-    if(trail == NULL)
-        return NULL;
+  if(trail == NULL)
+      return NULL;
     
-    return trail->next_hop;
+  return trail->next_hop;
 }
 
 
@@ -152,6 +154,7 @@ GDS_ROUTING_process (enum GNUNET_BLOCK_Type type,
                      const struct GNUNET_PeerIdentity *get_path,
                      const void *data, size_t data_size)
 {
+
 }
 
 
@@ -160,7 +163,7 @@ GDS_ROUTING_process (enum GNUNET_BLOCK_Type type,
  */
 void
 GDS_ROUTING_init ()
-{
+{ 
   routing_table = GNUNET_CONTAINER_multipeermap_create (DHT_MAX_RECENT * 4 / 3, GNUNET_NO);
 }