gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r8758 - GNUnet/src/applications/dv_dht/module


From: gnunet
Subject: [GNUnet-SVN] r8758 - GNUnet/src/applications/dv_dht/module
Date: Mon, 20 Jul 2009 14:54:51 -0600

Author: nevans
Date: 2009-07-20 14:54:51 -0600 (Mon, 20 Jul 2009)
New Revision: 8758

Modified:
   GNUnet/src/applications/dv_dht/module/routing.c
   GNUnet/src/applications/dv_dht/module/table.c
Log:
straight kademlia style routing, dv hops recorded

Modified: GNUnet/src/applications/dv_dht/module/routing.c
===================================================================
--- GNUnet/src/applications/dv_dht/module/routing.c     2009-07-19 13:12:03 UTC 
(rev 8757)
+++ GNUnet/src/applications/dv_dht/module/routing.c     2009-07-20 20:54:51 UTC 
(rev 8758)
@@ -348,6 +348,7 @@
   unsigned int tracked;
   unsigned int i;
   int match;
+  int cost;
   DV_DHT_Source_Route *pos;
   DV_DHT_Source_Route *prev;
 #if DEBUG_ROUTING
@@ -470,15 +471,6 @@
                              GNUNET_GE_USER | GNUNET_GE_BULK,
                              "Routing result to `%s'\n", &enc);
 #endif
-              if ((debug_routes_extended) && (dhtlog != NULL))
-                {
-                  queryuid = ntohl (result->queryuid);
-                  dhtlog->insert_route (NULL, queryuid,
-                                        DHTLOG_RESULT,
-                                        ntohl (result->hop_count), GNUNET_NO,
-                                        coreAPI->my_identity, key, NULL,
-                                        &pos->source);
-                }
               match = GNUNET_NO;
               match = GNUNET_bloomfilter_test (bloom, &pos->source.hashPubKey);
               if (match == GNUNET_YES)
@@ -486,9 +478,21 @@
                 pos = pos->next;
                 continue;
               }
-              dvapi->dv_send (&pos->source,
+
+              cost = dvapi->dv_send (&pos->source,
                               &result->header, DV_DHT_PRIORITY, DV_DHT_DELAY);
 
+
+              if ((debug_routes_extended) && (dhtlog != NULL))
+                {
+                  queryuid = ntohl (result->queryuid);
+                  dhtlog->insert_route (NULL, queryuid,
+                                        DHTLOG_RESULT,
+                                        ntohl (result->hop_count), cost, 
GNUNET_NO,
+                                        coreAPI->my_identity, key, NULL,
+                                        &pos->source);
+                }
+
               if (stats != NULL)
                 stats->change (stat_replies_routed, 1);
             }
@@ -515,7 +519,7 @@
                   queryuid = ntohl (result->queryuid);
                   dhtlog->insert_route (NULL, queryuid,
                                         DHTLOG_RESULT,
-                                        ntohl (result->hop_count), GNUNET_YES,
+                                        ntohl (result->hop_count), 0, 
GNUNET_YES,
                                         coreAPI->my_identity, key, NULL,
                                         NULL);
                 }
@@ -632,6 +636,7 @@
   int total;
   int i;
   int j;
+  int cost;
 #if DEBUG_ROUTING
   GNUNET_EncName enc;
   GNUNET_EncName henc;
@@ -701,7 +706,7 @@
         {
           queryuid = ntohl (get->queryuid);
           dhtlog->insert_route (NULL, ntohl (get->queryuid), DHTLOG_GET,
-                                hop_count, GNUNET_YES, coreAPI->my_identity,
+                                hop_count, 0, GNUNET_YES, coreAPI->my_identity,
                                 &get->key, sender, NULL);
         }
     }
@@ -747,9 +752,9 @@
                          GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER
                          | GNUNET_GE_BULK,
                          "Failed to select peer for fowarding in round 
%d/%d\n",
-                         i + 1, GET_TRIES);
+                         i + 1, target_value);
 #endif
-          break;
+          continue;
         }
 #if DEBUG_ROUTING
       GNUNET_hash_to_enc (&next[j].hashPubKey, &enc);
@@ -758,15 +763,15 @@
                      GNUNET_GE_BULK,
                      "Forwarding DV_DHT GET request to peer `%s'.\n", &enc);
 #endif
+
+      cost = dvapi->dv_send (&next[j], &aget.header, DV_DHT_PRIORITY, 
DV_DHT_DELAY);
       if ((debug_routes_extended) && (dhtlog != NULL))
         {
           queryuid = ntohl (get->queryuid);
           dhtlog->insert_route (NULL, ntohl (get->queryuid), DHTLOG_GET,
-                                hop_count, GNUNET_NO, coreAPI->my_identity,
+                                hop_count, cost, GNUNET_NO, 
coreAPI->my_identity,
                                 &get->key, sender, &next[j]);
         }
-
-      dvapi->dv_send (&next[j], &aget.header, DV_DHT_PRIORITY, DV_DHT_DELAY);
       j++;
     }
 
@@ -790,6 +795,7 @@
   unsigned int target_value;
   int store;
   int i;
+  int cost;
   unsigned int j;
 #if DEBUG_ROUTING
   GNUNET_EncName enc;
@@ -841,8 +847,8 @@
           GNUNET_GE_LOG (coreAPI->ectx,
                          GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER
                          | GNUNET_GE_BULK,
-                         "Failed to select peer for PUT fowarding in round 
%d/%d\n",
-                         i + 1, PUT_TRIES);
+                         "Failed to select peer for PUT forwarding in round 
%d/%d\n",
+                         i + 1, target_value);
 #endif
           continue;
         }
@@ -853,15 +859,25 @@
                      GNUNET_GE_BULK,
                      "Forwarding DV_DHT PUT request to peer `%s'.\n", &enc);
 #endif
+      cost = dvapi->dv_send (&next[j], &aput->header, DV_DHT_PRIORITY, 
DV_DHT_DELAY);
+#if DEBUG_ROUTING
+  if (cost == GNUNET_SYSERR)
+  {
+      GNUNET_hash_to_enc (&next[j].hashPubKey, &enc);
+      GNUNET_GE_LOG (coreAPI->ectx,
+                     GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
+                     GNUNET_GE_BULK,
+                     "Forwarding DV_DHT PUT request FAILED (dv unknown) to 
peer `%s'.\n", &enc);
+  }
+#endif
       if ((debug_routes_extended) && (dhtlog != NULL))
         {
           queryuid = ntohl (put->queryuid);
           dhtlog->insert_route (NULL, queryuid, DHTLOG_PUT,
-                                hop_count, GNUNET_NO,
+                                hop_count, cost, GNUNET_NO,
                                 coreAPI->my_identity, &put->key, sender,
                                 &next[j]);
         }
-      dvapi->dv_send (&next[j], &aput->header, DV_DHT_PRIORITY, DV_DHT_DELAY);
       j++;
     }
 
@@ -877,7 +893,7 @@
     {
       queryuid = ntohl (put->queryuid);
       dhtlog->insert_route (NULL, queryuid, DHTLOG_PUT,
-                            hop_count, GNUNET_NO,
+                            hop_count, 0, GNUNET_NO,
                             coreAPI->my_identity, &put->key, sender, NULL);
     }
 
@@ -905,7 +921,7 @@
         {
           queryuid = ntohl (put->queryuid);
           dhtlog->insert_route (NULL, queryuid, DHTLOG_PUT,
-                                hop_count, GNUNET_YES,
+                                hop_count, 0, GNUNET_YES,
                                 coreAPI->my_identity, &put->key, sender,
                                 NULL);
         }

Modified: GNUnet/src/applications/dv_dht/module/table.c
===================================================================
--- GNUnet/src/applications/dv_dht/module/table.c       2009-07-19 13:12:03 UTC 
(rev 8757)
+++ GNUnet/src/applications/dv_dht/module/table.c       2009-07-20 20:54:51 UTC 
(rev 8758)
@@ -421,6 +421,7 @@
                            struct GNUNET_BloomFilter *bloom)
 {
   unsigned long long total_distance;
+  unsigned long long largest_distance;
   unsigned long long selected;
   unsigned int distance;
   unsigned int bc;
@@ -429,9 +430,54 @@
   int match;
   const PeerBucket *bucket;
   const PeerInfo *pi;
+  const PeerInfo *chosen;
 
-  //return find_closest_peer(set, target);
   GNUNET_mutex_lock (lock);
+  largest_distance = 0;
+  total_distance = 0;
+  for (bc = 0; bc < bucketCount; bc++)
+    {
+      bucket = &buckets[bc];
+      for (ec = 0; ec < bucket->peers_size; ec++)
+        {
+          pi = bucket->peers[ec];
+          match = GNUNET_NO;
+          match = GNUNET_bloomfilter_test (bloom, &pi->id.hashPubKey);
+          if (match == GNUNET_YES)
+            {
+              continue;
+            }
+          for (i = 0; i < blocked_size; i++)
+            {
+              if (0 ==
+                  memcmp (&pi->id, &blocked[i], sizeof (GNUNET_PeerIdentity)))
+                {
+                  match = GNUNET_YES;
+                  break;
+                }
+            }
+          if (match == GNUNET_YES)
+            continue;
+
+          if (inverse_distance (target, &pi->id.hashPubKey) >
+              largest_distance)
+            {
+              chosen = bucket->peers[ec];
+              largest_distance = inverse_distance (target, &pi->id.hashPubKey);
+            }
+        }
+    }
+
+  GNUNET_mutex_unlock (lock);
+  if ((largest_distance > 0) && (chosen != NULL))
+    {
+      *set = chosen->id;
+      return GNUNET_OK;
+    }
+  else
+    return GNUNET_SYSERR;
+
+  GNUNET_mutex_lock (lock);
   if (stats != NULL)
     stats->change (stat_dht_route_looks, 1);
   total_distance = 0;
@@ -536,7 +582,10 @@
           pi = bucket->peers[ec];
           if (inverse_distance (target, &pi->id.hashPubKey) >
               largest_distance)
-            chosen = bucket->peers[ec];
+            {
+              chosen = bucket->peers[ec];
+              largest_distance = inverse_distance (target, &pi->id.hashPubKey);
+            }
         }
     }
 
@@ -605,8 +654,11 @@
 {
 
   GNUNET_PeerIdentity closest;
+  memset(&closest, 0, sizeof(GNUNET_PeerIdentity));
+  find_closest_peer (&closest, target);
+  if (&closest == NULL)
+    return GNUNET_SYSERR;
 
-  find_closest_peer (&closest, target);
   GNUNET_GE_LOG (coreAPI->ectx,
                  GNUNET_GE_WARNING | GNUNET_GE_ADMIN | GNUNET_GE_USER |
                  GNUNET_GE_BULK, "closest peer\n");
@@ -626,8 +678,8 @@
                  inverse_distance (target, &closest.hashPubKey),
                  inverse_distance (target,
                                    &coreAPI->my_identity->hashPubKey));
-  if (inverse_distance (target, &coreAPI->my_identity->hashPubKey) >
-      inverse_distance (target, &closest.hashPubKey))
+  if (inverse_distance (target, &coreAPI->my_identity->hashPubKey) >=
+      inverse_distance (target, &closest.hashPubKey) && (inverse_distance 
(target, &coreAPI->my_identity->hashPubKey) > 0))
     {
       return GNUNET_YES;
     }





reply via email to

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