aboutsummaryrefslogtreecommitdiff
path: root/src/fs/test_fs_download_recursive.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/test_fs_download_recursive.c')
-rw-r--r--src/fs/test_fs_download_recursive.c311
1 files changed, 152 insertions, 159 deletions
diff --git a/src/fs/test_fs_download_recursive.c b/src/fs/test_fs_download_recursive.c
index d24a38dbc..c3e0ea440 100644
--- a/src/fs/test_fs_download_recursive.c
+++ b/src/fs/test_fs_download_recursive.c
@@ -46,10 +46,9 @@ makeName (unsigned int i)
46{ 46{
47 char *fn; 47 char *fn;
48 48
49 fn = 49 fn = GNUNET_malloc (strlen
50 GNUNET_malloc (strlen 50 ("/tmp/gnunet-fsui-recursive_download_test/FSUITEST") +
51 ("/tmp/gnunet-fsui-recursive_download_test/FSUITEST") + 51 15);
52 15);
53 GNUNET_snprintf (fn, 52 GNUNET_snprintf (fn,
54 strlen 53 strlen
55 ("/tmp/gnunet-fsui-recursive_download_test/FSUITEST") + 15, 54 ("/tmp/gnunet-fsui-recursive_download_test/FSUITEST") + 15,
@@ -68,56 +67,56 @@ makeHierarchyHelper (const char *current, const char *tree, int index,
68 fi = 0; 67 fi = 0;
69 done = 0; 68 done = 0;
70 while (!done && tree[index] != '\0') 69 while (!done && tree[index] != '\0')
70 {
71 s = GNUNET_malloc (strlen (current) + strlen (DIR_SEPARATOR_STR) + 14);
72 GNUNET_snprintf (s, strlen (current) + strlen (DIR_SEPARATOR_STR) + 14,
73 "%s%s%u", current, DIR_SEPARATOR_STR, fi);
74 switch (tree[index++])
71 { 75 {
72 s = GNUNET_malloc (strlen (current) + strlen (DIR_SEPARATOR_STR) + 14); 76 case 'd':
73 GNUNET_snprintf (s, strlen (current) + strlen (DIR_SEPARATOR_STR) + 14, 77 if (check)
74 "%s%s%u", current, DIR_SEPARATOR_STR, fi); 78 {
75 switch (tree[index++]) 79 if (GNUNET_disk_directory_test (NULL, s) == GNUNET_NO)
76 { 80 {
77 case 'd': 81 index = -1;
78 if (check)
79 {
80 if (GNUNET_disk_directory_test (NULL, s) == GNUNET_NO)
81 {
82 index = -1;
83 done = 1;
84 }
85 }
86 else
87 {
88 GNUNET_disk_directory_create (NULL, s);
89 }
90 if (!done)
91 index = makeHierarchyHelper (s, tree, index, check);
92 break;
93 case 'f':
94 if (check)
95 {
96 /* TODO: compare file contents */
97 if (GNUNET_disk_directory_test (NULL, s) != GNUNET_NO)
98 {
99 index = -1;
100 done = 1;
101 }
102 }
103 else
104 {
105 buf = GNUNET_malloc (FILESIZE);
106 for (i = 0; i < FILESIZE; i++)
107 buf[i] = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 256);
108 GNUNET_disk_file_write (ectx, s, buf, FILESIZE, "600");
109 GNUNET_free (buf);
110 }
111 break;
112 case '.':
113 done = 1; 82 done = 1;
114 break;
115 default:
116 break;
117 } 83 }
118 GNUNET_free (s); 84 }
119 fi++; 85 else
86 {
87 GNUNET_disk_directory_create (NULL, s);
88 }
89 if (!done)
90 index = makeHierarchyHelper (s, tree, index, check);
91 break;
92 case 'f':
93 if (check)
94 {
95 /* TODO: compare file contents */
96 if (GNUNET_disk_directory_test (NULL, s) != GNUNET_NO)
97 {
98 index = -1;
99 done = 1;
100 }
101 }
102 else
103 {
104 buf = GNUNET_malloc (FILESIZE);
105 for (i = 0; i < FILESIZE; i++)
106 buf[i] = GNUNET_random_u32 (GNUNET_RANDOM_QUALITY_WEAK, 256);
107 GNUNET_disk_file_write (ectx, s, buf, FILESIZE, "600");
108 GNUNET_free (buf);
109 }
110 break;
111 case '.':
112 done = 1;
113 break;
114 default:
115 break;
120 } 116 }
117 GNUNET_free (s);
118 fi++;
119 }
121 return index; 120 return index;
122} 121}
123 122
@@ -139,10 +138,10 @@ checkHierarchy (unsigned int i, const char *tree)
139 138
140 fn = makeName (i); 139 fn = makeName (i);
141 if (GNUNET_disk_directory_test (NULL, fn) != GNUNET_YES) 140 if (GNUNET_disk_directory_test (NULL, fn) != GNUNET_YES)
142 { 141 {
143 GNUNET_free (fn); 142 GNUNET_free (fn);
144 return GNUNET_SYSERR; 143 return GNUNET_SYSERR;
145 } 144 }
146 res = ((makeHierarchyHelper (fn, tree, 0, 1) == -1) ? 145 res = ((makeHierarchyHelper (fn, tree, 0, 1) == -1) ?
147 GNUNET_SYSERR : GNUNET_OK); 146 GNUNET_SYSERR : GNUNET_OK);
148 GNUNET_free (fn); 147 GNUNET_free (fn);
@@ -160,89 +159,87 @@ static void *
160eventCallback (void *cls, const GNUNET_FSUI_Event * event) 159eventCallback (void *cls, const GNUNET_FSUI_Event * event)
161{ 160{
162 switch (event->type) 161 switch (event->type)
163 { 162 {
164 case GNUNET_FSUI_download_suspended: 163 case GNUNET_FSUI_download_suspended:
165 download = NULL; 164 download = NULL;
166 break; 165 break;
167 case GNUNET_FSUI_download_resumed: 166 case GNUNET_FSUI_download_resumed:
168 download = event->data.DownloadResumed.dc.pos; 167 download = event->data.DownloadResumed.dc.pos;
169 break; 168 break;
170 break; 169 break;
171 case GNUNET_FSUI_upload_progress: 170 case GNUNET_FSUI_upload_progress:
172#if DEBUG_VERBOSE > 1 171#if DEBUG_VERBOSE > 1
173 printf ("Upload is progressing (%llu/%llu)...\n", 172 printf ("Upload is progressing (%llu/%llu)...\n",
174 event->data.UploadProgress.completed, 173 event->data.UploadProgress.completed,
175 event->data.UploadProgress.total); 174 event->data.UploadProgress.total);
176#endif 175#endif
177 break; 176 break;
178 case GNUNET_FSUI_upload_completed: 177 case GNUNET_FSUI_upload_completed:
179 upURI = GNUNET_ECRS_uri_duplicate (event->data.UploadCompleted.uri); 178 upURI = GNUNET_ECRS_uri_duplicate (event->data.UploadCompleted.uri);
180#if DEBUG_VERBOSE 179#if DEBUG_VERBOSE
181 printf ("Upload of `%s' complete.\n", 180 printf ("Upload of `%s' complete.\n", event->data.UploadCompleted.filename);
182 event->data.UploadCompleted.filename);
183#endif 181#endif
184 break; 182 break;
185 case GNUNET_FSUI_download_completed: 183 case GNUNET_FSUI_download_completed:
186#if DEBUG_VERBOSE 184#if DEBUG_VERBOSE
187 printf ("Download of `%s' complete.\n", 185 printf ("Download of `%s' complete.\n",
188 event->data.DownloadCompleted.filename); 186 event->data.DownloadCompleted.filename);
189#endif 187#endif
190 if (checkHierarchy (43, DIRECTORY_TREE_SPEC) == GNUNET_OK) 188 if (checkHierarchy (43, DIRECTORY_TREE_SPEC) == GNUNET_OK)
191 download_done = 1; 189 download_done = 1;
192#if DEBUG_VERBOSE 190#if DEBUG_VERBOSE
193 else 191 else
194 printf ("Hierarchy check not successful yet...\n"); 192 printf ("Hierarchy check not successful yet...\n");
195#endif 193#endif
196 break; 194 break;
197 case GNUNET_FSUI_download_progress: 195 case GNUNET_FSUI_download_progress:
198#if DEBUG_VERBOSE > 1 196#if DEBUG_VERBOSE > 1
199 printf ("Download is progressing (%llu/%llu)...\n", 197 printf ("Download is progressing (%llu/%llu)...\n",
200 event->data.DownloadProgress.completed, 198 event->data.DownloadProgress.completed,
201 event->data.DownloadProgress.total); 199 event->data.DownloadProgress.total);
202#endif 200#endif
203 break; 201 break;
204 case GNUNET_FSUI_unindex_progress: 202 case GNUNET_FSUI_unindex_progress:
205#if DEBUG_VERBOSE > 1 203#if DEBUG_VERBOSE > 1
206 printf ("Unindex is progressing (%llu/%llu)...\n", 204 printf ("Unindex is progressing (%llu/%llu)...\n",
207 event->data.UnindexProgress.completed, 205 event->data.UnindexProgress.completed,
208 event->data.UnindexProgress.total); 206 event->data.UnindexProgress.total);
209#endif 207#endif
210 break; 208 break;
211 case GNUNET_FSUI_unindex_completed: 209 case GNUNET_FSUI_unindex_completed:
212#if DEBUG_VERBOSE 210#if DEBUG_VERBOSE
213 printf ("Unindex complete.\n"); 211 printf ("Unindex complete.\n");
214#endif 212#endif
215 break; 213 break;
216 case GNUNET_FSUI_unindex_error: 214 case GNUNET_FSUI_unindex_error:
217 fprintf (stderr, "Error unindexing: %s\n", 215 fprintf (stderr, "Error unindexing: %s\n",
218 event->data.UnindexError.message); 216 event->data.UnindexError.message);
219 break; 217 break;
220 case GNUNET_FSUI_upload_error: 218 case GNUNET_FSUI_upload_error:
221 fprintf (stderr, "Error uploading: %s\n", 219 fprintf (stderr, "Error uploading: %s\n", event->data.UploadError.message);
222 event->data.UploadError.message); 220 break;
223 break; 221 case GNUNET_FSUI_download_error:
224 case GNUNET_FSUI_download_error: 222 fprintf (stderr, "Error downloading: %s\n",
225 fprintf (stderr, "Error downloading: %s\n", 223 event->data.DownloadError.message);
226 event->data.DownloadError.message); 224 break;
227 break; 225 case GNUNET_FSUI_download_aborted:
228 case GNUNET_FSUI_download_aborted:
229#if DEBUG_VERBOSE 226#if DEBUG_VERBOSE
230 printf ("Received download aborted event.\n"); 227 printf ("Received download aborted event.\n");
231#endif 228#endif
232 break; 229 break;
233 case GNUNET_FSUI_unindex_suspended: 230 case GNUNET_FSUI_unindex_suspended:
234 case GNUNET_FSUI_upload_suspended: 231 case GNUNET_FSUI_upload_suspended:
235 case GNUNET_FSUI_upload_started: 232 case GNUNET_FSUI_upload_started:
236 case GNUNET_FSUI_upload_stopped: 233 case GNUNET_FSUI_upload_stopped:
237 case GNUNET_FSUI_download_started: 234 case GNUNET_FSUI_download_started:
238 case GNUNET_FSUI_download_stopped: 235 case GNUNET_FSUI_download_stopped:
239 case GNUNET_FSUI_unindex_started: 236 case GNUNET_FSUI_unindex_started:
240 case GNUNET_FSUI_unindex_stopped: 237 case GNUNET_FSUI_unindex_stopped:
241 break; 238 break;
242 default: 239 default:
243 printf ("Unexpected event: %d\n", event->type); 240 printf ("Unexpected event: %d\n", event->type);
244 break; 241 break;
245 } 242 }
246 if (lastEvent == waitForEvent) 243 if (lastEvent == waitForEvent)
247 return NULL; /* ignore all other events */ 244 return NULL; /* ignore all other events */
248 lastEvent = event->type; 245 lastEvent = event->type;
@@ -261,6 +258,7 @@ main (int argc, char *argv[])
261 int ok; 258 int ok;
262 char *fn = NULL; 259 char *fn = NULL;
263 char *fn43 = NULL; 260 char *fn43 = NULL;
261
264 char *keywords[] = { 262 char *keywords[] = {
265 "down_foo", 263 "down_foo",
266 "down_bar", 264 "down_bar",
@@ -274,20 +272,18 @@ main (int argc, char *argv[])
274 ok = GNUNET_YES; 272 ok = GNUNET_YES;
275 cfg = GNUNET_GC_create (); 273 cfg = GNUNET_GC_create ();
276 if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf")) 274 if (-1 == GNUNET_GC_parse_configuration (cfg, "check.conf"))
277 { 275 {
278 GNUNET_GC_free (cfg); 276 GNUNET_GC_free (cfg);
279 return -1; 277 return -1;
280 } 278 }
281 fprintf(stderr, 279 fprintf (stderr, "Setup...\n");
282 "Setup...\n");
283#if START_DAEMON 280#if START_DAEMON
284 GNUNET_disk_directory_remove (NULL, 281 GNUNET_disk_directory_remove (NULL,
285 "/tmp/gnunet-fsui-recursive_download_test/"); 282 "/tmp/gnunet-fsui-recursive_download_test/");
286 daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO); 283 daemon = GNUNET_daemon_start (NULL, cfg, "peer.conf", GNUNET_NO);
287 GNUNET_GE_ASSERT (NULL, daemon != NULL); 284 GNUNET_GE_ASSERT (NULL, daemon != NULL);
288 CHECK (GNUNET_OK == 285 CHECK (GNUNET_OK ==
289 GNUNET_wait_for_daemon_running (NULL, cfg, 286 GNUNET_wait_for_daemon_running (NULL, cfg, 30 * GNUNET_CRON_SECONDS));
290 30 * GNUNET_CRON_SECONDS));
291 GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to start */ 287 GNUNET_thread_sleep (5 * GNUNET_CRON_SECONDS); /* give apps time to start */
292 /* ACTUAL TEST CODE */ 288 /* ACTUAL TEST CODE */
293#endif 289#endif
@@ -298,10 +294,9 @@ main (int argc, char *argv[])
298 fn = makeHierarchy (42, DIRECTORY_TREE_SPEC); 294 fn = makeHierarchy (42, DIRECTORY_TREE_SPEC);
299 meta = GNUNET_meta_data_create (); 295 meta = GNUNET_meta_data_create ();
300 kuri = 296 kuri =
301 GNUNET_ECRS_keyword_command_line_to_uri (ectx, 2, 297 GNUNET_ECRS_keyword_command_line_to_uri (ectx, 2,
302 (const char **) keywords); 298 (const char **) keywords);
303 fprintf(stderr, 299 fprintf (stderr, "Uploading...\n");
304 "Uploading...\n");
305 waitForEvent = GNUNET_FSUI_upload_completed; 300 waitForEvent = GNUNET_FSUI_upload_completed;
306 upload = GNUNET_FSUI_upload_start (ctx, 301 upload = GNUNET_FSUI_upload_start (ctx,
307 fn, 302 fn,
@@ -315,19 +310,18 @@ main (int argc, char *argv[])
315 kuri = NULL; 310 kuri = NULL;
316 prog = 0; 311 prog = 0;
317 while (lastEvent != GNUNET_FSUI_upload_completed) 312 while (lastEvent != GNUNET_FSUI_upload_completed)
318 { 313 {
319 prog++; 314 prog++;
320 CHECK (prog < 5000); 315 CHECK (prog < 5000);
321 GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); 316 GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
322 if (GNUNET_shutdown_test () == GNUNET_YES) 317 if (GNUNET_shutdown_test () == GNUNET_YES)
323 break; 318 break;
324 } 319 }
325 GNUNET_FSUI_upload_stop (upload); 320 GNUNET_FSUI_upload_stop (upload);
326 upload = NULL; 321 upload = NULL;
327 CHECK (upURI != NULL); 322 CHECK (upURI != NULL);
328 323
329 fprintf(stderr, 324 fprintf (stderr, "Downloading...\n");
330 "Downloading...\n");
331 waitForEvent = GNUNET_FSUI_download_completed; 325 waitForEvent = GNUNET_FSUI_download_completed;
332 fn43 = makeName (43); 326 fn43 = makeName (43);
333 download = GNUNET_FSUI_download_start (ctx, 327 download = GNUNET_FSUI_download_start (ctx,
@@ -339,29 +333,28 @@ main (int argc, char *argv[])
339 fn43 = NULL; 333 fn43 = NULL;
340 prog = 0; 334 prog = 0;
341 while (!download_done) 335 while (!download_done)
342 { 336 {
343 prog++; 337 prog++;
344 CHECK (prog < 5000); 338 CHECK (prog < 5000);
345 GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS); 339 GNUNET_thread_sleep (50 * GNUNET_CRON_MILLISECONDS);
346 if (GNUNET_shutdown_test () == GNUNET_YES) 340 if (GNUNET_shutdown_test () == GNUNET_YES)
347 break; 341 break;
348 } 342 }
349FAILURE: 343FAILURE:
350 fprintf(stderr, 344 fprintf (stderr, "Cleanup...\n");
351 "Cleanup...\n");
352 if (meta != NULL) 345 if (meta != NULL)
353 GNUNET_meta_data_destroy (meta); 346 GNUNET_meta_data_destroy (meta);
354 if (ctx != NULL) 347 if (ctx != NULL)
355 { 348 {
356 if (download != NULL) 349 if (download != NULL)
357 GNUNET_FSUI_download_stop (download); 350 GNUNET_FSUI_download_stop (download);
358 GNUNET_FSUI_stop (ctx); 351 GNUNET_FSUI_stop (ctx);
359 } 352 }
360 if (fn != NULL) 353 if (fn != NULL)
361 { 354 {
362 GNUNET_disk_directory_remove (NULL, fn); 355 GNUNET_disk_directory_remove (NULL, fn);
363 GNUNET_free (fn); 356 GNUNET_free (fn);
364 } 357 }
365 if (kuri != NULL) 358 if (kuri != NULL)
366 GNUNET_ECRS_uri_destroy (kuri); 359 GNUNET_ECRS_uri_destroy (kuri);
367 fn43 = makeName (43); 360 fn43 = makeName (43);