+ if (0 != n_dht)
+ return;
+ if (GNUNET_YES == in_shutdown)
+ return;
+ switch (mode)
+ {
+ case MODE_PUT:
+ if ((n_puts_ok + n_puts_fail) != n_active)
+ return;
+ /* Start GETs if all PUTs have been made */
+ mode = MODE_GET;
+ //(void) GNUNET_SCHEDULER_add_now (&call_start_profiling, NULL);
+ start_profiling ();
+ return;
+ case MODE_GET:
+ if ((n_gets_ok + n_gets_fail) != n_active)
+ return;
+ break;
+ }
+}
+
+/**
+ * Connect to DHT services of active peers
+ */
+static void
+start_profiling()
+{
+ struct Context *ctx;
+ unsigned int i;
+
+ DEBUG("GNUNET_TESTBED_service_connect \n");
+ GNUNET_break (GNUNET_YES != in_shutdown);
+ for(i = 0; i < n_active; i++)
+ {
+ struct ActiveContext *ac = &a_ac[i];
+ GNUNET_assert (NULL != (ctx = ac->ctx));
+ GNUNET_assert (NULL == ctx->op);
+ ctx->op =
+ GNUNET_TESTBED_service_connect (ctx,
+ ctx->peer,
+ "dht",
+ &dht_connected, ac,
+ &dht_connect,
+ &dht_disconnect,
+ ac);
+ }
+}
+
+#if ENABLE_MALICIOUS
+/**
+ * Count of total number of malicious peers.
+ */
+static unsigned int count_malicious;
+
+/**
+ * Continuation of GNUNET_DHT_act_malicious
+ * @param cls Malicious context
+ * @param success #GNUNET_OK if the ACT_MALICIOUS was transmitted,
+ * #GNUNET_NO on timeout,
+ * #GNUNET_SYSERR on disconnect from service
+ * after the ACT_MALICIOUS message was transmitted
+ * (so we don't know if it was received or not)
+ */
+static void
+act_malicious_cont (void *cls, int success)
+{
+ struct MaliciousContext *mc = cls;
+ struct Context *ctx = mc->ctx;
+
+ GNUNET_TESTBED_operation_done (ctx->op);
+ ctx->op = NULL;
+ return;
+}
+
+
+/**
+ * Call malicious API for all the malicious peers.
+ * @param cls the malicious context.
+ * @param op the operation that has been finished
+ * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
+ * @param emsg error message in case the operation has failed; will be NULL if
+ * operation has executed successfully.
+ */
+static void
+dht_set_malicious(void *cls,
+ struct GNUNET_TESTBED_Operation *op,
+ void *ca_result,
+ const char *emsg)
+{
+ struct MaliciousContext *mc = cls;
+ struct Context *ctx = mc->ctx;
+
+ GNUNET_assert (NULL != ctx);
+ GNUNET_assert (NULL != ctx->op);
+ GNUNET_assert (ctx->op == op);
+ mc->dht = (struct GNUNET_DHT_Handle *) ca_result;
+ if (NULL != emsg)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connection to DHT service failed: %s\n", emsg);
+ GNUNET_TESTBED_operation_done (ctx->op); /* Calls dht_disconnect_malicious() */
+ ctx->op = NULL;
+ return;
+ }
+ mc->dht_malicious = GNUNET_DHT_act_malicious(mc->dht, 1, act_malicious_cont, mc);