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
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
22 * @file fs/test_gnunet_service_fs_p2p.c
23 * @brief test P2P routing using simple publish + download operation
24 * @author Christian Grothoff
27 #include "fs_test_lib.h"
29 #define VERBOSE GNUNET_NO
32 * File-size we use for testing.
34 #define FILESIZE (1024 * 1024 * 1)
37 * How long until we give up on the download?
39 #define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
45 static const char *progname;
47 static unsigned int anonymity_level;
49 static struct GNUNET_TESTBED_Peer *daemons[NUM_DAEMONS];
53 static struct GNUNET_TIME_Absolute start_time;
60 struct GNUNET_TIME_Relative del;
63 GNUNET_SCHEDULER_shutdown ();
65 GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time,
66 TIMEOUT)).rel_value_us)
68 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
69 "Timeout during download, shutting down with error\n");
74 del = GNUNET_TIME_absolute_get_duration (start_time);
75 if (0 == del.rel_value_us)
78 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
79 1000000LL / del.rel_value_us);
81 "Download speed was %s/s\n",
84 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
85 "Finished download, shutting down\n");
89 GNUNET_DISK_directory_remove (fn);
96 do_download (void *cls, const struct GNUNET_FS_Uri *uri,
101 GNUNET_SCHEDULER_shutdown ();
102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
103 "Timeout during upload attempt, shutting down with error\n");
107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n",
108 (unsigned long long) FILESIZE);
109 start_time = GNUNET_TIME_absolute_get ();
110 GNUNET_FS_TEST_download (daemons[0], TIMEOUT,
111 anonymity_level, SEED, uri,
115 : GNUNET_strdup (fn));
120 do_publish (void *cls,
121 struct GNUNET_TESTBED_RunHandle *h,
122 unsigned int num_peers,
123 struct GNUNET_TESTBED_Peer **peers,
124 unsigned int links_succeeded,
125 unsigned int links_failed)
129 if (NULL != strstr (progname, "cadet"))
133 GNUNET_assert (NUM_DAEMONS == num_peers);
134 for (i=0;i<num_peers;i++)
135 daemons[i] = peers[i];
136 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
137 (unsigned long long) FILESIZE);
138 GNUNET_FS_TEST_publish (daemons[1], TIMEOUT,
139 anonymity_level, GNUNET_NO,
141 VERBOSE, &do_download, NULL);
146 main (int argc, char *argv[])
151 if (NULL != strstr (progname, "cadet"))
152 config = "test_gnunet_service_fs_p2p_cadet.conf";
154 config = "fs_test_lib_data.conf";
155 (void) GNUNET_TESTBED_test_run ("test-gnunet-service-fs-p2p",
160 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
164 /* end of test_gnunet_service_fs_p2p.c */