summaryrefslogtreecommitdiff
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.c142
1 files changed, 71 insertions, 71 deletions
diff --git a/src/fs/test_gnunet_service_fs_p2p.c b/src/fs/test_gnunet_service_fs_p2p.c
index 2050b0835..eba4e112d 100644
--- a/src/fs/test_gnunet_service_fs_p2p.c
+++ b/src/fs/test_gnunet_service_fs_p2p.c
@@ -11,12 +11,12 @@
11 WITHOUT ANY WARRANTY; without even the implied warranty of 11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details. 13 Affero General Public License for more details.
14 14
15 You should have received a copy of the GNU Affero General Public License 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/>. 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17 17
18 SPDX-License-Identifier: AGPL3.0-or-later 18 SPDX-License-Identifier: AGPL3.0-or-later
19*/ 19 */
20 20
21/** 21/**
22 * @file fs/test_gnunet_service_fs_p2p.c 22 * @file fs/test_gnunet_service_fs_p2p.c
@@ -36,7 +36,7 @@
36/** 36/**
37 * How long until we give up on the download? 37 * How long until we give up on the download?
38 */ 38 */
39#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 300) 39#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 300)
40 40
41#define NUM_DAEMONS 2 41#define NUM_DAEMONS 2
42 42
@@ -54,110 +54,110 @@ static struct GNUNET_TIME_Absolute start_time;
54 54
55 55
56static void 56static void
57do_stop (void *cls) 57do_stop(void *cls)
58{ 58{
59 char *fn = cls; 59 char *fn = cls;
60 struct GNUNET_TIME_Relative del; 60 struct GNUNET_TIME_Relative del;
61 char *fancy; 61 char *fancy;
62 62
63 GNUNET_SCHEDULER_shutdown (); 63 GNUNET_SCHEDULER_shutdown();
64 if (0 == 64 if (0 ==
65 GNUNET_TIME_absolute_get_remaining (GNUNET_TIME_absolute_add (start_time, 65 GNUNET_TIME_absolute_get_remaining(GNUNET_TIME_absolute_add(start_time,
66 TIMEOUT)).rel_value_us) 66 TIMEOUT)).rel_value_us)
67 { 67 {
68 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 68 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
69 "Timeout during download, shutting down with error\n"); 69 "Timeout during download, shutting down with error\n");
70 ok = 1; 70 ok = 1;
71 } 71 }
72 else 72 else
73 { 73 {
74 del = GNUNET_TIME_absolute_get_duration (start_time); 74 del = GNUNET_TIME_absolute_get_duration(start_time);
75 if (0 == del.rel_value_us) 75 if (0 == del.rel_value_us)
76 del.rel_value_us = 1; 76 del.rel_value_us = 1;
77 fancy = 77 fancy =
78 GNUNET_STRINGS_byte_size_fancy (((unsigned long long) FILESIZE) * 78 GNUNET_STRINGS_byte_size_fancy(((unsigned long long)FILESIZE) *
79 1000000LL / del.rel_value_us); 79 1000000LL / del.rel_value_us);
80 fprintf (stdout, 80 fprintf(stdout,
81 "Download speed was %s/s\n", 81 "Download speed was %s/s\n",
82 fancy); 82 fancy);
83 GNUNET_free (fancy); 83 GNUNET_free(fancy);
84 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 84 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
85 "Finished download, shutting down\n"); 85 "Finished download, shutting down\n");
86 } 86 }
87 if (NULL != fn) 87 if (NULL != fn)
88 { 88 {
89 GNUNET_DISK_directory_remove (fn); 89 GNUNET_DISK_directory_remove(fn);
90 GNUNET_free (fn); 90 GNUNET_free(fn);
91 } 91 }
92} 92}
93 93
94 94
95static void 95static void
96do_download (void *cls, const struct GNUNET_FS_Uri *uri, 96do_download(void *cls, const struct GNUNET_FS_Uri *uri,
97 const char *fn) 97 const char *fn)
98{ 98{
99 if (NULL == uri) 99 if (NULL == uri)
100 { 100 {
101 GNUNET_SCHEDULER_shutdown (); 101 GNUNET_SCHEDULER_shutdown();
102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 102 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
103 "Timeout during upload attempt, shutting down with error\n"); 103 "Timeout during upload attempt, shutting down with error\n");
104 ok = 1; 104 ok = 1;
105 return; 105 return;
106 } 106 }
107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n", 107 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Downloading %llu bytes\n",
108 (unsigned long long) FILESIZE); 108 (unsigned long long)FILESIZE);
109 start_time = GNUNET_TIME_absolute_get (); 109 start_time = GNUNET_TIME_absolute_get();
110 GNUNET_FS_TEST_download (daemons[0], TIMEOUT, 110 GNUNET_FS_TEST_download(daemons[0], TIMEOUT,
111 anonymity_level, SEED, uri, 111 anonymity_level, SEED, uri,
112 VERBOSE, &do_stop, 112 VERBOSE, &do_stop,
113 (NULL == fn) 113 (NULL == fn)
114 ? NULL 114 ? NULL
115 : GNUNET_strdup (fn)); 115 : GNUNET_strdup(fn));
116} 116}
117 117
118 118
119static void 119static void
120do_publish (void *cls, 120do_publish(void *cls,
121 struct GNUNET_TESTBED_RunHandle *h, 121 struct GNUNET_TESTBED_RunHandle *h,
122 unsigned int num_peers, 122 unsigned int num_peers,
123 struct GNUNET_TESTBED_Peer **peers, 123 struct GNUNET_TESTBED_Peer **peers,
124 unsigned int links_succeeded, 124 unsigned int links_succeeded,
125 unsigned int links_failed) 125 unsigned int links_failed)
126{ 126{
127 unsigned int i; 127 unsigned int i;
128 128
129 if (NULL != strstr (progname, "cadet")) 129 if (NULL != strstr(progname, "cadet"))
130 anonymity_level = 0; 130 anonymity_level = 0;
131 else 131 else
132 anonymity_level = 1; 132 anonymity_level = 1;
133 GNUNET_assert (NUM_DAEMONS == num_peers); 133 GNUNET_assert(NUM_DAEMONS == num_peers);
134 for (i=0;i<num_peers;i++) 134 for (i = 0; i < num_peers; i++)
135 daemons[i] = peers[i]; 135 daemons[i] = peers[i];
136 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n", 136 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Publishing %llu bytes\n",
137 (unsigned long long) FILESIZE); 137 (unsigned long long)FILESIZE);
138 GNUNET_FS_TEST_publish (daemons[1], TIMEOUT, 138 GNUNET_FS_TEST_publish(daemons[1], TIMEOUT,
139 anonymity_level, GNUNET_NO, 139 anonymity_level, GNUNET_NO,
140 FILESIZE, SEED, 140 FILESIZE, SEED,
141 VERBOSE, &do_download, NULL); 141 VERBOSE, &do_download, NULL);
142} 142}
143 143
144 144
145int 145int
146main (int argc, char *argv[]) 146main(int argc, char *argv[])
147{ 147{
148 const char *config; 148 const char *config;
149 149
150 progname = argv[0]; 150 progname = argv[0];
151 if (NULL != strstr (progname, "cadet")) 151 if (NULL != strstr(progname, "cadet"))
152 config = "test_gnunet_service_fs_p2p_cadet.conf"; 152 config = "test_gnunet_service_fs_p2p_cadet.conf";
153 else 153 else
154 config = "fs_test_lib_data.conf"; 154 config = "fs_test_lib_data.conf";
155 (void) GNUNET_TESTBED_test_run ("test-gnunet-service-fs-p2p", 155 (void)GNUNET_TESTBED_test_run("test-gnunet-service-fs-p2p",
156 config, 156 config,
157 NUM_DAEMONS, 157 NUM_DAEMONS,
158 0, NULL, NULL, 158 0, NULL, NULL,
159 &do_publish, NULL); 159 &do_publish, NULL);
160 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-lib/"); 160 GNUNET_DISK_directory_remove("/tmp/gnunet-test-fs-lib/");
161 return ok; 161 return ok;
162} 162}
163 163