2 This file is part of GNUnet.
3 Copyright (C) 2010, 2011, 2012 GNUnet e.V.
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your 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 Affero General Public License for more details.
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 * @file fs/perf_gnunet_service_fs_p2p_respect.c
21 * @brief profile P2P routing respect mechanism. Creates
22 * a clique of NUM_DAEMONS (i.e. 3) where two
23 * peers share (seed) different files and download
24 * them from each other while all the other peers
25 * just "leach" those files. Ideally, the seeders
26 * "learn" that they contribute (to each other),
27 * and give the other seeder higher priority;
28 * naturally, this only happens nicely for larger
29 * files; finally, once the seeders are done, the
30 * leachers should see fast download rates as well.
31 * @author Christian Grothoff
34 * - 10 MB, 3 peers, with delays:
35 * Download speed of type `seeder 1' was 757 KiB/s
36 * Download speed of type `seeder 2' was 613 KiB/s
37 * Download speed of type `leach` was 539 KiB/s
39 * - 10 MB, 3 peers, without delays:
40 * Download speed of type `seeder 1' was 1784 KiB/s
41 * Download speed of type `seeder 2' was 1604 KiB/s
42 * Download speed of type `leach` was 1384 KiB/s
45 #include "fs_test_lib.h"
46 #include "gnunet_testbed_service.h"
48 #define VERBOSE GNUNET_NO
51 * File-size we use for testing.
53 #define FILESIZE (1024 * 1024 * 1)
56 * How long until we give up on transmitting the message?
58 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 30)
61 * Number of daemons in clique, must be at least 3 (!).
66 * Seed for first file on offer.
71 * Seed for second file on offer.
75 static struct GNUNET_TESTBED_Peer *daemons[NUM_DAEMONS];
79 static struct GNUNET_TIME_Absolute start_time;
81 static const char *progname;
83 static struct GNUNET_FS_Uri *uri1;
85 static struct GNUNET_FS_Uri *uri2;
92 * Master context for 'stat_run'.
96 struct GNUNET_STATISTICS_Handle *stat;
97 struct GNUNET_TESTBED_Operation *op;
104 const char *subsystem;
109 * Statistics we print out.
111 static struct StatValues stats[] = {
112 {"fs", "# artificial delays introduced (ms)"},
113 {"fs", "# queries forwarded"},
114 {"fs", "# replies received and matched"},
115 {"fs", "# results found locally"},
116 {"fs", "# requests forwarded due to high load"},
117 {"fs", "# requests done for free (low load)"},
118 {"fs", "# requests dropped, priority insufficient"},
119 {"fs", "# requests done for a price (normal load)"},
120 {"fs", "# requests dropped by datastore (queue length limit)"},
121 {"fs", "# P2P searches received"},
122 {"fs", "# P2P searches discarded (queue length bound)"},
123 {"fs", "# replies received for local clients"},
124 {"fs", "# queries retransmitted to same target"},
125 {"core", "# bytes decrypted"},
126 {"core", "# bytes encrypted"},
127 {"core", "# discarded CORE_SEND requests"},
128 {"core", "# discarded lower priority CORE_SEND requests"},
129 {"transport", "# bytes received via TCP"},
130 {"transport", "# bytes transmitted via TCP"},
131 {"datacache", "# bytes stored"},
139 GNUNET_SCHEDULER_shutdown ();
142 GNUNET_DISK_directory_remove (fn1);
147 GNUNET_DISK_directory_remove (fn2);
154 * Callback function to process statistic values.
157 * @param subsystem name of subsystem that created the statistic
158 * @param name the name of the datum
159 * @param value the current value
160 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
161 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
164 print_stat (void *cls, const char *subsystem, const char *name, uint64_t value,
167 struct StatMaster *sm = cls;
169 FPRINTF (stderr, "Peer %2u: %12s/%50s = %12llu\n", sm->daemon, subsystem,
170 name, (unsigned long long) value);
176 * Function that gathers stats from all daemons.
180 struct GNUNET_TESTBED_Operation *op,
186 * Function called when GET operation on stats is done.
189 get_done (void *cls, int success)
191 struct StatMaster *sm = cls;
193 GNUNET_break (GNUNET_OK == success);
195 stat_run (sm, sm->op, sm->stat, NULL);
201 * Adapter function called to establish a connection to
202 * statistics service.
205 * @param cfg configuration of the peer to connect to; will be available until
206 * GNUNET_TESTBED_operation_done() is called on the operation returned
207 * from GNUNET_TESTBED_service_connect()
208 * @return service handle to return in 'op_result', NULL on error
211 statistics_connect_adapter (void *cls,
212 const struct GNUNET_CONFIGURATION_Handle *cfg)
214 return GNUNET_STATISTICS_create ("<driver>",
220 * Adapter function called to destroy a connection to
221 * statistics service.
224 * @param op_result service handle returned from the connect adapter
227 statistics_disconnect_adapter (void *cls,
230 GNUNET_STATISTICS_destroy (op_result, GNUNET_NO);
235 * Function that gathers stats from all daemons.
239 struct GNUNET_TESTBED_Operation *op,
243 struct StatMaster *sm = cls;
245 sm->stat = ca_result;
246 GNUNET_assert (NULL != sm->stat);
247 if (NULL != stats[sm->value].name)
249 GNUNET_STATISTICS_get (sm->stat,
253 stats[sm->value].subsystem, stats[sm->value].name,
255 &get_done, &print_stat,
259 GNUNET_TESTBED_operation_done (sm->op);
262 if (NUM_DAEMONS == sm->daemon)
269 GNUNET_TESTBED_service_connect (NULL,
273 &statistics_connect_adapter,
274 &statistics_disconnect_adapter,
280 do_report (void *cls)
282 static int download_counter;
283 const char *type = cls;
284 struct GNUNET_TIME_Relative del;
286 struct StatMaster *sm;
289 GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time,
290 TIMEOUT)).rel_value_us)
292 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
293 "Timeout during download for type `%s', shutting down with error\n",
299 del = GNUNET_TIME_absolute_get_duration (start_time);
300 if (del.rel_value_us == 0)
301 del.rel_value_us = 1;
303 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
304 1000000LL / del.rel_value_us);
305 FPRINTF (stderr, "Download speed of type `%s' was %s/s\n", type, fancy);
307 if (NUM_DAEMONS != ++download_counter)
308 return; /* more downloads to come */
309 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
310 "Finished all downloads, getting statistics\n");
311 sm = GNUNET_new (struct StatMaster);
313 GNUNET_TESTBED_service_connect (NULL,
317 &statistics_connect_adapter,
318 &statistics_disconnect_adapter,
324 do_downloads (void *cls, const struct GNUNET_FS_Uri *u2,
333 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
334 "Timeout during upload attempt, shutting down with error\n");
339 fn2 = GNUNET_strdup (fn);
340 uri2 = GNUNET_FS_uri_dup (u2);
341 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n",
342 (unsigned long long) FILESIZE);
343 start_time = GNUNET_TIME_absolute_get ();
344 if (NULL != strstr (progname, "dht"))
348 /* (semi) leach-download(s); not true leaches since
349 * these peers do participate in sharing, they just
350 * don't have to offer anything *initially*. */
351 for (i = 0; i < NUM_DAEMONS - 2; i++)
352 GNUNET_FS_TEST_download (daemons[i], TIMEOUT, anonymity,
353 0 == (i % 2) ? SEED1 : SEED2,
354 0 == (i % 2) ? uri1 : uri2, VERBOSE, &do_report,
356 /* mutual downloads of (primary) sharing peers */
357 GNUNET_FS_TEST_download (daemons[NUM_DAEMONS - 2], TIMEOUT, anonymity, SEED1,
358 uri1, VERBOSE, &do_report, "seeder 2");
359 GNUNET_FS_TEST_download (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, SEED2,
360 uri2, VERBOSE, &do_report, "seeder 1");
365 do_publish2 (void *cls,
366 const struct GNUNET_FS_Uri *u1,
375 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
376 "Timeout during upload attempt, shutting down with error\n");
381 fn1 = GNUNET_strdup (fn);
382 uri1 = GNUNET_FS_uri_dup (u1);
383 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
384 (unsigned long long) FILESIZE);
385 if (NULL != strstr (progname, "index"))
386 do_index = GNUNET_YES;
388 do_index = GNUNET_NO;
389 if (NULL != strstr (progname, "dht"))
394 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 2], TIMEOUT, anonymity,
395 do_index, FILESIZE, SEED2, VERBOSE, &do_downloads,
401 do_publish1 (void *cls,
402 struct GNUNET_TESTBED_Operation *op,
405 unsigned int *coco = cls;
409 GNUNET_TESTBED_operation_done (op);
413 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n", emsg);
417 if (0 != (--(*coco)))
418 return; /* more connections to be created */
419 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
420 (unsigned long long) FILESIZE);
421 if (NULL != strstr (progname, "index"))
422 do_index = GNUNET_YES;
424 do_index = GNUNET_NO;
425 if (NULL != strstr (progname, "dht"))
429 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity,
430 do_index, FILESIZE, SEED1, VERBOSE, &do_publish2,
436 do_connect (void *cls,
437 struct GNUNET_TESTBED_RunHandle *h,
438 unsigned int num_peers,
439 struct GNUNET_TESTBED_Peer **peers,
440 unsigned int links_succeeded,
441 unsigned int links_failed)
443 static unsigned int coco;
447 GNUNET_assert (NUM_DAEMONS == num_peers);
448 for (i=0;i<num_peers;i++)
449 daemons[i] = peers[i];
450 for (i=0;i<NUM_DAEMONS;i++)
451 for (j=i+1;j<NUM_DAEMONS;j++)
454 GNUNET_TESTBED_overlay_connect (NULL,
464 main (int argc, char *argv[])
467 (void) GNUNET_TESTBED_test_run ("perf-gnunet-service-fs-p2p-respect",
468 "perf_gnunet_service_fs_p2p.conf",
472 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
476 /* end of perf_gnunet_service_fs_p2p_respect.c */