2 This file is part of GNUnet.
3 Copyright (C) 2010, 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.
17 * @file fs/test_gnunet_service_fs_p2p.c
18 * @brief test P2P routing using simple publish + download operation
19 * @author Christian Grothoff
22 #include "fs_test_lib.h"
24 #define VERBOSE GNUNET_NO
27 * File-size we use for testing.
29 #define FILESIZE (1024 * 1024 * 1)
32 * How long until we give up on the download?
34 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
40 static const char *progname;
42 static unsigned int anonymity_level;
44 static struct GNUNET_TESTBED_Peer *daemons[NUM_DAEMONS];
48 static struct GNUNET_TIME_Absolute start_time;
55 struct GNUNET_TIME_Relative del;
58 GNUNET_SCHEDULER_shutdown ();
60 GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time,
61 TIMEOUT)).rel_value_us)
63 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
64 "Timeout during download, shutting down with error\n");
69 del = GNUNET_TIME_absolute_get_duration (start_time);
70 if (0 == del.rel_value_us)
73 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
74 1000000LL / del.rel_value_us);
76 "Download speed was %s/s\n",
79 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
80 "Finished download, shutting down\n");
84 GNUNET_DISK_directory_remove (fn);
91 do_download (void *cls, const struct GNUNET_FS_Uri *uri,
96 GNUNET_SCHEDULER_shutdown ();
97 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
98 "Timeout during upload attempt, shutting down with error\n");
102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n",
103 (unsigned long long) FILESIZE);
104 start_time = GNUNET_TIME_absolute_get ();
105 GNUNET_FS_TEST_download (daemons[0], TIMEOUT,
106 anonymity_level, SEED, uri,
110 : GNUNET_strdup (fn));
115 do_publish (void *cls,
116 struct GNUNET_TESTBED_RunHandle *h,
117 unsigned int num_peers,
118 struct GNUNET_TESTBED_Peer **peers,
119 unsigned int links_succeeded,
120 unsigned int links_failed)
124 if (NULL != strstr (progname, "cadet"))
128 GNUNET_assert (NUM_DAEMONS == num_peers);
129 for (i=0;i<num_peers;i++)
130 daemons[i] = peers[i];
131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
132 (unsigned long long) FILESIZE);
133 GNUNET_FS_TEST_publish (daemons[1], TIMEOUT,
134 anonymity_level, GNUNET_NO,
136 VERBOSE, &do_download, NULL);
141 main (int argc, char *argv[])
146 if (NULL != strstr (progname, "cadet"))
147 config = "test_gnunet_service_fs_p2p_cadet.conf";
149 config = "fs_test_lib_data.conf";
150 (void) GNUNET_TESTBED_test_run ("test-gnunet-service-fs-p2p",
155 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
159 /* end of test_gnunet_service_fs_p2p.c */