2 This file is part of GNUnet.
3 (C) 2010, 2011 Christian Grothoff (and other contributing authors)
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.
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.
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.
22 * @file fs/perf_gnunet_service_fs_p2p_trust.c
23 * @brief profile P2P routing trust mechanism. Creates
24 * a clique of NUM_DAEMONS (i.e. 3) where two
25 * peers share (seed) different files and download
26 * them from each other while all the other peers
27 * just "leach" those files. Ideally, the seeders
28 * "learn" that they contribute (to each other),
29 * and give the other seeder higher priority;
30 * naturally, this only happens nicely for larger
31 * files; finally, once the seeders are done, the
32 * leachers should see fast download rates as well.
33 * @author Christian Grothoff
36 * - 10 MB, 3 peers, with delays:
37 * Download speed of type `seeder 1' was 757 KiB/s
38 * Download speed of type `seeder 2' was 613 KiB/s
39 * Download speed of type `leach` was 539 KiB/s
41 * - 10 MB, 3 peers, without delays:
42 * Download speed of type `seeder 1' was 1784 KiB/s
43 * Download speed of type `seeder 2' was 1604 KiB/s
44 * Download speed of type `leach` was 1384 KiB/s
47 #include "fs_test_lib.h"
48 #include "gnunet_testing_lib.h"
50 #define VERBOSE GNUNET_NO
53 * File-size we use for testing.
55 #define FILESIZE (1024 * 1024 * 10)
58 * How long until we give up on transmitting the message?
60 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
63 * Number of daemons in clique, must be at least 3 (!).
68 * Seed for first file on offer.
73 * Seed for second file on offer.
77 static struct GNUNET_FS_TestDaemon *daemons[NUM_DAEMONS];
81 static struct GNUNET_TIME_Absolute start_time;
83 static const char *progname;
85 static struct GNUNET_FS_Uri *uri1;
87 static struct GNUNET_FS_Uri *uri2;
90 do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
92 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
97 * Master context for 'stat_run'.
101 struct GNUNET_STATISTICS_Handle *stat;
108 const char *subsystem;
113 * Statistics we print out.
115 static struct StatValues stats[] = {
116 {"fs", "# artificial delays introduced (ms)"},
117 {"fs", "# queries forwarded"},
118 {"fs", "# replies received and matched"},
119 {"fs", "# results found locally"},
120 {"fs", "# requests forwarded due to high load"},
121 {"fs", "# requests done for free (low load)"},
122 {"fs", "# requests dropped, priority insufficient"},
123 {"fs", "# requests done for a price (normal load)"},
124 {"fs", "# requests dropped by datastore (queue length limit)"},
125 {"fs", "# P2P searches received"},
126 {"fs", "# P2P searches discarded (queue length bound)"},
127 {"fs", "# replies received for local clients"},
128 {"fs", "# queries retransmitted to same target"},
129 {"core", "# bytes decrypted"},
130 {"core", "# bytes encrypted"},
131 {"core", "# discarded CORE_SEND requests"},
132 {"core", "# discarded lower priority CORE_SEND requests"},
133 {"transport", "# bytes received via TCP"},
134 {"transport", "# bytes transmitted via TCP"},
135 {"datacache", "# bytes stored"},
141 * Callback function to process statistic values.
144 * @param subsystem name of subsystem that created the statistic
145 * @param name the name of the datum
146 * @param value the current value
147 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
148 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
151 print_stat (void *cls, const char *subsystem, const char *name, uint64_t value,
154 struct StatMaster *sm = cls;
156 fprintf (stderr, "Peer %2u: %12s/%50s = %12llu\n", sm->daemon, subsystem,
157 name, (unsigned long long) value);
163 * Function that gathers stats from all daemons.
166 stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
170 * Function called when GET operation on stats is done.
173 get_done (void *cls, int success)
175 struct StatMaster *sm = cls;
177 GNUNET_break (GNUNET_OK == success);
179 GNUNET_SCHEDULER_add_now (&stat_run, sm);
184 * Function that gathers stats from all daemons.
187 stat_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
189 struct StatMaster *sm = cls;
191 if (stats[sm->value].name != NULL)
193 GNUNET_STATISTICS_get (sm->stat,
197 stats[sm->value].subsystem, stats[sm->value].name,
199 GNUNET_TIME_UNIT_FOREVER_REL, &get_done, &print_stat,
203 GNUNET_STATISTICS_destroy (sm->stat, GNUNET_NO);
206 if (sm->daemon == NUM_DAEMONS)
209 GNUNET_SCHEDULER_add_now (&do_stop, NULL);
213 GNUNET_STATISTICS_create ("<driver>",
214 GNUNET_FS_TEST_get_configuration (daemons,
216 GNUNET_SCHEDULER_add_now (&stat_run, sm);
221 do_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
223 static int download_counter;
224 const char *type = cls;
225 struct GNUNET_TIME_Relative del;
227 struct StatMaster *sm;
229 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
231 del = GNUNET_TIME_absolute_get_duration (start_time);
232 if (del.rel_value == 0)
235 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
236 1000LL / del.rel_value);
237 fprintf (stderr, "Download speed of type `%s' was %s/s\n", type, fancy);
239 if (NUM_DAEMONS != ++download_counter)
240 return; /* more downloads to come */
241 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
242 "Finished all downloads, shutting down\n",
243 (unsigned long long) FILESIZE);
244 sm = GNUNET_malloc (sizeof (struct StatMaster));
246 GNUNET_STATISTICS_create ("<driver>",
247 GNUNET_FS_TEST_get_configuration (daemons,
249 GNUNET_SCHEDULER_add_now (&stat_run, sm);
253 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
254 "Timeout during download for type `%s', shutting down with error\n",
257 GNUNET_SCHEDULER_add_now (&do_stop, NULL);
263 do_downloads (void *cls, const struct GNUNET_FS_Uri *u2)
270 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
271 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
272 "Timeout during upload attempt, shutting down with error\n");
276 uri2 = GNUNET_FS_uri_dup (u2);
277 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n",
278 (unsigned long long) FILESIZE);
279 start_time = GNUNET_TIME_absolute_get ();
280 if (NULL != strstr (progname, "dht"))
284 /* (semi) leach-download(s); not true leaches since
285 * these peers do participate in sharing, they just
286 * don't have to offer anything *initially*. */
287 for (i = 0; i < NUM_DAEMONS - 2; i++)
288 GNUNET_FS_TEST_download (daemons[i], TIMEOUT, anonymity,
289 0 == (i % 2) ? SEED1 : SEED2,
290 0 == (i % 2) ? uri1 : uri2, VERBOSE, &do_report,
292 /* mutual downloads of (primary) sharing peers */
293 GNUNET_FS_TEST_download (daemons[NUM_DAEMONS - 2], TIMEOUT, anonymity, SEED1,
294 uri1, VERBOSE, &do_report, "seeder 2");
295 GNUNET_FS_TEST_download (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, SEED2,
296 uri2, VERBOSE, &do_report, "seeder 1");
301 do_publish2 (void *cls, const struct GNUNET_FS_Uri *u1)
308 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
309 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
310 "Timeout during upload attempt, shutting down with error\n");
314 uri1 = GNUNET_FS_uri_dup (u1);
315 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
316 (unsigned long long) FILESIZE);
317 if (NULL != strstr (progname, "index"))
318 do_index = GNUNET_YES;
320 do_index = GNUNET_NO;
321 if (NULL != strstr (progname, "dht"))
326 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 2], TIMEOUT, anonymity,
327 do_index, FILESIZE, SEED2, VERBOSE, &do_downloads,
332 do_publish1 (void *cls, const char *emsg)
339 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS, daemons);
340 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n", emsg);
344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
345 (unsigned long long) FILESIZE);
346 if (NULL != strstr (progname, "index"))
347 do_index = GNUNET_YES;
349 do_index = GNUNET_NO;
350 if (NULL != strstr (progname, "dht"))
355 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity,
356 do_index, FILESIZE, SEED1, VERBOSE, &do_publish2,
362 do_connect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
364 struct GNUNET_TESTING_PeerGroup *pg;
366 GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE));
367 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
368 "Daemons started, will now try to connect them\n");
369 pg = GNUNET_FS_TEST_get_group (daemons);
370 GNUNET_TESTING_create_topology (pg, GNUNET_TESTING_TOPOLOGY_CLIQUE,
371 GNUNET_TESTING_TOPOLOGY_NONE, NULL);
372 GNUNET_TESTING_connect_topology (pg, GNUNET_TESTING_TOPOLOGY_CLIQUE,
373 GNUNET_TESTING_TOPOLOGY_OPTION_NONE, 0.0,
374 TIMEOUT, NUM_DAEMONS, &do_publish1, NULL);
379 run (void *cls, char *const *args, const char *cfgfile,
380 const struct GNUNET_CONFIGURATION_Handle *cfg)
382 GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf", TIMEOUT, NUM_DAEMONS,
383 daemons, &do_connect, NULL);
388 main (int argc, char *argv[])
390 char *const argvx[] = {
391 "perf-gnunet-service-fs-p2p",
393 "fs_test_lib_data.conf",
399 struct GNUNET_GETOPT_CommandLineOption options[] = {
400 GNUNET_GETOPT_OPTION_END
403 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
404 GNUNET_log_setup ("perf_gnunet_service_fs_p2p_trust",
411 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, argvx,
412 "perf-gnunet-service-fs-p2p-trust", "nohelp", options,
414 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
418 /* end of perf_gnunet_service_fs_p2p_trust.c */