+/**
+ * Process successor statistic values.
+ *
+ * @param cls closure
+ * @param peer the peer the statistic belong to
+ * @param subsystem name of subsystem that created the statistic
+ * @param name the name of the datum
+ * @param value the current value
+ * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
+ * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
+ */
+static int
+successor_stats_iterator (void *cls,
+ const struct GNUNET_TESTBED_Peer *peer,
+ const char *subsystem,
+ const char *name,
+ uint64_t value,
+ int is_persistent)
+{
+ static const char *key_string = "XDHT";
+ if (0 == strncmp (key_string, name, strlen (key_string)))
+ {
+ char *my_id_str;
+ char successor_str[13];
+ char truncated_my_id_str[13];
+ char truncated_successor_str[13];
+ struct GNUNET_HashCode *my_id_key;
+ struct GNUNET_HashCode *succ_key;
+
+ strtok((char *)name,":");
+ my_id_str = strtok(NULL,":");
+
+ strncpy(truncated_my_id_str, my_id_str, 12);
+ truncated_my_id_str[12] = '\0';
+ my_id_key = GNUNET_new(struct GNUNET_HashCode);
+ GNUNET_CRYPTO_hash (truncated_my_id_str, sizeof(truncated_my_id_str),my_id_key);
+ GNUNET_STRINGS_data_to_string(&value, sizeof(uint64_t), successor_str, 13);
+ strncpy(truncated_successor_str, successor_str, 12);
+ truncated_successor_str[12] ='\0';
+
+ succ_key = GNUNET_new(struct GNUNET_HashCode);
+ GNUNET_CRYPTO_hash (truncated_successor_str, sizeof(truncated_successor_str),succ_key);
+
+ if (0 == flag)
+ {
+ start_key = my_id_key;
+ flag = 1;
+ }
+ /* FIXME: GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE do not free the value
+ which is replaced, need to free it. */
+ GNUNET_CONTAINER_multihashmap_put (successor_peer_hashmap,
+ my_id_key, (void *)succ_key,
+ GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
+ }
+ return GNUNET_OK;
+}
+
+
+/*
+ * Task that collects peer and its corresponding successors.
+ *
+ * @param cls Closure (NULL).
+ * @param tc Task Context.
+ */
+static void
+collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
+ return;
+
+ GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start collecting statistics...\n");
+ GNUNET_assert(NULL != testbed_handles);
+ successor_stats_op =
+ GNUNET_TESTBED_get_statistics (num_peers, testbed_handles,
+ "dht", NULL,
+ successor_stats_iterator,
+ successor_stats_cont, cls);
+
+ GNUNET_assert(NULL != successor_stats_op);
+}
+
+
+#if ENABLE_MALICIOUS
+/**
+ * Set the malicious variable in peer malicious context.
+ */
+static void
+set_malicious()
+{
+ unsigned int i;
+ DEBUG ("Setting %u peers malicious");
+ for(i = 0; i < n_malicious; i++)
+ {
+ struct MaliciousContext *mc = &a_mc[i];
+ mc->ctx->op =
+ GNUNET_TESTBED_service_connect (ac->ctx,
+ ac->ctx->peer,
+ "dht",
+ &dht_set_malicious, mc,
+ &dht_connect,
+ &dht_finish,
+ mc);
+ }
+}
+#endif