aboutsummaryrefslogtreecommitdiff
path: root/src/fs/test_gnunet_service_fs_p2p.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/test_gnunet_service_fs_p2p.c')
-rw-r--r--src/fs/test_gnunet_service_fs_p2p.c166
1 files changed, 0 insertions, 166 deletions
diff --git a/src/fs/test_gnunet_service_fs_p2p.c b/src/fs/test_gnunet_service_fs_p2p.c
deleted file mode 100644
index bedcb7173..000000000
--- a/src/fs/test_gnunet_service_fs_p2p.c
+++ /dev/null
@@ -1,166 +0,0 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2010, 2012 GNUnet e.V.
4
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.
9
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.
14
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/>.
17
18 SPDX-License-Identifier: AGPL3.0-or-later
19 */
20
21/**
22 * @file fs/test_gnunet_service_fs_p2p.c
23 * @brief test P2P routing using simple publish + download operation
24 * @author Christian Grothoff
25 */
26#include "platform.h"
27#include "fs_test_lib.h"
28
29#define VERBOSE GNUNET_NO
30
31/**
32 * File-size we use for testing.
33 */
34#define FILESIZE (1024 * 1024 * 1)
35
36/**
37 * How long until we give up on the download?
38 */
39#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300)
40
41#define NUM_DAEMONS 2
42
43#define SEED 42
44
45static const char *progname;
46
47static unsigned int anonymity_level;
48
49static struct GNUNET_TESTBED_Peer *daemons[NUM_DAEMONS];
50
51static int ok;
52
53static struct GNUNET_TIME_Absolute start_time;
54
55
56static void
57do_stop (void *cls)
58{
59 char *fn = cls;
60 struct GNUNET_TIME_Relative del;
61 char *fancy;
62
63 GNUNET_SCHEDULER_shutdown ();
64 if (0 ==
65 GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time,
66 TIMEOUT)).
67 rel_value_us)
68 {
69 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
70 "Timeout during download, shutting down with error\n");
71 ok = 1;
72 }
73 else
74 {
75 del = GNUNET_TIME_absolute_get_duration (start_time);
76 if (0 == del.rel_value_us)
77 del.rel_value_us = 1;
78 fancy =
79 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE)
80 * 1000000LL / del.rel_value_us);
81 fprintf (stdout,
82 "Download speed was %s/s\n",
83 fancy);
84 GNUNET_free (fancy);
85 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
86 "Finished download, shutting down\n");
87 }
88 if (NULL != fn)
89 {
90 GNUNET_DISK_directory_remove (fn);
91 GNUNET_free (fn);
92 }
93}
94
95
96static void
97do_download (void *cls, const struct GNUNET_FS_Uri *uri,
98 const char *fn)
99{
100 if (NULL == uri)
101 {
102 GNUNET_SCHEDULER_shutdown ();
103 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
104 "Timeout during upload attempt, shutting down with error\n");
105 ok = 1;
106 return;
107 }
108 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n",
109 (unsigned long long) FILESIZE);
110 start_time = GNUNET_TIME_absolute_get ();
111 GNUNET_FS_TEST_download (daemons[0], TIMEOUT,
112 anonymity_level, SEED, uri,
113 VERBOSE, &do_stop,
114 (NULL == fn)
115 ? NULL
116 : GNUNET_strdup (fn));
117}
118
119
120static void
121do_publish (void *cls,
122 struct GNUNET_TESTBED_RunHandle *h,
123 unsigned int num_peers,
124 struct GNUNET_TESTBED_Peer **peers,
125 unsigned int links_succeeded,
126 unsigned int links_failed)
127{
128 unsigned int i;
129
130 if (NULL != strstr (progname, "cadet"))
131 anonymity_level = 0;
132 else
133 anonymity_level = 1;
134 GNUNET_assert (NUM_DAEMONS == num_peers);
135 for (i = 0; i < num_peers; i++)
136 daemons[i] = peers[i];
137 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
138 (unsigned long long) FILESIZE);
139 GNUNET_FS_TEST_publish (daemons[1], TIMEOUT,
140 anonymity_level, GNUNET_NO,
141 FILESIZE, SEED,
142 VERBOSE, &do_download, NULL);
143}
144
145
146int
147main (int argc, char *argv[])
148{
149 const char *config;
150
151 progname = argv[0];
152 if (NULL != strstr (progname, "cadet"))
153 config = "test_gnunet_service_fs_p2p_cadet.conf";
154 else
155 config = "fs_test_lib_data.conf";
156 (void) GNUNET_TESTBED_test_run ("test-gnunet-service-fs-p2p",
157 config,
158 NUM_DAEMONS,
159 0, NULL, NULL,
160 &do_publish, NULL);
161 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/");
162 return ok;
163}
164
165
166/* end of test_gnunet_service_fs_p2p.c */