xdht: track topology successor and predecessor neighbours.
authorSree Harsha Totakura <totakura@in.tum.de>
Thu, 24 Jul 2014 15:18:37 +0000 (15:18 +0000)
committerSree Harsha Totakura <totakura@in.tum.de>
Thu, 24 Jul 2014 15:18:37 +0000 (15:18 +0000)
src/dht/gnunet-service-xdht.c
src/dht/gnunet-service-xdht_neighbours.c

index 40aa71a0f2d0d4b9490c4b4d96145bb76b55842f..c8bc11686f5270ace66ec537bae43772418e4337 100644 (file)
@@ -77,6 +77,11 @@ static struct GNUNET_TRANSPORT_GetHelloHandle *ghh;
  */
 struct GNUNET_TIME_Relative hello_expiration;
 
+/**
+ * Should we store our topology predecessor and successor IDs into statistics?
+ */
+extern unsigned int track_topology;
+
 #if ENABLE_MALICIOUS
 /**
  * Should this peer act malicious?
@@ -153,6 +158,7 @@ static void
 run (void *cls, struct GNUNET_SERVER_Handle *server,
      const struct GNUNET_CONFIGURATION_Handle *c)
 {
+  unsigned long long _track_topology;
   GDS_cfg = c;
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_time (c, "transport", "HELLO_EXPIRATION", &hello_expiration))
@@ -161,13 +167,17 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
   }
   GDS_block_context = GNUNET_BLOCK_context_create (GDS_cfg);
   GDS_stats = GNUNET_STATISTICS_create ("dht", GDS_cfg);
-
   GDS_ROUTING_init ();
   GDS_NSE_init ();
   GDS_DATACACHE_init ();
   GDS_HELLO_init ();
   GDS_CLIENTS_init (server);
-
+  if (GNUNET_OK ==
+      GNUNET_CONFIGURATION_get_value_number (c, "xdht", "track_toplogy",
+                                             &_track_topology))
+  {
+    track_topology = (unsigned int) _track_topology;
+  }
   if (GNUNET_OK != GDS_NEIGHBOURS_init ())
   {
     shutdown_task (NULL, NULL);
index 97e983b56bc534b04b5057b800de1e38a7344b57..d8b52b0e89c3c66e595e6dbb65aeb78ede4ee3c3 100644 (file)
@@ -859,6 +859,11 @@ static struct FingerInfo finger_table [MAX_FINGERS];
  */
 static struct GNUNET_CORE_Handle *core_api;
 
+/**
+ * Handle for the statistics service.
+ */
+extern struct GNUNET_STATISTICS_Handle *GDS_stats;
+
 /**
  * The current finger index that we have want to find trail to. We start the
  * search with value = 0, i.e. successor  and then go to PREDCESSOR_FINGER_ID
@@ -867,6 +872,11 @@ static struct GNUNET_CORE_Handle *core_api;
  */
 static unsigned int current_search_finger_index;
 
+/**
+ * Should we store our topology predecessor and successor IDs into statistics?
+ */
+unsigned int track_topology;
+
 
 /**
  * Called when core is ready to send a message we asked for
@@ -3386,6 +3396,22 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
                                               GDS_ROUTING_SRC_TO_DEST,
                                               finger_identity);
       }
+      /* Store the successor for path tracking */
+      if (track_topology &&  (NULL != GDS_stats) && (0 == finger_table_index))
+      {
+        char *my_id_str;
+        char *succ_id_str;
+        char *key;
+
+        my_id_str = GNUNET_strdup (GNUNET_i2s (&my_identity));
+        succ_id_str = GNUNET_strdup (GNUNET_i2s
+                                     (&existing_finger->finger_identity));
+        GNUNET_asprintf (&key, "XDHT:0:%.4s:%.4s", my_id_str, succ_id_str);
+        GNUNET_free (my_id_str);
+        GNUNET_free (succ_id_str);
+        GNUNET_STATISTICS_update (GDS_stats, "key", 1, 0);
+        GNUNET_free (key);
+      }
     }
   }
   else
@@ -5653,4 +5679,4 @@ GDS_NEIGHBOURS_get_my_id (void)
   return my_identity;
 }
 
-/* end of gnunet-service-xdht_neighbours.c */
\ No newline at end of file
+/* end of gnunet-service-xdht_neighbours.c */