aboutsummaryrefslogtreecommitdiff
path: root/src/fs/test_fs_list_indexed.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/test_fs_list_indexed.c')
-rw-r--r--src/fs/test_fs_list_indexed.c276
1 files changed, 141 insertions, 135 deletions
diff --git a/src/fs/test_fs_list_indexed.c b/src/fs/test_fs_list_indexed.c
index a4e7eb53f..b5e5982d0 100644
--- a/src/fs/test_fs_list_indexed.c
+++ b/src/fs/test_fs_list_indexed.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_fs_list_indexed.c 22 * @file fs/test_fs_list_indexed.c
@@ -40,12 +40,12 @@
40/** 40/**
41 * How long until we give up on transmitting the message? 41 * How long until we give up on transmitting the message?
42 */ 42 */
43#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60) 43#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 60)
44 44
45/** 45/**
46 * How long should our test-content live? 46 * How long should our test-content live?
47 */ 47 */
48#define LIFETIME GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 15) 48#define LIFETIME GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MINUTES, 15)
49 49
50 50
51static struct GNUNET_TIME_Absolute start; 51static struct GNUNET_TIME_Absolute start;
@@ -62,115 +62,121 @@ static int err;
62 62
63 63
64static void 64static void
65abort_publish_task (void *cls) 65abort_publish_task(void *cls)
66{ 66{
67 GNUNET_FS_publish_stop (publish); 67 GNUNET_FS_publish_stop(publish);
68 publish = NULL; 68 publish = NULL;
69 GNUNET_DISK_directory_remove (fn1); 69 GNUNET_DISK_directory_remove(fn1);
70 GNUNET_free (fn1); 70 GNUNET_free(fn1);
71 fn1 = NULL; 71 fn1 = NULL;
72 GNUNET_DISK_directory_remove (fn2); 72 GNUNET_DISK_directory_remove(fn2);
73 GNUNET_free (fn2); 73 GNUNET_free(fn2);
74 fn2 = NULL; 74 fn2 = NULL;
75} 75}
76 76
77 77
78static void 78static void
79list_indexed_task (void *cls) 79list_indexed_task(void *cls)
80{ 80{
81 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); 81 GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL);
82} 82}
83 83
84 84
85static void * 85static void *
86progress_cb (void *cls, const struct GNUNET_FS_ProgressInfo *event) 86progress_cb(void *cls, const struct GNUNET_FS_ProgressInfo *event)
87{ 87{
88 void *ret; 88 void *ret;
89 89
90 ret = NULL; 90 ret = NULL;
91 switch (event->status) 91 switch (event->status)
92 { 92 {
93 case GNUNET_FS_STATUS_PUBLISH_COMPLETED: 93 case GNUNET_FS_STATUS_PUBLISH_COMPLETED:
94 ret = event->value.publish.cctx; 94 ret = event->value.publish.cctx;
95 printf ("Publish complete, %llu kbps.\n", 95 printf("Publish complete, %llu kbps.\n",
96 (unsigned long long) (FILESIZE * 1000000LL / 96 (unsigned long long)(FILESIZE * 1000000LL /
97 (1 + 97 (1 +
98 GNUNET_TIME_absolute_get_duration 98 GNUNET_TIME_absolute_get_duration
99 (start).rel_value_us) / 1024)); 99 (start).rel_value_us) / 1024));
100 if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx)) 100 if (0 == strcmp("list_indexed-context-dir", event->value.publish.cctx))
101 GNUNET_SCHEDULER_add_now (&list_indexed_task, NULL); 101 GNUNET_SCHEDULER_add_now(&list_indexed_task, NULL);
102 102
103 break; 103 break;
104 case GNUNET_FS_STATUS_PUBLISH_PROGRESS: 104
105 ret = event->value.publish.cctx; 105 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
106 GNUNET_assert (publish == event->value.publish.pc); 106 ret = event->value.publish.cctx;
107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 107 GNUNET_assert(publish == event->value.publish.pc);
108 "Publish is progressing (%llu/%llu at level %u off %llu)...\n", 108 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
109 (unsigned long long) event->value.publish.completed, 109 "Publish is progressing (%llu/%llu at level %u off %llu)...\n",
110 (unsigned long long) event->value.publish.size, 110 (unsigned long long)event->value.publish.completed,
111 event->value.publish.specifics.progress.depth, 111 (unsigned long long)event->value.publish.size,
112 (unsigned long long) event->value.publish.specifics. 112 event->value.publish.specifics.progress.depth,
113 progress.offset); 113 (unsigned long long)event->value.publish.specifics.
114 break; 114 progress.offset);
115 case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY: 115 break;
116 ret = event->value.publish.cctx; 116
117 break; 117 case GNUNET_FS_STATUS_PUBLISH_PROGRESS_DIRECTORY:
118 case GNUNET_FS_STATUS_PUBLISH_ERROR: 118 ret = event->value.publish.cctx;
119 ret = event->value.publish.cctx; 119 break;
120 fprintf (stderr, "Error publishing file: %s\n", 120
121 event->value.publish.specifics.error.message); 121 case GNUNET_FS_STATUS_PUBLISH_ERROR:
122 err = 1; 122 ret = event->value.publish.cctx;
123 if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx)) 123 fprintf(stderr, "Error publishing file: %s\n",
124 GNUNET_SCHEDULER_add_now (&abort_publish_task, NULL); 124 event->value.publish.specifics.error.message);
125 break; 125 err = 1;
126 case GNUNET_FS_STATUS_PUBLISH_START: 126 if (0 == strcmp("list_indexed-context-dir", event->value.publish.cctx))
127 ret = event->value.publish.cctx; 127 GNUNET_SCHEDULER_add_now(&abort_publish_task, NULL);
128 if (0 == strcmp ("list_indexed-context1", event->value.publish.cctx)) 128 break;
129 { 129
130 GNUNET_assert (0 == 130 case GNUNET_FS_STATUS_PUBLISH_START:
131 strcmp ("list_indexed-context-dir", 131 ret = event->value.publish.cctx;
132 event->value.publish.pctx)); 132 if (0 == strcmp("list_indexed-context1", event->value.publish.cctx))
133 GNUNET_assert (FILESIZE == event->value.publish.size); 133 {
134 GNUNET_assert (0 == event->value.publish.completed); 134 GNUNET_assert(0 ==
135 GNUNET_assert (1 == event->value.publish.anonymity); 135 strcmp("list_indexed-context-dir",
136 } 136 event->value.publish.pctx));
137 else if (0 == strcmp ("list_indexed-context2", event->value.publish.cctx)) 137 GNUNET_assert(FILESIZE == event->value.publish.size);
138 { 138 GNUNET_assert(0 == event->value.publish.completed);
139 GNUNET_assert (0 == 139 GNUNET_assert(1 == event->value.publish.anonymity);
140 strcmp ("list_indexed-context-dir", 140 }
141 event->value.publish.pctx)); 141 else if (0 == strcmp("list_indexed-context2", event->value.publish.cctx))
142 GNUNET_assert (FILESIZE == event->value.publish.size); 142 {
143 GNUNET_assert (0 == event->value.publish.completed); 143 GNUNET_assert(0 ==
144 GNUNET_assert (2 == event->value.publish.anonymity); 144 strcmp("list_indexed-context-dir",
145 } 145 event->value.publish.pctx));
146 else if (0 == 146 GNUNET_assert(FILESIZE == event->value.publish.size);
147 strcmp ("list_indexed-context-dir", event->value.publish.cctx)) 147 GNUNET_assert(0 == event->value.publish.completed);
148 { 148 GNUNET_assert(2 == event->value.publish.anonymity);
149 GNUNET_assert (0 == event->value.publish.completed); 149 }
150 GNUNET_assert (3 == event->value.publish.anonymity); 150 else if (0 ==
151 } 151 strcmp("list_indexed-context-dir", event->value.publish.cctx))
152 else 152 {
153 GNUNET_assert (0); 153 GNUNET_assert(0 == event->value.publish.completed);
154 break; 154 GNUNET_assert(3 == event->value.publish.anonymity);
155 case GNUNET_FS_STATUS_PUBLISH_STOPPED: 155 }
156 if (0 == strcmp ("list_indexed-context-dir", event->value.publish.cctx)) 156 else
157 { 157 GNUNET_assert(0);
158 GNUNET_assert (publish == event->value.publish.pc); 158 break;
159 publish = NULL; 159
160 case GNUNET_FS_STATUS_PUBLISH_STOPPED:
161 if (0 == strcmp("list_indexed-context-dir", event->value.publish.cctx))
162 {
163 GNUNET_assert(publish == event->value.publish.pc);
164 publish = NULL;
165 }
166 break;
167
168 default:
169 printf("Unexpected event: %d\n", event->status);
170 break;
160 } 171 }
161 break;
162 default:
163 printf ("Unexpected event: %d\n", event->status);
164 break;
165 }
166 return ret; 172 return ret;
167} 173}
168 174
169 175
170static void 176static void
171run (void *cls, 177run(void *cls,
172 const struct GNUNET_CONFIGURATION_Handle *cfg, 178 const struct GNUNET_CONFIGURATION_Handle *cfg,
173 struct GNUNET_TESTING_Peer *peer) 179 struct GNUNET_TESTING_Peer *peer)
174{ 180{
175 const char *keywords[] = { 181 const char *keywords[] = {
176 "down_foo", 182 "down_foo",
@@ -185,70 +191,70 @@ run (void *cls,
185 size_t i; 191 size_t i;
186 struct GNUNET_FS_BlockOptions bo; 192 struct GNUNET_FS_BlockOptions bo;
187 193
188 fs = GNUNET_FS_start (cfg, "test-fs-list_indexed", &progress_cb, NULL, 194 fs = GNUNET_FS_start(cfg, "test-fs-list_indexed", &progress_cb, NULL,
189 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END); 195 GNUNET_FS_FLAGS_NONE, GNUNET_FS_OPTIONS_END);
190 GNUNET_assert (NULL != fs); 196 GNUNET_assert(NULL != fs);
191 fn1 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst"); 197 fn1 = GNUNET_DISK_mktemp("gnunet-list_indexed-test-dst");
192 buf = GNUNET_malloc (FILESIZE); 198 buf = GNUNET_malloc(FILESIZE);
193 for (i = 0; i < FILESIZE; i++) 199 for (i = 0; i < FILESIZE; i++)
194 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 200 buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256);
195 GNUNET_assert (FILESIZE == 201 GNUNET_assert(FILESIZE ==
196 GNUNET_DISK_fn_write (fn1, buf, FILESIZE, 202 GNUNET_DISK_fn_write(fn1, buf, FILESIZE,
197 GNUNET_DISK_PERM_USER_READ | 203 GNUNET_DISK_PERM_USER_READ |
198 GNUNET_DISK_PERM_USER_WRITE)); 204 GNUNET_DISK_PERM_USER_WRITE));
199 GNUNET_free (buf); 205 GNUNET_free(buf);
200 206
201 fn2 = GNUNET_DISK_mktemp ("gnunet-list_indexed-test-dst"); 207 fn2 = GNUNET_DISK_mktemp("gnunet-list_indexed-test-dst");
202 buf = GNUNET_malloc (FILESIZE); 208 buf = GNUNET_malloc(FILESIZE);
203 for (i = 0; i < FILESIZE; i++) 209 for (i = 0; i < FILESIZE; i++)
204 buf[i] = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 256); 210 buf[i] = GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, 256);
205 GNUNET_assert (FILESIZE == 211 GNUNET_assert(FILESIZE ==
206 GNUNET_DISK_fn_write (fn2, buf, FILESIZE, 212 GNUNET_DISK_fn_write(fn2, buf, FILESIZE,
207 GNUNET_DISK_PERM_USER_READ | 213 GNUNET_DISK_PERM_USER_READ |
208 GNUNET_DISK_PERM_USER_WRITE)); 214 GNUNET_DISK_PERM_USER_WRITE));
209 GNUNET_free (buf); 215 GNUNET_free(buf);
210 216
211 meta = GNUNET_CONTAINER_meta_data_create (); 217 meta = GNUNET_CONTAINER_meta_data_create();
212 kuri = GNUNET_FS_uri_ksk_create_from_args (2, keywords); 218 kuri = GNUNET_FS_uri_ksk_create_from_args(2, keywords);
213 bo.content_priority = 42; 219 bo.content_priority = 42;
214 bo.anonymity_level = 1; 220 bo.anonymity_level = 1;
215 bo.replication_level = 0; 221 bo.replication_level = 0;
216 bo.expiration_time = GNUNET_TIME_relative_to_absolute (LIFETIME); 222 bo.expiration_time = GNUNET_TIME_relative_to_absolute(LIFETIME);
217 fi1 = 223 fi1 =
218 GNUNET_FS_file_information_create_from_file (fs, "list_indexed-context1", 224 GNUNET_FS_file_information_create_from_file(fs, "list_indexed-context1",
219 fn1, kuri, meta, GNUNET_YES, 225 fn1, kuri, meta, GNUNET_YES,
220 &bo); 226 &bo);
221 GNUNET_assert (NULL != fi1); 227 GNUNET_assert(NULL != fi1);
222 bo.anonymity_level = 2; 228 bo.anonymity_level = 2;
223 fi2 = 229 fi2 =
224 GNUNET_FS_file_information_create_from_file (fs, "list_indexed-context2", 230 GNUNET_FS_file_information_create_from_file(fs, "list_indexed-context2",
225 fn2, kuri, meta, GNUNET_YES, 231 fn2, kuri, meta, GNUNET_YES,
226 &bo); 232 &bo);
227 GNUNET_assert (NULL != fi2); 233 GNUNET_assert(NULL != fi2);
228 bo.anonymity_level = 3; 234 bo.anonymity_level = 3;
229 fidir = 235 fidir =
230 GNUNET_FS_file_information_create_empty_directory (fs, 236 GNUNET_FS_file_information_create_empty_directory(fs,
231 "list_indexed-context-dir", 237 "list_indexed-context-dir",
232 kuri, meta, &bo, NULL); 238 kuri, meta, &bo, NULL);
233 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi1)); 239 GNUNET_assert(GNUNET_OK == GNUNET_FS_file_information_add(fidir, fi1));
234 GNUNET_assert (GNUNET_OK == GNUNET_FS_file_information_add (fidir, fi2)); 240 GNUNET_assert(GNUNET_OK == GNUNET_FS_file_information_add(fidir, fi2));
235 GNUNET_FS_uri_destroy (kuri); 241 GNUNET_FS_uri_destroy(kuri);
236 GNUNET_CONTAINER_meta_data_destroy (meta); 242 GNUNET_CONTAINER_meta_data_destroy(meta);
237 GNUNET_assert (NULL != fidir); 243 GNUNET_assert(NULL != fidir);
238 start = GNUNET_TIME_absolute_get (); 244 start = GNUNET_TIME_absolute_get();
239 publish = 245 publish =
240 GNUNET_FS_publish_start (fs, fidir, NULL, NULL, NULL, 246 GNUNET_FS_publish_start(fs, fidir, NULL, NULL, NULL,
241 GNUNET_FS_PUBLISH_OPTION_NONE); 247 GNUNET_FS_PUBLISH_OPTION_NONE);
242 GNUNET_assert (publish != NULL); 248 GNUNET_assert(publish != NULL);
243} 249}
244 250
245 251
246int 252int
247main (int argc, char *argv[]) 253main(int argc, char *argv[])
248{ 254{
249 if (0 != GNUNET_TESTING_peer_run ("test-fs-list-indexed", 255 if (0 != GNUNET_TESTING_peer_run("test-fs-list-indexed",
250 "test_fs_list_indexed_data.conf", 256 "test_fs_list_indexed_data.conf",
251 &run, NULL)) 257 &run, NULL))
252 return 1; 258 return 1;
253 return 0; 259 return 0;
254} 260}