2 This file is part of GNUnet.
3 (C) 2010, 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/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;
57 do_stop (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
59 struct GNUNET_TIME_Relative del;
62 GNUNET_SCHEDULER_shutdown ();
63 if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_TIMEOUT))
65 del = GNUNET_TIME_absolute_get_duration (start_time);
66 if (del.rel_value == 0)
69 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) *
70 1000LL / del.rel_value);
71 FPRINTF (stdout, "Download speed was %s/s\n", fancy);
73 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished download, shutting down\n",
74 (unsigned long long) FILESIZE);
78 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
79 "Timeout during download, shutting down with error\n");
86 do_download (void *cls, const struct GNUNET_FS_Uri *uri)
90 GNUNET_SCHEDULER_shutdown ();
91 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
92 "Timeout during upload attempt, shutting down with error\n");
96 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n",
97 (unsigned long long) FILESIZE);
98 start_time = GNUNET_TIME_absolute_get ();
99 GNUNET_FS_TEST_download (daemons[0], TIMEOUT,
100 anonymity_level, SEED, uri,
107 do_publish (void *cls,
108 unsigned int num_peers,
109 struct GNUNET_TESTBED_Peer **peers)
113 if (NULL != strstr (progname, "stream"))
117 GNUNET_assert (NUM_DAEMONS == num_peers);
118 for (i=0;i<num_peers;i++)
119 daemons[i] = peers[i];
120 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
121 (unsigned long long) FILESIZE);
122 GNUNET_FS_TEST_publish (daemons[1], TIMEOUT,
123 anonymity_level, GNUNET_NO,
125 VERBOSE, &do_download, NULL);
130 main (int argc, char *argv[])
135 if (NULL != strstr (progname, "stream"))
136 config = "test_gnunet_service_fs_p2p_stream.conf";
138 config = "fs_test_lib_data.conf";
139 (void) GNUNET_TESTBED_test_run ("test-gnunet-service-fs-p2p",
144 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
148 /* end of test_gnunet_service_fs_p2p.c */