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 sm->stat = ca_result;
228 GNUNET_assert (NULL != sm->stat);
229 if (NULL != stats[sm->value].name)
231 GNUNET_STATISTICS_get (sm->stat,
235 stats[sm->value].subsystem, stats[sm->value].name,
237 GNUNET_TIME_UNIT_FOREVER_REL, &get_done, &print_stat,
241 GNUNET_TESTBED_operation_done (sm->op);
244 if (NUM_DAEMONS == sm->daemon)
247 GNUNET_SCHEDULER_shutdown ();
251 GNUNET_TESTBED_service_connect (NULL,
255 &statistics_connect_adapter,
256 &statistics_disconnect_adapter,
262 do_report (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
264 static int download_counter;
265 const char *type = cls;
266 struct GNUNET_TIME_Relative del;
268 struct StatMaster *sm;
270 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_PREREQ_DONE))
272 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
273 "Timeout during download for type `%s', shutting down with error\n",
276 GNUNET_SCHEDULER_shutdown ();
279 del = GNUNET_TIME_absolute_get_duration (start_time);
280 if (del.rel_value == 0)
283 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
284 1000LL / del.rel_value);
285 FPRINTF (stderr, "Download speed of type `%s' was %s/s\n", type, fancy);
287 if (NUM_DAEMONS != ++download_counter)
288 return; /* more downloads to come */
289 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
290 "Finished all downloads, getting statistics\n");
291 sm = GNUNET_malloc (sizeof (struct StatMaster));
293 GNUNET_TESTBED_service_connect (NULL,
297 &statistics_connect_adapter,
298 &statistics_disconnect_adapter,
304 do_downloads (void *cls, const struct GNUNET_FS_Uri *u2)
311 GNUNET_SCHEDULER_shutdown ();
312 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
313 "Timeout during upload attempt, shutting down with error\n");
317 uri2 = GNUNET_FS_uri_dup (u2);
318 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n",
319 (unsigned long long) FILESIZE);
320 start_time = GNUNET_TIME_absolute_get ();
321 if (NULL != strstr (progname, "dht"))
325 /* (semi) leach-download(s); not true leaches since
326 * these peers do participate in sharing, they just
327 * don't have to offer anything *initially*. */
328 for (i = 0; i < NUM_DAEMONS - 2; i++)
329 GNUNET_FS_TEST_download (daemons[i], TIMEOUT, anonymity,
330 0 == (i % 2) ? SEED1 : SEED2,
331 0 == (i % 2) ? uri1 : uri2, VERBOSE, &do_report,
333 /* mutual downloads of (primary) sharing peers */
334 GNUNET_FS_TEST_download (daemons[NUM_DAEMONS - 2], TIMEOUT, anonymity, SEED1,
335 uri1, VERBOSE, &do_report, "seeder 2");
336 GNUNET_FS_TEST_download (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, SEED2,
337 uri2, VERBOSE, &do_report, "seeder 1");
342 do_publish2 (void *cls,
343 const struct GNUNET_FS_Uri *u1)
350 GNUNET_SCHEDULER_shutdown ();
351 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
352 "Timeout during upload attempt, shutting down with error\n");
356 uri1 = GNUNET_FS_uri_dup (u1);
357 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
358 (unsigned long long) FILESIZE);
359 if (NULL != strstr (progname, "index"))
360 do_index = GNUNET_YES;
362 do_index = GNUNET_NO;
363 if (NULL != strstr (progname, "dht"))
368 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 2], TIMEOUT, anonymity,
369 do_index, FILESIZE, SEED2, VERBOSE, &do_downloads,
375 do_publish1 (void *cls,
376 struct GNUNET_TESTBED_Operation *op,
379 unsigned int *coco = cls;
383 GNUNET_TESTBED_operation_done (op);
386 GNUNET_SCHEDULER_shutdown ();
387 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n", emsg);
391 if (0 != (--(*coco)))
392 return; /* more connections to be created */
393 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
394 (unsigned long long) FILESIZE);
395 if (NULL != strstr (progname, "index"))
396 do_index = GNUNET_YES;
398 do_index = GNUNET_NO;
399 if (NULL != strstr (progname, "dht"))
403 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity,
404 do_index, FILESIZE, SEED1, VERBOSE, &do_publish2,
410 do_connect (void *cls,
411 unsigned int num_peers,
412 struct GNUNET_TESTBED_Peer **peers)
414 static unsigned int coco;
418 GNUNET_assert (NUM_DAEMONS == num_peers);
419 for (i=0;i<num_peers;i++)
420 daemons[i] = peers[i];
421 for (i=0;i<NUM_DAEMONS;i++)
422 for (j=i+1;j<NUM_DAEMONS;j++)
425 GNUNET_TESTBED_overlay_connect (NULL,
435 main (int argc, char *argv[])
438 (void) GNUNET_TESTBED_test_run ("perf-gnunet-service-fs-p2p-respect",
439 "perf_gnunet_service_fs_p2p.conf",
443 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
447 /* end of perf_gnunet_service_fs_p2p_respect.c */