removed debug out
[oweals/gnunet.git] / src / dht / gnunet-dht-driver.c
1 /*
2      This file is part of GNUnet.
3      (C) 2009 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20 /**
21  * @file dht/gnunet-dht-driver.c
22  * @brief Driver for setting up a group of gnunet peers and
23  *        then issuing GETS and PUTS on the DHT.  Coarse results
24  *        are reported, fine grained results (if requested) are
25  *        logged to a (mysql) database, or to file.
26  */
27 #include "platform.h"
28 #include "gnunet_testing_lib.h"
29 #include "gnunet_core_service.h"
30 #include "gnunet_dht_service.h"
31 #include "dhtlog.h"
32
33 /* DEFINES */
34 #define VERBOSE GNUNET_NO
35
36 /* Timeout for entire driver to run */
37 #define DEFAULT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 5)
38
39 /* Timeout for waiting for (individual) replies to get requests */
40 #define DEFAULT_GET_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 90)
41
42 /* Timeout for waiting for gets to be sent to the service */
43 #define DEFAULT_GET_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
44
45 /* Timeout for waiting for puts to be sent to the service */
46 #define DEFAULT_PUT_DELAY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10)
47
48 #define DEFAULT_SECONDS_PER_PEER_START GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 45)
49
50 #define DEFAULT_TEST_DATA_SIZE 8
51
52 #define DEFAULT_MAX_OUTSTANDING_PUTS 10
53
54 #define DEFAULT_MAX_OUTSTANDING_GETS 10
55
56 #define DEFAULT_CONNECT_TIMEOUT 60
57
58 #define DEFAULT_TOPOLOGY_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 8)
59
60 /* Structs */
61
62 struct TestPutContext
63 {
64   /* This is a linked list */
65   struct TestPutContext *next;
66
67   /**
68    * Handle to the first peers DHT service (via the API)
69    */
70   struct GNUNET_DHT_Handle *dht_handle;
71
72   /**
73    *  Handle to the PUT peer daemon
74    */
75   struct GNUNET_TESTING_Daemon *daemon;
76
77   /**
78    *  Identifier for this PUT
79    */
80   uint32_t uid;
81
82   /**
83    * Task for disconnecting DHT handles
84    */
85   GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
86 };
87
88 struct TestGetContext
89 {
90   /* This is a linked list */
91   struct TestGetContext *next;
92
93   /**
94    * Handle to the first peers DHT service (via the API)
95    */
96   struct GNUNET_DHT_Handle *dht_handle;
97
98   /**
99    * Handle for the DHT get request
100    */
101   struct GNUNET_DHT_GetHandle *get_handle;
102
103   /**
104    *  Handle to the GET peer daemon
105    */
106   struct GNUNET_TESTING_Daemon *daemon;
107
108   /**
109    *  Identifier for this GET
110    */
111   uint32_t uid;
112
113   /**
114    * Task for disconnecting DHT handles (and stopping GET)
115    */
116   GNUNET_SCHEDULER_TaskIdentifier disconnect_task;
117
118   /**
119    * Whether or not this request has been fulfilled already.
120    */
121   int succeeded;
122 };
123
124 /**
125  * Simple struct to keep track of progress, and print a
126  * nice little percentage meter for long running tasks.
127  */
128 struct ProgressMeter
129 {
130   unsigned int total;
131
132   unsigned int modnum;
133
134   unsigned int dotnum;
135
136   unsigned int completed;
137
138   int print;
139
140   char *startup_string;
141 };
142
143 /* Globals */
144
145 /**
146  * Timeout to let all get requests happen.
147  */
148 static struct GNUNET_TIME_Relative all_get_timeout;
149
150 /**
151  * Per get timeout
152  */
153 static struct GNUNET_TIME_Relative get_timeout;
154
155 static struct GNUNET_TIME_Relative get_delay;
156
157 static struct GNUNET_TIME_Relative put_delay;
158
159 static struct GNUNET_TIME_Relative seconds_per_peer_start;
160
161 static unsigned long long test_data_size = DEFAULT_TEST_DATA_SIZE;
162
163 static unsigned long long max_outstanding_puts = DEFAULT_MAX_OUTSTANDING_PUTS;
164
165 static unsigned long long max_outstanding_gets = DEFAULT_MAX_OUTSTANDING_GETS;
166
167 static unsigned long long malicious_getters;
168
169 static unsigned long long malicious_putters;
170
171 static unsigned long long malicious_droppers;
172
173 static unsigned long long settle_time;
174
175 static struct GNUNET_DHTLOG_Handle *dhtlog_handle;
176
177 static unsigned long long trialuid;
178
179 /**
180  * List of GETS to perform
181  */
182 struct TestGetContext *all_gets;
183
184 /**
185  * List of PUTS to perform
186  */
187 struct TestPutContext *all_puts;
188
189 /**
190  * Directory to store temporary data in, defined in config file
191  */
192 static char *test_directory;
193
194 /**
195  * Variable used to store the number of connections we should wait for.
196  */
197 static unsigned int expected_connections;
198
199 /**
200  * Variable used to keep track of how many peers aren't yet started.
201  */
202 static unsigned long long peers_left;
203
204 /**
205  * Handle to the set of all peers run for this test.
206  */
207 static struct GNUNET_TESTING_PeerGroup *pg;
208
209 /**
210  * Global scheduler, used for all GNUNET_SCHEDULER_* functions.
211  */
212 static struct GNUNET_SCHEDULER_Handle *sched;
213
214 /**
215  * Total number of peers to run, set based on config file.
216  */
217 static unsigned long long num_peers;
218
219 /**
220  * Total number of items to insert.
221  */
222 static unsigned long long num_puts;
223
224 /**
225  * Total number of items to attempt to get.
226  */
227 static unsigned long long num_gets;
228
229 /**
230  * How many puts do we currently have in flight?
231  */
232 static unsigned long long outstanding_puts;
233
234 /**
235  * How many puts are done?
236  */
237 static unsigned long long puts_completed;
238
239 /**
240  * How many puts do we currently have in flight?
241  */
242 static unsigned long long outstanding_gets;
243
244 /**
245  * How many gets are done?
246  */
247 static unsigned long long gets_completed;
248
249 /**
250  * How many gets failed?
251  */
252 static unsigned long long gets_failed;
253
254 /**
255  * Global used to count how many connections we have currently
256  * been notified about (how many times has topology_callback been called
257  * with success?)
258  */
259 static unsigned int total_connections;
260
261 /**
262  * Global used to count how many failed connections we have
263  * been notified about (how many times has topology_callback
264  * been called with failure?)
265  */
266 static unsigned int failed_connections;
267
268 /* Task handle to use to schedule shutdown if something goes wrong */
269 GNUNET_SCHEDULER_TaskIdentifier die_task;
270
271 static char *blacklist_transports;
272
273 static enum GNUNET_TESTING_Topology topology;
274
275 static enum GNUNET_TESTING_Topology blacklist_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* Don't do any blacklisting */
276
277 static enum GNUNET_TESTING_Topology connect_topology = GNUNET_TESTING_TOPOLOGY_NONE; /* NONE actually means connect all allowed peers */
278
279 static enum GNUNET_TESTING_TopologyOption connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL;
280
281 static double connect_topology_option_modifier = 0.0;
282
283 static struct ProgressMeter *hostkey_meter;
284
285 static struct ProgressMeter *peer_start_meter;
286
287 static struct ProgressMeter *peer_connect_meter;
288
289 static struct ProgressMeter *put_meter;
290
291 static struct ProgressMeter *get_meter;
292
293 /* Global return value (0 for success, anything else for failure) */
294 static int ok;
295
296 /**
297  * Create a meter to keep track of the progress of some task.
298  *
299  * @param total the total number of items to complete
300  * @param start_string a string to prefix the meter with (if printing)
301  * @param print GNUNET_YES to print the meter, GNUNET_NO to count
302  *              internally only
303  *
304  * @return the progress meter
305  */
306 static struct ProgressMeter *
307 create_meter(unsigned int total, char * start_string, int print)
308 {
309   struct ProgressMeter *ret;
310   ret = GNUNET_malloc(sizeof(struct ProgressMeter));
311   ret->print = print;
312   ret->total = total;
313   ret->modnum = total / 4;
314   ret->dotnum = (total / 50) + 1;
315   if (start_string != NULL)
316     ret->startup_string = GNUNET_strdup(start_string);
317   else
318     ret->startup_string = GNUNET_strdup("");
319
320   return ret;
321 }
322
323 /**
324  * Update progress meter (increment by one).
325  *
326  * @param meter the meter to update and print info for
327  *
328  * @return GNUNET_YES if called the total requested,
329  *         GNUNET_NO if more items expected
330  */
331 static int
332 update_meter(struct ProgressMeter *meter)
333 {
334   if (meter->print == GNUNET_YES)
335     {
336       if (meter->completed % meter->modnum == 0)
337         {
338           if (meter->completed == 0)
339             {
340               fprintf(stdout, "%sProgress: [0%%", meter->startup_string);
341             }
342           else
343             fprintf(stdout, "%d%%", (int)(((float)meter->completed / meter->total) * 100));
344         }
345       else if (meter->completed % meter->dotnum == 0)
346         fprintf(stdout, ".");
347
348       if (meter->completed + 1 == meter->total)
349         fprintf(stdout, "%d%%]\n", 100);
350       fflush(stdout);
351     }
352   meter->completed++;
353
354   if (meter->completed == meter->total)
355     return GNUNET_YES;
356   return GNUNET_NO;
357 }
358
359 /**
360  * Release resources for meter
361  *
362  * @param meter the meter to free
363  */
364 static void
365 free_meter(struct ProgressMeter *meter)
366 {
367   GNUNET_free_non_null(meter->startup_string);
368   GNUNET_free_non_null(meter);
369 }
370
371 /**
372  * Check whether peers successfully shut down.
373  */
374 void shutdown_callback (void *cls,
375                         const char *emsg)
376 {
377   if (emsg != NULL)
378     {
379       if (ok == 0)
380         ok = 2;
381     }
382 }
383
384 /**
385  * Task to release DHT handles for PUT
386  */
387 static void
388 put_disconnect_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
389 {
390   struct TestPutContext *test_put = cls;
391   test_put->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
392   GNUNET_DHT_disconnect(test_put->dht_handle);
393   test_put->dht_handle = NULL;
394 }
395
396 /**
397  * Function scheduled to be run on the successful completion of this
398  * testcase.
399  */
400 static void
401 finish_testing (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
402 {
403   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Ending test normally!\n", (char *)cls);
404   GNUNET_assert (pg != NULL);
405   struct TestPutContext *test_put = all_puts;
406   struct TestGetContext *test_get = all_gets;
407
408   while (test_put != NULL)
409     {
410       if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
411         GNUNET_SCHEDULER_cancel(sched, test_put->disconnect_task);
412       if (test_put->dht_handle != NULL)
413         GNUNET_DHT_disconnect(test_put->dht_handle);
414       test_put = test_put->next;
415     }
416
417   while (test_get != NULL)
418     {
419       if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
420         GNUNET_SCHEDULER_cancel(sched, test_get->disconnect_task);
421       if (test_get->get_handle != NULL)
422         GNUNET_DHT_get_stop(test_get->get_handle, NULL, NULL);
423       if (test_get->dht_handle != NULL)
424         GNUNET_DHT_disconnect(test_get->dht_handle);
425       test_get = test_get->next;
426     }
427
428   GNUNET_TESTING_daemons_stop (pg, DEFAULT_TIMEOUT, &shutdown_callback, NULL);
429
430   /* FIXME: optionally get stats for dropped messages, etc. */
431   if (dhtlog_handle != NULL)
432     {
433       fprintf(stderr, "Update trial endtime\n");
434       dhtlog_handle->update_trial (trialuid, 0, 0, 0);
435     }
436
437   if (hostkey_meter != NULL)
438     free_meter(hostkey_meter);
439   if (peer_start_meter != NULL)
440     free_meter(peer_start_meter);
441   if (peer_connect_meter != NULL)
442     free_meter(peer_connect_meter);
443   if (put_meter != NULL)
444     free_meter(put_meter);
445   if (get_meter != NULL)
446     free_meter(get_meter);
447
448   ok = 0;
449 }
450
451
452 /**
453  * Check if the get_handle is being used, if so stop the request.  Either
454  * way, schedule the end_badly_cont function which actually shuts down the
455  * test.
456  */
457 static void
458 end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
459 {
460   GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Failing test with error: `%s'!\n", (char *)cls);
461
462   struct TestPutContext *test_put = all_puts;
463   struct TestGetContext *test_get = all_gets;
464
465   while (test_put != NULL)
466     {
467       if (test_put->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
468         GNUNET_SCHEDULER_cancel(sched, test_put->disconnect_task);
469       if (test_put->dht_handle != NULL)
470         GNUNET_DHT_disconnect(test_put->dht_handle);
471       test_put = test_put->next;
472     }
473
474   while (test_get != NULL)
475     {
476       if (test_get->disconnect_task != GNUNET_SCHEDULER_NO_TASK)
477         GNUNET_SCHEDULER_cancel(sched, test_get->disconnect_task);
478       if (test_get->get_handle != NULL)
479         GNUNET_DHT_get_stop(test_get->get_handle, NULL, NULL);
480       if (test_get->dht_handle != NULL)
481         GNUNET_DHT_disconnect(test_get->dht_handle);
482       test_get = test_get->next;
483     }
484
485   GNUNET_TESTING_daemons_stop (pg, DEFAULT_TIMEOUT, &shutdown_callback, NULL);
486
487   /* FIXME: optionally get stats for dropped messages, etc. */
488   if (dhtlog_handle != NULL)
489     {
490       fprintf(stderr, "Update trial endtime\n");
491       dhtlog_handle->update_trial (trialuid, 0, 0, 0);
492     }
493
494   if (hostkey_meter != NULL)
495     free_meter(hostkey_meter);
496   if (peer_start_meter != NULL)
497     free_meter(peer_start_meter);
498   if (peer_connect_meter != NULL)
499     free_meter(peer_connect_meter);
500   if (put_meter != NULL)
501     free_meter(put_meter);
502   if (get_meter != NULL)
503     free_meter(get_meter);
504
505   ok = 1;
506 }
507
508 /**
509  * Task to release DHT handle associated with GET request.
510  */
511 static void
512 get_stop_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
513 {
514   struct TestGetContext *test_get = cls;
515   outstanding_gets--; /* GET is really finished */
516   GNUNET_DHT_disconnect(test_get->dht_handle);
517   test_get->dht_handle = NULL;
518
519 #if VERBOSE > 1
520   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%d gets succeeded, %d gets failed!\n", gets_completed, gets_failed);
521 #endif
522   update_meter(get_meter);
523   if ((gets_completed == num_gets) && (outstanding_gets == 0))/* All gets successful */
524     {
525       GNUNET_SCHEDULER_cancel(sched, die_task);
526       GNUNET_SCHEDULER_add_now(sched, &finish_testing, NULL);
527     }
528   else if ((gets_completed + gets_failed == num_gets) && (outstanding_gets == 0)) /* Had some failures */
529     {
530       GNUNET_SCHEDULER_cancel(sched, die_task);
531       GNUNET_SCHEDULER_add_now(sched, &finish_testing, NULL);
532     }
533 }
534
535 /**
536  * Task to release get handle.
537  */
538 static void
539 get_stop_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
540 {
541   struct TestGetContext *test_get = cls;
542
543   if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT)
544     gets_failed++;
545   GNUNET_assert(test_get->get_handle != NULL);
546   GNUNET_DHT_get_stop(test_get->get_handle, &get_stop_finished, test_get);
547   test_get->get_handle = NULL;
548   test_get->disconnect_task = GNUNET_SCHEDULER_NO_TASK;
549 }
550
551 /**
552  * Iterator called if the GET request initiated returns a response.
553  *
554  * @param cls closure
555  * @param exp when will this value expire
556  * @param key key of the result
557  * @param type type of the result
558  * @param size number of bytes in data
559  * @param data pointer to the result data
560  */
561 void get_result_iterator (void *cls,
562                           struct GNUNET_TIME_Absolute exp,
563                           const GNUNET_HashCode * key,
564                           uint32_t type,
565                           uint32_t size,
566                           const void *data)
567 {
568   struct TestGetContext *test_get = cls;
569   GNUNET_HashCode search_key; /* Key stored under */
570   char original_data[test_data_size]; /* Made up data to store */
571
572   memset(original_data, test_get->uid, sizeof(original_data));
573   GNUNET_CRYPTO_hash(original_data, test_data_size, &search_key);
574
575   if (test_get->succeeded == GNUNET_YES)
576     return; /* Get has already been successful, probably ending now */
577
578   if ((0 != memcmp(&search_key, key, sizeof (GNUNET_HashCode))) || (0 != memcmp(original_data, data, sizeof(original_data))))
579     {
580       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Key or data is not the same as was inserted!\n");
581     }
582   else
583     {
584       gets_completed++;
585       test_get->succeeded = GNUNET_YES;
586     }
587 #if VERBOSE > 1
588   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received correct GET response!\n");
589 #endif
590   GNUNET_SCHEDULER_cancel(sched, test_get->disconnect_task);
591   GNUNET_SCHEDULER_add_continuation(sched, &get_stop_task, test_get, GNUNET_SCHEDULER_REASON_PREREQ_DONE);
592 }
593
594 /**
595  * Continuation telling us GET request was sent.
596  */
597 static void
598 get_continuation (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
599 {
600   // Is there something to be done here?
601   if (tc->reason != GNUNET_SCHEDULER_REASON_PREREQ_DONE)
602     return;
603 }
604
605 /**
606  * Set up some data, and call API PUT function
607  */
608 static void
609 do_get (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
610 {
611   struct TestGetContext *test_get = cls;
612   GNUNET_HashCode key; /* Made up key to store data under */
613   char data[test_data_size]; /* Made up data to store */
614
615   if (num_gets == 0)
616     {
617       GNUNET_SCHEDULER_cancel(sched, die_task);
618       GNUNET_SCHEDULER_add_now(sched, &finish_testing, NULL);
619     }
620   if (test_get == NULL)
621     return; /* End of the list */
622
623   memset(data, test_get->uid, sizeof(data));
624   GNUNET_CRYPTO_hash(data, test_data_size, &key);
625
626   if (outstanding_gets > max_outstanding_gets)
627     {
628       GNUNET_SCHEDULER_add_delayed (sched, get_delay, &do_get, test_get);
629       return;
630     }
631
632   test_get->dht_handle = GNUNET_DHT_connect(sched, test_get->daemon->cfg, 10);
633   /* Insert the data at the first peer */
634   GNUNET_assert(test_get->dht_handle != NULL);
635   outstanding_gets++;
636   test_get->get_handle = GNUNET_DHT_get_start(test_get->dht_handle,
637                                               GNUNET_TIME_relative_get_forever(),
638                                               1,
639                                               &key,
640                                               &get_result_iterator,
641                                               test_get,
642                                               &get_continuation,
643                                               test_get);
644 #if VERBOSE > 1
645   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting get for uid %u from peer %s\n",
646              test_get->uid,
647              test_get->daemon->shortname);
648 #endif
649   test_get->disconnect_task = GNUNET_SCHEDULER_add_delayed(sched, get_timeout, &get_stop_task, test_get);
650   GNUNET_SCHEDULER_add_now (sched, &do_get, test_get->next);
651 }
652
653 /**
654  * Called when the PUT request has been transmitted to the DHT service.
655  * Schedule the GET request for some time in the future.
656  */
657 static void
658 put_finished (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
659 {
660   struct TestPutContext *test_put = cls;
661   outstanding_puts--;
662   puts_completed++;
663
664   if (tc->reason == GNUNET_SCHEDULER_REASON_TIMEOUT)
665     fprintf(stderr, "PUT Request failed!\n");
666
667   GNUNET_SCHEDULER_cancel(sched, test_put->disconnect_task);
668   test_put->disconnect_task = GNUNET_SCHEDULER_add_now(sched, &put_disconnect_task, test_put);
669   if (GNUNET_YES == update_meter(put_meter))
670     {
671       GNUNET_assert(outstanding_puts == 0);
672       GNUNET_SCHEDULER_cancel (sched, die_task);
673       die_task = GNUNET_SCHEDULER_add_delayed (sched, all_get_timeout,
674                                                &end_badly, "from do gets");
675       GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, settle_time), &do_get, all_gets);
676       return;
677     }
678 }
679
680 /**
681  * Set up some data, and call API PUT function
682  */
683 static void
684 do_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
685 {
686   struct TestPutContext *test_put = cls;
687   GNUNET_HashCode key; /* Made up key to store data under */
688   char data[test_data_size]; /* Made up data to store */
689   uint32_t rand;
690
691   if (test_put == NULL)
692     return; /* End of list */
693
694   memset(data, test_put->uid, sizeof(data));
695   GNUNET_CRYPTO_hash(data, test_data_size, &key);
696
697   if (outstanding_puts > max_outstanding_puts)
698     {
699       GNUNET_SCHEDULER_add_delayed (sched, put_delay, &do_put, test_put);
700       return;
701     }
702
703 #if VERBOSE > 1
704     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting put for uid %u from peer %s\n",
705                test_put->uid,
706                test_put->daemon->shortname);
707 #endif
708   test_put->dht_handle = GNUNET_DHT_connect(sched, test_put->daemon->cfg, 10);
709
710   GNUNET_assert(test_put->dht_handle != NULL);
711   outstanding_puts++;
712   GNUNET_DHT_put(test_put->dht_handle,
713                  &key,
714                  1,
715                  sizeof(data), data,
716                  GNUNET_TIME_absolute_get_forever(),
717                  GNUNET_TIME_relative_get_forever(),
718                  &put_finished, test_put);
719   test_put->disconnect_task = GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_get_forever(), &put_disconnect_task, test_put);
720   rand = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 2);
721   GNUNET_SCHEDULER_add_delayed(sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, rand), &do_put, test_put->next);
722 }
723
724
725 /**
726  * Set up some all of the put and get operations we want
727  * to do.  Allocate data structure for each, add to list,
728  * then call actual insert functions.
729  */
730 static void
731 setup_puts_and_gets (void *cls, const struct GNUNET_SCHEDULER_TaskContext * tc)
732 {
733   int i;
734   uint32_t temp_daemon;
735   struct TestPutContext *test_put;
736   struct TestGetContext *test_get;
737   int remember[num_puts][num_peers];
738
739   for (i = 0; i < num_puts; i++)
740     {
741       test_put = GNUNET_malloc(sizeof(struct TestPutContext));
742       test_put->uid = i;
743       temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
744       test_put->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
745       test_put->next = all_puts;
746       all_puts = test_put;
747     }
748
749   for (i = 0; i < num_gets; i++)
750     {
751       test_get = GNUNET_malloc(sizeof(struct TestGetContext));
752       test_get->uid = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_puts);
753       temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
754       while (remember[test_get->uid][temp_daemon] == 1)
755         temp_daemon = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, num_peers);
756       test_get->daemon = GNUNET_TESTING_daemon_get(pg, temp_daemon);
757       remember[test_get->uid][temp_daemon] = 1;
758       test_get->next = all_gets;
759       all_gets = test_get;
760     }
761
762   /*GNUNET_SCHEDULER_cancel (sched, die_task);*/
763   die_task = GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, num_puts * 2),
764                                            &end_badly, "from do puts");
765   GNUNET_SCHEDULER_add_now (sched, &do_put, all_puts);
766 }
767 /**
768  * This function is called whenever a connection attempt is finished between two of
769  * the started peers (started with GNUNET_TESTING_daemons_start).  The total
770  * number of times this function is called should equal the number returned
771  * from the GNUNET_TESTING_connect_topology call.
772  *
773  * The emsg variable is NULL on success (peers connected), and non-NULL on
774  * failure (peers failed to connect).
775  */
776 void
777 topology_callback (void *cls,
778                    const struct GNUNET_PeerIdentity *first,
779                    const struct GNUNET_PeerIdentity *second,
780                    uint32_t distance,
781                    const struct GNUNET_CONFIGURATION_Handle *first_cfg,
782                    const struct GNUNET_CONFIGURATION_Handle *second_cfg,
783                    struct GNUNET_TESTING_Daemon *first_daemon,
784                    struct GNUNET_TESTING_Daemon *second_daemon,
785                    const char *emsg)
786 {
787   if (emsg == NULL)
788     {
789       total_connections++;
790 #if VERBOSE > 1
791       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "connected peer %s to peer %s, distance %u\n",
792                  first_daemon->shortname,
793                  second_daemon->shortname,
794                  distance);
795 #endif
796     }
797 #if VERBOSE
798   else
799     {
800       failed_connections++;
801       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to connect peer %s to peer %s with error :\n%s\n",
802                   first_daemon->shortname,
803                   second_daemon->shortname, emsg);
804     }
805 #endif
806   GNUNET_assert(peer_connect_meter != NULL);
807   if (GNUNET_YES == update_meter(peer_connect_meter))
808     {
809 #if VERBOSE
810       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
811                   "Created %d total connections, which is our target number!  Starting next phase of testing.\n",
812                   total_connections);
813 #endif
814       if (dhtlog_handle != NULL)
815         dhtlog_handle->update_connections (trialuid, total_connections);
816
817       GNUNET_SCHEDULER_cancel (sched, die_task);
818       /*die_task = GNUNET_SCHEDULER_add_delayed (sched, DEFAULT_TIMEOUT,
819                                                &end_badly, "from setup puts/gets");*/
820
821       GNUNET_SCHEDULER_add_delayed (sched, GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, settle_time), &setup_puts_and_gets, NULL);
822     }
823   else if (total_connections + failed_connections == expected_connections)
824     {
825       GNUNET_SCHEDULER_cancel (sched, die_task);
826       die_task = GNUNET_SCHEDULER_add_now (sched,
827                                            &end_badly, "from topology_callback (too many failed connections)");
828     }
829 }
830
831 static void
832 peers_started_callback (void *cls,
833        const struct GNUNET_PeerIdentity *id,
834        const struct GNUNET_CONFIGURATION_Handle *cfg,
835        struct GNUNET_TESTING_Daemon *d, const char *emsg)
836 {
837   if (emsg != NULL)
838     {
839       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to start daemon with error: `%s'\n",
840                   emsg);
841       return;
842     }
843   GNUNET_assert (id != NULL);
844
845 #if VERBOSE > 1
846   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Started daemon %llu out of %llu\n",
847               (num_peers - peers_left) + 1, num_peers);
848 #endif
849
850   peers_left--;
851
852   if (GNUNET_YES == update_meter(peer_start_meter))
853     {
854 #if VERBOSE
855       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
856                   "All %d daemons started, now connecting peers!\n",
857                   num_peers);
858 #endif
859       GNUNET_SCHEDULER_cancel (sched, die_task);
860
861       expected_connections = -1;
862       if ((pg != NULL) && (peers_left == 0))
863         {
864           expected_connections = GNUNET_TESTING_connect_topology (pg, connect_topology, connect_topology_option, connect_topology_option_modifier);
865           peer_connect_meter = create_meter(expected_connections, "Peer connection ", GNUNET_YES);
866 #if VERBOSE
867           GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
868                       "Have %d expected connections\n", expected_connections);
869 #endif
870         }
871
872       if (expected_connections == GNUNET_SYSERR)
873         {
874           die_task = GNUNET_SCHEDULER_add_now (sched,
875                                                &end_badly, "from connect topology (bad return)");
876         }
877
878       die_task = GNUNET_SCHEDULER_add_delayed (sched,
879                                                GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, DEFAULT_CONNECT_TIMEOUT * expected_connections),
880                                                &end_badly, "from connect topology (timeout)");
881
882       ok = 0;
883     }
884 }
885
886 static void
887 create_topology ()
888 {
889   peers_left = num_peers; /* Reset counter */
890   if (GNUNET_TESTING_create_topology (pg, topology, blacklist_topology, blacklist_transports) != GNUNET_SYSERR)
891     {
892 #if VERBOSE
893       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
894                   "Topology set up, now starting peers!\n");
895 #endif
896       GNUNET_TESTING_daemons_continue_startup(pg);
897     }
898   else
899     {
900       GNUNET_SCHEDULER_cancel (sched, die_task);
901       die_task = GNUNET_SCHEDULER_add_now (sched,
902                                            &end_badly, "from create topology (bad return)");
903     }
904   GNUNET_SCHEDULER_cancel (sched, die_task);
905   die_task = GNUNET_SCHEDULER_add_delayed (sched,
906                                            GNUNET_TIME_relative_multiply(seconds_per_peer_start, num_peers),
907                                            &end_badly, "from continue startup (timeout)");
908 }
909
910 /**
911  * Callback indicating that the hostkey was created for a peer.
912  *
913  * @param cls NULL
914  * @param id the peer identity
915  * @param d the daemon handle (pretty useless at this point, remove?)
916  * @param emsg non-null on failure
917  */
918 void hostkey_callback (void *cls,
919                        const struct GNUNET_PeerIdentity *id,
920                        struct GNUNET_TESTING_Daemon *d,
921                        const char *emsg)
922 {
923   if (emsg != NULL)
924     {
925       GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Hostkey callback received error: %s\n", emsg);
926     }
927
928 #if VERBOSE > 1
929     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
930                 "Hostkey (%d/%d) created for peer `%s'\n",
931                 num_peers - peers_left, num_peers, GNUNET_i2s(id));
932 #endif
933
934     peers_left--;
935     if (GNUNET_YES == update_meter(hostkey_meter))
936       {
937 #if VERBOSE
938         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
939                     "All %d hostkeys created, now creating topology!\n",
940                     num_peers);
941 #endif
942         GNUNET_SCHEDULER_cancel (sched, die_task);
943         /* Set up task in case topology creation doesn't finish
944          * within a reasonable amount of time */
945         die_task = GNUNET_SCHEDULER_add_delayed (sched,
946                                                  DEFAULT_TOPOLOGY_TIMEOUT,
947                                                  &end_badly, "from create_topology");
948         GNUNET_SCHEDULER_add_now(sched, &create_topology, NULL);
949         ok = 0;
950       }
951 }
952
953
954 static void
955 run (void *cls,
956      struct GNUNET_SCHEDULER_Handle *s,
957      char *const *args,
958      const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
959 {
960   struct GNUNET_TESTING_Host *hosts;
961   struct GNUNET_TESTING_Host *temphost;
962   char * topology_str;
963   char * connect_topology_str;
964   char * blacklist_topology_str;
965   char * connect_topology_option_str;
966   char * connect_topology_option_modifier_string;
967   char *trialmessage;
968   char * topology_percentage_str;
969   float topology_percentage;
970   char * topology_probability_str;
971   char * hostfile;
972   float topology_probability;
973   unsigned long long temp_config_number;
974   char *buf;
975   char *data;
976
977   struct stat frstat;
978   int count;
979
980   sched = s;
981
982   /* Get path from configuration file */
983   if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string(cfg, "paths", "servicehome", &test_directory))
984     {
985       ok = 404;
986       return;
987     }
988
989   /**
990    * Get DHT specific testing options.
991    */
992   if ((GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht_testing", "mysql_logging"))||
993       (GNUNET_YES == GNUNET_CONFIGURATION_get_value_yesno(cfg, "dht_testing", "mysql_logging_extended")))
994     {
995       dhtlog_handle = GNUNET_DHTLOG_connect(cfg);
996       if (dhtlog_handle == NULL)
997         {
998           GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
999                       "Could not connect to mysql server for logging, will NOT log dht operations!");
1000           ok = 3306;
1001           return;
1002         }
1003     }
1004
1005   if (GNUNET_OK !=
1006       GNUNET_CONFIGURATION_get_value_string (cfg, "dht_testing", "comment",
1007                                              &trialmessage))
1008     trialmessage = NULL;
1009
1010   if (GNUNET_OK !=
1011       GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "hostfile",
1012                                              &hostfile))
1013     hostfile = NULL;
1014
1015   hosts = NULL;
1016   if (hostfile != NULL)
1017     {
1018       if (GNUNET_OK != GNUNET_DISK_file_test (hostfile))
1019           GNUNET_DISK_fn_write (hostfile, NULL, 0, GNUNET_DISK_PERM_USER_READ
1020             | GNUNET_DISK_PERM_USER_WRITE);
1021       if ((0 != STAT (hostfile, &frstat)) || (frstat.st_size == 0))
1022         {
1023           GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1024                       "Could not open file specified for host list, ending test!");
1025           ok = 1119;
1026           GNUNET_free_non_null(trialmessage);
1027           GNUNET_free(hostfile);
1028           return;
1029         }
1030
1031     data = GNUNET_malloc_large (frstat.st_size);
1032     GNUNET_assert(data != NULL);
1033     if (frstat.st_size !=
1034         GNUNET_DISK_fn_read (hostfile, data, frstat.st_size))
1035       {
1036         GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1037                   "Could not read file %s specified for host list, ending test!", hostfile);
1038         GNUNET_free (hostfile);
1039         GNUNET_free (data);
1040         return;
1041       }
1042
1043     buf = data;
1044     count = 0;
1045     while (count < frstat.st_size)
1046       {
1047         count++;
1048         if (((data[count] == '\n') || (data[count] == '\0')) && (buf != &data[count]))
1049           {
1050             data[count] = '\0';
1051             temphost = GNUNET_malloc(sizeof(struct GNUNET_TESTING_Host));
1052             temphost->hostname = buf;
1053             temphost->next = hosts;
1054             hosts = temphost;
1055             buf = &data[count + 1];
1056           }
1057         else if ((data[count] == '\n') || (data[count] == '\0'))
1058           buf = &data[count + 1];
1059       }
1060     }
1061
1062   if (GNUNET_OK !=
1063           GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "malicious_getters",
1064                                                  &malicious_getters))
1065     malicious_getters = 0;
1066
1067   if (GNUNET_OK !=
1068           GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "malicious_putters",
1069                                                  &malicious_putters))
1070     malicious_putters = 0;
1071
1072   if (GNUNET_OK !=
1073             GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "malicious_droppers",
1074                                                    &malicious_droppers))
1075     malicious_droppers = 0;
1076
1077   if (GNUNET_OK !=
1078       GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "settle_time",
1079                                                  &settle_time))
1080     settle_time = 0;
1081
1082   if (GNUNET_SYSERR ==
1083       GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "num_puts",
1084                                              &num_puts))
1085     num_puts = num_peers;
1086
1087   if (GNUNET_SYSERR ==
1088       GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "num_gets",
1089                                              &num_gets))
1090     num_gets = num_peers;
1091
1092   if (GNUNET_OK ==
1093         GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "get_timeout",
1094                                                &temp_config_number))
1095     get_timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_config_number);
1096   else
1097     get_timeout = DEFAULT_GET_TIMEOUT;
1098
1099   if (GNUNET_OK ==
1100         GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "concurrent_puts",
1101                                                &temp_config_number))
1102     max_outstanding_puts = temp_config_number;
1103   else
1104     max_outstanding_puts = DEFAULT_MAX_OUTSTANDING_PUTS;
1105
1106   if (GNUNET_OK ==
1107         GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "concurrent_gets",
1108                                                &temp_config_number))
1109     max_outstanding_gets = temp_config_number;
1110   else
1111     max_outstanding_gets = DEFAULT_MAX_OUTSTANDING_GETS;
1112
1113   if (GNUNET_OK ==
1114         GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "timeout",
1115                                                &temp_config_number))
1116     all_get_timeout = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_config_number);
1117   else
1118     all_get_timeout.value = get_timeout.value * ((num_gets / max_outstanding_gets) + 1);
1119
1120   if (GNUNET_OK ==
1121         GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "get_delay",
1122                                                &temp_config_number))
1123     get_delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_config_number);
1124   else
1125     get_delay = DEFAULT_GET_DELAY;
1126
1127   if (GNUNET_OK ==
1128         GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "put_delay",
1129                                                &temp_config_number))
1130     put_delay = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_config_number);
1131   else
1132     put_delay = DEFAULT_PUT_DELAY;
1133
1134   if (GNUNET_OK ==
1135       GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "peer_start_timeout",
1136                                              &temp_config_number))
1137     seconds_per_peer_start = GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, temp_config_number);
1138   else
1139     seconds_per_peer_start = DEFAULT_SECONDS_PER_PEER_START;
1140
1141   if (GNUNET_OK ==
1142         GNUNET_CONFIGURATION_get_value_number (cfg, "dht_testing", "data_size",
1143                                                &temp_config_number))
1144     test_data_size = temp_config_number;
1145   else
1146     test_data_size = DEFAULT_TEST_DATA_SIZE;
1147
1148   /**
1149    * Get testing related options.
1150    */
1151   if ((GNUNET_YES ==
1152       GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "topology",
1153                                             &topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&topology, topology_str)))
1154     {
1155       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1156                   "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "TOPOLOGY");
1157       topology = GNUNET_TESTING_TOPOLOGY_CLIQUE; /* Defaults to NONE, so set better default here */
1158     }
1159
1160   if (GNUNET_OK !=
1161       GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "percentage",
1162                                                  &topology_percentage_str))
1163     topology_percentage = 0.5;
1164   else
1165     {
1166       topology_percentage = atof (topology_percentage_str);
1167     }
1168
1169   if (GNUNET_OK !=
1170       GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "probability",
1171                                                  &topology_probability_str))
1172     topology_probability = 0.5;
1173   else
1174     {
1175      topology_probability = atof (topology_probability_str);
1176     }
1177
1178   if ((GNUNET_YES ==
1179       GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology",
1180                                             &connect_topology_str)) && (GNUNET_NO == GNUNET_TESTING_topology_get(&connect_topology, connect_topology_str)))
1181     {
1182       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1183                   "Invalid connect topology `%s' given for section %s option %s\n", connect_topology_str, "TESTING", "CONNECT_TOPOLOGY");
1184     }
1185   GNUNET_free_non_null(connect_topology_str);
1186   if ((GNUNET_YES ==
1187       GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "connect_topology_option",
1188                                             &connect_topology_option_str)) && (GNUNET_NO == GNUNET_TESTING_topology_option_get(&connect_topology_option, connect_topology_option_str)))
1189     {
1190       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1191                   "Invalid connect topology option `%s' given for section %s option %s\n", connect_topology_option_str, "TESTING", "CONNECT_TOPOLOGY_OPTION");
1192       connect_topology_option = GNUNET_TESTING_TOPOLOGY_OPTION_ALL; /* Defaults to NONE, set to ALL */
1193     }
1194   GNUNET_free_non_null(connect_topology_option_str);
1195   if (GNUNET_YES ==
1196         GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "connect_topology_option_modifier",
1197                                                &connect_topology_option_modifier_string))
1198     {
1199       if (sscanf(connect_topology_option_modifier_string, "%lf", &connect_topology_option_modifier) != 1)
1200       {
1201         GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1202         _("Invalid value `%s' for option `%s' in section `%s': expected float\n"),
1203         connect_topology_option_modifier_string,
1204         "connect_topology_option_modifier",
1205         "TESTING");
1206       }
1207       GNUNET_free (connect_topology_option_modifier_string);
1208     }
1209
1210   if (GNUNET_YES != GNUNET_CONFIGURATION_get_value_string (cfg, "testing", "blacklist_transports",
1211                                          &blacklist_transports))
1212     blacklist_transports = NULL;
1213
1214   if ((GNUNET_YES ==
1215       GNUNET_CONFIGURATION_get_value_string(cfg, "testing", "blacklist_topology",
1216                                             &blacklist_topology_str)) &&
1217       (GNUNET_NO == GNUNET_TESTING_topology_get(&blacklist_topology, blacklist_topology_str)))
1218     {
1219       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1220                   "Invalid topology `%s' given for section %s option %s\n", topology_str, "TESTING", "BLACKLIST_TOPOLOGY");
1221     }
1222   GNUNET_free_non_null(topology_str);
1223   GNUNET_free_non_null(blacklist_topology_str);
1224
1225   /* Get number of peers to start from configuration */
1226   if (GNUNET_SYSERR ==
1227       GNUNET_CONFIGURATION_get_value_number (cfg, "testing", "num_peers",
1228                                              &num_peers))
1229     {
1230       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1231                   "Number of peers must be specified in section %s option %s\n", topology_str, "TESTING", "NUM_PEERS");
1232     }
1233
1234   /* Set peers_left so we know when all peers started */
1235   peers_left = num_peers;
1236
1237   /* Set up a task to end testing if peer start fails */
1238   die_task = GNUNET_SCHEDULER_add_delayed (sched,
1239                                            GNUNET_TIME_relative_multiply(seconds_per_peer_start, num_peers),
1240                                            &end_badly, "didn't generate all hostkeys within allowed startup time!");
1241
1242   if (dhtlog_handle == NULL)
1243     GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1244                 "dhtlog_handle is NULL!");
1245
1246   if ((trialmessage != NULL) && (dhtlog_handle != NULL))
1247     {
1248       dhtlog_handle->insert_trial (&trialuid, peers_left, topology,
1249                                     blacklist_topology, connect_topology,
1250                                     connect_topology_option,
1251                                     connect_topology_option_modifier, topology_percentage,
1252                                     topology_probability, num_puts, num_gets,
1253                                     max_outstanding_gets, settle_time, 1,
1254                                     malicious_getters, malicious_putters,
1255                                     malicious_droppers, trialmessage);
1256     }
1257   else if (dhtlog_handle != NULL)
1258     {
1259       dhtlog_handle->insert_trial (&trialuid, peers_left, topology,
1260                                     blacklist_topology, connect_topology,
1261                                     connect_topology_option,
1262                                     connect_topology_option_modifier, topology_percentage,
1263                                     topology_probability, num_puts, num_gets,
1264                                     max_outstanding_gets, settle_time, 1,
1265                                     malicious_getters, malicious_putters,
1266                                     malicious_droppers, "");
1267     }
1268
1269   hostkey_meter = create_meter(peers_left, "Hostkeys created ", GNUNET_YES);
1270   peer_start_meter = create_meter(peers_left, "Peers started ", GNUNET_YES);
1271
1272   put_meter = create_meter(num_puts, "Puts completed ", GNUNET_YES);
1273   get_meter = create_meter(num_gets, "Gets completed ", GNUNET_YES);
1274   pg = GNUNET_TESTING_daemons_start (sched, cfg,
1275                                      peers_left,
1276                                      GNUNET_TIME_relative_multiply(seconds_per_peer_start, num_peers),
1277                                      &hostkey_callback, NULL,
1278                                      &peers_started_callback, NULL,
1279                                      &topology_callback, NULL,
1280                                      hosts);
1281
1282 }
1283
1284
1285 int
1286 main (int argc, char *argv[])
1287 {
1288   int ret;
1289   struct GNUNET_GETOPT_CommandLineOption options[] = {
1290       GNUNET_GETOPT_OPTION_END
1291     };
1292
1293   ret = GNUNET_PROGRAM_run (argc,
1294                             argv, "gnunet-dht-driver", "nohelp",
1295                             options, &run, &ok);
1296
1297   if (ret != GNUNET_OK)
1298     {
1299       GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`gnunet-dht-driver': Failed with error code %d\n", ret);
1300     }
1301
1302   /**
1303    * Need to remove base directory, subdirectories taken care
1304    * of by the testing framework.
1305    */
1306   if (GNUNET_DISK_directory_remove (test_directory) != GNUNET_OK)
1307     {
1308       GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to remove testing directory %s\n", test_directory);
1309     }
1310   return ret;
1311 }
1312
1313 /* end of test_dht_twopeer_put_get.c */