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/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
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;
94 * Master context for 'stat_run'.
98 struct GNUNET_STATISTICS_Handle *stat;
99 struct GNUNET_TESTBED_Operation *op;
106 const char *subsystem;
111 * Statistics we print out.
113 static struct StatValues stats[] = {
114 { "fs", "# artificial delays introduced (ms)" },
115 { "fs", "# queries forwarded" },
116 { "fs", "# replies received and matched" },
117 { "fs", "# results found locally" },
118 { "fs", "# requests forwarded due to high load" },
119 { "fs", "# requests done for free (low load)" },
120 { "fs", "# requests dropped, priority insufficient" },
121 { "fs", "# requests done for a price (normal load)" },
122 { "fs", "# requests dropped by datastore (queue length limit)" },
123 { "fs", "# P2P searches received" },
124 { "fs", "# P2P searches discarded (queue length bound)" },
125 { "fs", "# replies received for local clients" },
126 { "fs", "# queries retransmitted to same target" },
127 { "core", "# bytes decrypted" },
128 { "core", "# bytes encrypted" },
129 { "core", "# discarded CORE_SEND requests" },
130 { "core", "# discarded lower priority CORE_SEND requests" },
131 { "transport", "# bytes received via TCP" },
132 { "transport", "# bytes transmitted via TCP" },
133 { "datacache", "# bytes stored" },
141 GNUNET_SCHEDULER_shutdown ();
144 GNUNET_DISK_directory_remove (fn1);
149 GNUNET_DISK_directory_remove (fn2);
156 * Callback function to process statistic values.
159 * @param subsystem name of subsystem that created the statistic
160 * @param name the name of the datum
161 * @param value the current value
162 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
163 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
166 print_stat (void *cls, const char *subsystem, const char *name, uint64_t value,
169 struct StatMaster *sm = cls;
171 fprintf (stderr, "Peer %2u: %12s/%50s = %12llu\n", sm->daemon, subsystem,
172 name, (unsigned long long) value);
178 * Function that gathers stats from all daemons.
182 struct GNUNET_TESTBED_Operation *op,
188 * Function called when GET operation on stats is done.
191 get_done (void *cls, int success)
193 struct StatMaster *sm = cls;
195 GNUNET_break (GNUNET_OK == success);
197 stat_run (sm, sm->op, sm->stat, NULL);
203 * Adapter function called to establish a connection to
204 * statistics service.
207 * @param cfg configuration of the peer to connect to; will be available until
208 * GNUNET_TESTBED_operation_done() is called on the operation returned
209 * from GNUNET_TESTBED_service_connect()
210 * @return service handle to return in 'op_result', NULL on error
213 statistics_connect_adapter (void *cls,
214 const struct GNUNET_CONFIGURATION_Handle *cfg)
216 return GNUNET_STATISTICS_create ("<driver>",
222 * Adapter function called to destroy a connection to
223 * statistics service.
226 * @param op_result service handle returned from the connect adapter
229 statistics_disconnect_adapter (void *cls,
232 GNUNET_STATISTICS_destroy (op_result, GNUNET_NO);
237 * Function that gathers stats from all daemons.
241 struct GNUNET_TESTBED_Operation *op,
245 struct StatMaster *sm = cls;
247 sm->stat = ca_result;
248 GNUNET_assert (NULL != sm->stat);
249 if (NULL != stats[sm->value].name)
251 GNUNET_STATISTICS_get (sm->stat,
255 stats[sm->value].subsystem, stats[sm->value].name,
257 &get_done, &print_stat,
261 GNUNET_TESTBED_operation_done (sm->op);
264 if (NUM_DAEMONS == sm->daemon)
271 GNUNET_TESTBED_service_connect (NULL,
275 &statistics_connect_adapter,
276 &statistics_disconnect_adapter,
282 do_report (void *cls)
284 static int download_counter;
285 const char *type = cls;
286 struct GNUNET_TIME_Relative del;
288 struct StatMaster *sm;
291 GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time,
295 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
296 "Timeout during download for type `%s', shutting down with error\n",
302 del = GNUNET_TIME_absolute_get_duration (start_time);
303 if (del.rel_value_us == 0)
304 del.rel_value_us = 1;
306 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE)
307 * 1000000LL / del.rel_value_us);
308 fprintf (stderr, "Download speed of type `%s' was %s/s\n", type, fancy);
310 if (NUM_DAEMONS != ++download_counter)
311 return; /* more downloads to come */
312 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
313 "Finished all downloads, getting statistics\n");
314 sm = GNUNET_new (struct StatMaster);
316 GNUNET_TESTBED_service_connect (NULL,
320 &statistics_connect_adapter,
321 &statistics_disconnect_adapter,
327 do_downloads (void *cls, const struct GNUNET_FS_Uri *u2,
336 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
337 "Timeout during upload attempt, shutting down with error\n");
342 fn2 = GNUNET_strdup (fn);
343 uri2 = GNUNET_FS_uri_dup (u2);
344 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n",
345 (unsigned long long) FILESIZE);
346 start_time = GNUNET_TIME_absolute_get ();
347 if (NULL != strstr (progname, "dht"))
351 /* (semi) leach-download(s); not true leaches since
352 * these peers do participate in sharing, they just
353 * don't have to offer anything *initially*. */
354 for (i = 0; i < NUM_DAEMONS - 2; i++)
355 GNUNET_FS_TEST_download (daemons[i], TIMEOUT, anonymity,
356 0 == (i % 2) ? SEED1 : SEED2,
357 0 == (i % 2) ? uri1 : uri2, VERBOSE, &do_report,
359 /* mutual downloads of (primary) sharing peers */
360 GNUNET_FS_TEST_download (daemons[NUM_DAEMONS - 2], TIMEOUT, anonymity, SEED1,
361 uri1, VERBOSE, &do_report, "seeder 2");
362 GNUNET_FS_TEST_download (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity, SEED2,
363 uri2, VERBOSE, &do_report, "seeder 1");
368 do_publish2 (void *cls,
369 const struct GNUNET_FS_Uri *u1,
378 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
379 "Timeout during upload attempt, shutting down with error\n");
384 fn1 = GNUNET_strdup (fn);
385 uri1 = GNUNET_FS_uri_dup (u1);
386 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "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 - 2], TIMEOUT, anonymity,
398 do_index, FILESIZE, SEED2, VERBOSE, &do_downloads,
404 do_publish1 (void *cls,
405 struct GNUNET_TESTBED_Operation *op,
408 unsigned int *coco = cls;
412 GNUNET_TESTBED_operation_done (op);
416 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error trying to connect: %s\n", emsg);
420 if (0 != (--(*coco)))
421 return; /* more connections to be created */
422 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
423 (unsigned long long) FILESIZE);
424 if (NULL != strstr (progname, "index"))
425 do_index = GNUNET_YES;
427 do_index = GNUNET_NO;
428 if (NULL != strstr (progname, "dht"))
432 GNUNET_FS_TEST_publish (daemons[NUM_DAEMONS - 1], TIMEOUT, anonymity,
433 do_index, FILESIZE, SEED1, VERBOSE, &do_publish2,
439 do_connect (void *cls,
440 struct GNUNET_TESTBED_RunHandle *h,
441 unsigned int num_peers,
442 struct GNUNET_TESTBED_Peer **peers,
443 unsigned int links_succeeded,
444 unsigned int links_failed)
446 static unsigned int coco;
450 GNUNET_assert (NUM_DAEMONS == num_peers);
451 for (i = 0; i < num_peers; i++)
452 daemons[i] = peers[i];
453 for (i = 0; i < NUM_DAEMONS; i++)
454 for (j = i + 1; j < NUM_DAEMONS; j++)
457 GNUNET_TESTBED_overlay_connect (NULL,
467 main (int argc, char *argv[])
470 (void) GNUNET_TESTBED_test_run ("perf-gnunet-service-fs-p2p-respect",
471 "perf_gnunet_service_fs_p2p.conf",
475 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
479 /* end of perf_gnunet_service_fs_p2p_respect.c */