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
37 * Download speed of type `seeder 1' was 3864 KiB/s
38 * Download speed of type `seeder 2' was 3764 KiB/s
39 * Download speed of type `leach' was 3592 KiB/s
40 * Analysis: download too small for trust to go into effect
42 * Download speed of type `seeder 1' was 4018 KiB/s
43 * Download speed of type `seeder 2' was 4016 KiB/s
45 * Analysis: leach squeezed out entirely early, then backs off far too
46 * far => fails to ever recover (code needs improvement...)
47 * [system load is initially very high, then drops to 0
48 * after seeders are done]
51 #include "fs_test_lib.h"
52 #include "gnunet_testing_lib.h"
54 #define VERBOSE GNUNET_YES
57 * File-size we use for testing.
59 #define FILESIZE (1024 * 1024 * 10)
62 * How long until we give up on transmitting the message?
64 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
67 * Number of daemons in clique, must be at least 3 (!).
72 * Seed for first file on offer.
77 * Seed for second file on offer.
81 static struct GNUNET_FS_TestDaemon *daemons[NUM_DAEMONS];
85 static struct GNUNET_TIME_Absolute start_time;
87 static const char *progname;
89 static struct GNUNET_FS_Uri *uri1;
91 static struct GNUNET_FS_Uri *uri2;
95 const struct GNUNET_SCHEDULER_TaskContext *tc)
97 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS,
103 * Master context for 'stat_run'.
107 struct GNUNET_STATISTICS_Handle *stat;
114 const char *subsystem;
119 * Statistics we print out.
121 static struct StatValues stats[] =
123 { "fs", "# queries forwarded"},
124 { "fs", "# replies received and matched"},
125 { "fs", "# results found locally"},
126 { "fs", "# requests forwarded due to high load"},
127 { "fs", "# requests done for free (low load)"},
128 { "fs", "# requests dropped, priority insufficient"},
129 { "fs", "# requests done for a price (normal load)"},
130 { "fs", "# requests dropped by datastore (queue length limit)"},
131 { "fs", "# P2P searches received"},
132 { "fs", "# P2P searches discarded (queue length bound)"},
133 { "fs", "# replies received for local clients"},
134 { "fs", "# queries retransmitted to same target"},
135 { "fs", "cummulative artificial delay introduced (ms)"},
136 { "core", "# bytes decrypted"},
137 { "core", "# bytes encrypted"},
138 { "core", "# discarded CORE_SEND requests"},
139 { "core", "# discarded CORE_SEND request bytes"},
140 { "core", "# discarded lower priority CORE_SEND requests"},
141 { "core", "# discarded lower priority CORE_SEND request bytes"},
142 { "transport", "# bytes received via TCP"},
143 { "transport", "# bytes transmitted via TCP"},
144 { "datacache", "# bytes stored"},
150 * Callback function to process statistic values.
153 * @param subsystem name of subsystem that created the statistic
154 * @param name the name of the datum
155 * @param value the current value
156 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
157 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
160 print_stat (void *cls,
161 const char *subsystem,
166 struct StatMaster *sm = cls;
168 "Peer %2u: %12s/%50s = %12llu\n",
172 (unsigned long long) value);
178 * Function that gathers stats from all daemons.
182 const struct GNUNET_SCHEDULER_TaskContext *tc);
186 * Function called when GET operation on stats is done.
192 struct StatMaster *sm = cls;
193 GNUNET_break (GNUNET_OK == success);
195 GNUNET_SCHEDULER_add_now (&stat_run, sm);
200 * Function that gathers stats from all daemons.
204 const struct GNUNET_SCHEDULER_TaskContext *tc)
206 struct StatMaster *sm = cls;
208 if (stats[sm->value].name != NULL)
210 GNUNET_STATISTICS_get (sm->stat,
214 stats[sm->value].subsystem,
215 stats[sm->value].name,
217 GNUNET_TIME_UNIT_FOREVER_REL,
222 GNUNET_STATISTICS_destroy (sm->stat, GNUNET_NO);
225 if (sm->daemon == NUM_DAEMONS)
228 GNUNET_SCHEDULER_add_now (&do_stop, NULL);
231 sm->stat = GNUNET_STATISTICS_create ("<driver>",
232 GNUNET_FS_TEST_get_configuration (daemons,
234 GNUNET_SCHEDULER_add_now (&stat_run, sm);
239 do_report (void *cls,
240 const struct GNUNET_SCHEDULER_TaskContext *tc)
242 static int download_counter;
243 const char *type = cls;
244 struct GNUNET_TIME_Relative del;
246 struct StatMaster *sm;
248 if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
250 del = GNUNET_TIME_absolute_get_duration (start_time);
251 if (del.rel_value == 0)
253 fancy = GNUNET_STRINGS_byte_size_fancy (((unsigned long long)FILESIZE) * 1000LL / del.rel_value);
255 "Download speed of type `%s' was %s/s\n",
259 if (NUM_DAEMONS != ++download_counter)
260 return; /* more downloads to come */
261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
262 "Finished all downloads, shutting down\n",
263 (unsigned long long) FILESIZE);
264 sm = GNUNET_malloc (sizeof (struct StatMaster));
265 sm->stat = GNUNET_STATISTICS_create ("<driver>",
266 GNUNET_FS_TEST_get_configuration (daemons,
268 GNUNET_SCHEDULER_add_now (&stat_run, sm);
272 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
273 "Timeout during download for type `%s', shutting down with error\n",
276 GNUNET_SCHEDULER_add_now (&do_stop, NULL);
282 do_downloads (void *cls,
283 const struct GNUNET_FS_Uri *u2)
290 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS,
292 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
293 "Timeout during upload attempt, shutting down with error\n");
297 uri2 = GNUNET_FS_uri_dup (u2);
298 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
299 "Downloading %llu bytes\n",
300 (unsigned long long) FILESIZE);
301 start_time = GNUNET_TIME_absolute_get ();
302 if (NULL != strstr (progname, "dht"))
306 /* (semi) leach-download(s); not true leaches since
307 these peers do participate in sharing, they just
308 don't have to offer anything *initially*. */
309 for (i=0;i<NUM_DAEMONS-2;i++)
310 GNUNET_FS_TEST_download (daemons[i],
313 0 == (i%2) ? SEED1 : SEED2,
314 0 == (i%2) ? uri1 : uri2,
316 &do_report, "leach");
317 /* mutual downloads of (primary) sharing peers */
318 GNUNET_FS_TEST_download (daemons[NUM_DAEMONS-1],
320 anonymity, SEED1, uri1,
322 &do_report, "seeder 2");
323 GNUNET_FS_TEST_download (daemons[NUM_DAEMONS-2],
325 anonymity, SEED2, uri2,
327 &do_report, "seeder 1");
332 do_publish2 (void *cls,
333 const struct GNUNET_FS_Uri *u1)
340 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS,
342 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
343 "Timeout during upload attempt, shutting down with error\n");
347 uri1 = GNUNET_FS_uri_dup (u1);
348 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
349 "Publishing %llu bytes\n",
350 (unsigned long long) FILESIZE);
351 if (NULL != strstr (progname, "index"))
352 do_index = GNUNET_YES;
354 do_index = GNUNET_NO;
355 if (NULL != strstr (progname, "dht"))
360 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS-2],
363 do_index, FILESIZE, SEED2,
365 &do_downloads, NULL);
369 do_publish1 (void *cls,
377 GNUNET_FS_TEST_daemons_stop (NUM_DAEMONS,
379 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
380 "Error trying to connect: %s\n",
385 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
386 "Publishing %llu bytes\n",
387 (unsigned long long) FILESIZE);
388 if (NULL != strstr (progname, "index"))
389 do_index = GNUNET_YES;
391 do_index = GNUNET_NO;
392 if (NULL != strstr (progname, "dht"))
397 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS-1],
400 do_index, FILESIZE, SEED1,
407 do_connect (void *cls,
408 const struct GNUNET_SCHEDULER_TaskContext *tc)
410 struct GNUNET_TESTING_PeerGroup *pg;
412 GNUNET_assert (0 != (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE));
413 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
414 "Daemons started, will now try to connect them\n");
415 pg = GNUNET_FS_TEST_get_group (daemons);
416 GNUNET_TESTING_create_topology (pg,
417 GNUNET_TESTING_TOPOLOGY_CLIQUE,
418 GNUNET_TESTING_TOPOLOGY_NONE,
420 GNUNET_TESTING_connect_topology (pg,
421 GNUNET_TESTING_TOPOLOGY_CLIQUE,
422 GNUNET_TESTING_TOPOLOGY_OPTION_NONE,
435 const struct GNUNET_CONFIGURATION_Handle *cfg)
437 GNUNET_FS_TEST_daemons_start ("fs_test_lib_data.conf",
447 main (int argc, char *argv[])
449 char *const argvx[] = {
450 "perf-gnunet-service-fs-p2p",
452 "fs_test_lib_data.conf",
458 struct GNUNET_GETOPT_CommandLineOption options[] = {
459 GNUNET_GETOPT_OPTION_END
462 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
463 GNUNET_log_setup ("perf_gnunet_service_fs_p2p_trust",
470 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
471 argvx, "perf-gnunet-service-fs-p2p-trust",
472 "nohelp", options, &run, NULL);
473 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
477 /* end of perf_gnunet_service_fs_p2p_trust.c */