2 This file is part of GNUnet.
3 (C) 2010, 2011, 2012 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_respect.c
23 * @brief profile P2P routing respect 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_testbed_service.h"
50 #define VERBOSE GNUNET_NO
53 * File-size we use for testing.
55 #define FILESIZE (1024 * 1024 * 1)
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_TESTBED_Peer *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;
91 * Master context for 'stat_run'.
95 struct GNUNET_STATISTICS_Handle *stat;
96 struct GNUNET_TESTBED_Operation *op;
103 const char *subsystem;
108 * Statistics we print out.
110 static struct StatValues stats[] = {
111 {"fs", "# artificial delays introduced (ms)"},
112 {"fs", "# queries forwarded"},
113 {"fs", "# replies received and matched"},
114 {"fs", "# results found locally"},
115 {"fs", "# requests forwarded due to high load"},
116 {"fs", "# requests done for free (low load)"},
117 {"fs", "# requests dropped, priority insufficient"},
118 {"fs", "# requests done for a price (normal load)"},
119 {"fs", "# requests dropped by datastore (queue length limit)"},
120 {"fs", "# P2P searches received"},
121 {"fs", "# P2P searches discarded (queue length bound)"},
122 {"fs", "# replies received for local clients"},
123 {"fs", "# queries retransmitted to same target"},
124 {"core", "# bytes decrypted"},
125 {"core", "# bytes encrypted"},
126 {"core", "# discarded CORE_SEND requests"},
127 {"core", "# discarded lower priority CORE_SEND requests"},
128 {"transport", "# bytes received via TCP"},
129 {"transport", "# bytes transmitted via TCP"},
130 {"datacache", "# bytes stored"},
136 * Callback function to process statistic values.
139 * @param subsystem name of subsystem that created the statistic
140 * @param name the name of the datum
141 * @param value the current value
142 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
143 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
146 print_stat (void *cls, const char *subsystem, const char *name, uint64_t value,
149 struct StatMaster *sm = cls;
151 FPRINTF (stderr, "Peer %2u: %12s/%50s = %12llu\n", sm->daemon, subsystem,
152 name, (unsigned long long) value);
158 * Function that gathers stats from all daemons.
162 struct GNUNET_TESTBED_Operation *op,
168 * Function called when GET operation on stats is done.
171 get_done (void *cls, int success)
173 struct StatMaster *sm = cls;
175 GNUNET_break (GNUNET_OK == success);
177 stat_run (sm, sm->op, sm->stat, NULL);
183 * Adapter function called to establish a connection to
184 * statistics service.
187 * @param cfg configuration of the peer to connect to; will be available until
188 * GNUNET_TESTBED_operation_done() is called on the operation returned
189 * from GNUNET_TESTBED_service_connect()
190 * @return service handle to return in 'op_result', NULL on error
193 statistics_connect_adapter (void *cls,
194 const struct GNUNET_CONFIGURATION_Handle *cfg)
196 return GNUNET_STATISTICS_create ("<driver>",
202 * Adapter function called to destroy a connection to
203 * statistics service.
206 * @param op_result service handle returned from the connect adapter
209 statistics_disconnect_adapter (void *cls,
212 GNUNET_STATISTICS_destroy (op_result, GNUNET_NO);
217 * Function that gathers stats from all daemons.
221 struct GNUNET_TESTBED_Operation *op,
225 struct StatMaster *sm = cls;
227 if (stats[sm->value].name != NULL)
229 GNUNET_STATISTICS_get (sm->stat,
233 stats[sm->value].subsystem, stats[sm->value].name,
235 GNUNET_TIME_UNIT_FOREVER_REL, &get_done, &print_stat,
239 GNUNET_TESTBED_operation_done (sm->op);
242 if (NUM_DAEMONS == sm->daemon)
245 GNUNET_SCHEDULER_shutdown ();
249 GNUNET_TESTBED_service_connect (NULL,
253 &statistics_connect_adapter,
254 &statistics_disconnect_adapter,
260 do_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
262 static int download_counter;
263 const char *type = cls;
264 struct GNUNET_TIME_Relative del;
266 struct StatMaster *sm;
268 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
270 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
271 "Timeout during download for type `%s', shutting down with error\n",
274 GNUNET_SCHEDULER_shutdown ();
277 del = GNUNET_TIME_absolute_get_duration (start_time);
278 if (del.rel_value == 0)
281 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
282 1000LL / del.rel_value);
283 FPRINTF (stderr, "Download speed of type `%s' was %s/s\n", type, fancy);
285 if (NUM_DAEMONS != ++download_counter)
286 return; /* more downloads to come */
287 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
288 "Finished all downloads, shutting down\n",
289 (unsigned long long) FILESIZE);
290 sm = GNUNET_malloc (sizeof (struct StatMaster));
292 GNUNET_TESTBED_service_connect (NULL,
296 &statistics_connect_adapter,
297 &statistics_disconnect_adapter,
303 do_downloads (void *cls, const struct GNUNET_FS_Uri *u2)
310 GNUNET_SCHEDULER_shutdown ();
311 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
312 "Timeout during upload attempt, shutting down with error\n");
316 uri2 = GNUNET_FS_uri_dup (u2);
317 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n",
318 (unsigned long long) FILESIZE);
319 start_time = GNUNET_TIME_absolute_get ();
320 if (NULL != strstr (progname, "dht"))
324 /* (semi) leach-download(s); not true leaches since
325 * these peers do participate in sharing, they just
326 * don't have to offer anything *initially*. */
327 for (i = 0; i < NUM_DAEMONS - 2; i++)
328 GNUNET_FS_TEST_download (daemons[i], TIMEOUT, anonymity,
329 0 == (i % 2) ? SEED1 : SEED2,
330 0 == (i % 2) ? uri1 : uri2, VERBOSE, &do_report,
332 /* mutual downloads of (primary) sharing peers */
333 GNUNET_FS_TEST_download (daemons[NUM_DAEMONS - 2], TIMEOUT, anonymity, SEED1,
334 uri1, VERBOSE, &do_report, "seeder 2");
335 GNUNET_FS_TEST_download (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, SEED2,
336 uri2, VERBOSE, &do_report, "seeder 1");
341 do_publish2 (void *cls,
342 const struct GNUNET_FS_Uri *u1)
349 GNUNET_SCHEDULER_shutdown ();
350 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
351 "Timeout during upload attempt, shutting down with error\n");
355 uri1 = GNUNET_FS_uri_dup (u1);
356 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
357 (unsigned long long) FILESIZE);
358 if (NULL != strstr (progname, "index"))
359 do_index = GNUNET_YES;
361 do_index = GNUNET_NO;
362 if (NULL != strstr (progname, "dht"))
367 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 2], TIMEOUT, anonymity,
368 do_index, FILESIZE, SEED2, VERBOSE, &do_downloads,
374 do_publish1 (void *cls,
375 struct GNUNET_TESTBED_Operation *op,
378 unsigned int *coco = cls;
382 GNUNET_TESTBED_operation_done (op);
385 GNUNET_SCHEDULER_shutdown ();
386 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n", emsg);
390 if (0 != (--(*coco)))
391 return; /* more connections to be created */
392 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
393 (unsigned long long) FILESIZE);
394 if (NULL != strstr (progname, "index"))
395 do_index = GNUNET_YES;
397 do_index = GNUNET_NO;
398 if (NULL != strstr (progname, "dht"))
402 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity,
403 do_index, FILESIZE, SEED1, VERBOSE, &do_publish2,
409 do_connect (void *cls,
410 unsigned int num_peers,
411 struct GNUNET_TESTBED_Peer **peers)
413 static unsigned int coco;
417 GNUNET_assert (NUM_DAEMONS == num_peers);
418 for (i=0;i<num_peers;i++)
419 daemons[i] = peers[i];
420 for (i=0;i<NUM_DAEMONS;i++)
421 for (j=i+1;j<NUM_DAEMONS;j++)
424 GNUNET_TESTBED_overlay_connect (NULL,
434 main (int argc, char *argv[])
437 GNUNET_TESTBED_test_run ("perf-gnunet-service-fs-p2p-respect",
438 "perf_gnunet_service_fs_p2p.conf",
442 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
446 /* end of perf_gnunet_service_fs_p2p_respect.c */