aboutsummaryrefslogtreecommitdiff
path: root/src/fs
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs')
-rw-r--r--src/fs/fs.c56
-rw-r--r--src/fs/fs_download.c25
-rw-r--r--src/fs/fs_publish.c9
-rw-r--r--src/fs/test_fs_download_persistence.c44
4 files changed, 85 insertions, 49 deletions
diff --git a/src/fs/fs.c b/src/fs/fs.c
index 58045591e..78d29dff1 100644
--- a/src/fs/fs.c
+++ b/src/fs/fs.c
@@ -529,9 +529,7 @@ get_write_handle (struct GNUNET_FS_Handle *h,
529 } 529 }
530 ret = GNUNET_BIO_write_open (fn); 530 ret = GNUNET_BIO_write_open (fn);
531 if (ret == NULL) 531 if (ret == NULL)
532 fprintf (stderr, 532 GNUNET_break (0);
533 "Failed to create write handle for `%s' from `%s/%s'\n",
534 fn, ext, ent);
535 GNUNET_free (fn); 533 GNUNET_free (fn);
536 return ret; 534 return ret;
537} 535}
@@ -1671,11 +1669,13 @@ count_download_requests (void *cls,
1671 * 1669 *
1672 * @param dc download context to compute for 1670 * @param dc download context to compute for
1673 * @param uni unique filename to use, use "" for the directory name 1671 * @param uni unique filename to use, use "" for the directory name
1672 * @param ext extension to use, use ".dir" for our own subdirectory
1674 * @return the expanded file name, NULL for none 1673 * @return the expanded file name, NULL for none
1675 */ 1674 */
1676static char * 1675static char *
1677get_download_sync_filename (struct GNUNET_FS_DownloadContext *dc, 1676get_download_sync_filename (struct GNUNET_FS_DownloadContext *dc,
1678 const char *uni) 1677 const char *uni,
1678 const char *ext)
1679{ 1679{
1680 char *par; 1680 char *par;
1681 char *epar; 1681 char *epar;
@@ -1688,14 +1688,15 @@ get_download_sync_filename (struct GNUNET_FS_DownloadContext *dc,
1688 uni); 1688 uni);
1689 if (dc->parent->serialization == NULL) 1689 if (dc->parent->serialization == NULL)
1690 return NULL; 1690 return NULL;
1691 par = get_download_sync_filename (dc->parent, dc->parent->serialization); 1691 par = get_download_sync_filename (dc->parent, dc->parent->serialization, "");
1692 if (par == NULL) 1692 if (par == NULL)
1693 return NULL; 1693 return NULL;
1694 GNUNET_asprintf (&epar, 1694 GNUNET_asprintf (&epar,
1695 "%s.dir%s%s", 1695 "%s.dir%s%s%s",
1696 par, 1696 par,
1697 DIR_SEPARATOR_STR, 1697 DIR_SEPARATOR_STR,
1698 uni); 1698 uni,
1699 ext);
1699 GNUNET_free (par); 1700 GNUNET_free (par);
1700 return epar; 1701 return epar;
1701} 1702}
@@ -1720,7 +1721,7 @@ GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc)
1720 1721
1721 if (NULL == dc->serialization) 1722 if (NULL == dc->serialization)
1722 { 1723 {
1723 dir = get_download_sync_filename (dc, ""); 1724 dir = get_download_sync_filename (dc, "", "");
1724 if (dir == NULL) 1725 if (dir == NULL)
1725 return; 1726 return;
1726 if (GNUNET_OK != 1727 if (GNUNET_OK !=
@@ -1735,7 +1736,7 @@ GNUNET_FS_download_sync_ (struct GNUNET_FS_DownloadContext *dc)
1735 } 1736 }
1736 else 1737 else
1737 { 1738 {
1738 fn = get_download_sync_filename (dc, dc->serialization); 1739 fn = get_download_sync_filename (dc, dc->serialization, "");
1739 } 1740 }
1740 wh = GNUNET_BIO_write_open (fn); 1741 wh = GNUNET_BIO_write_open (fn);
1741 if (wh == NULL) 1742 if (wh == NULL)
@@ -2440,6 +2441,15 @@ deserialize_subdownload (void *cls,
2440 2441
2441 ser = get_serialization_short_name (filename); 2442 ser = get_serialization_short_name (filename);
2442 rh = GNUNET_BIO_read_open (filename); 2443 rh = GNUNET_BIO_read_open (filename);
2444 if (rh == NULL)
2445 {
2446 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2447 _("Failed to resume sub-download `%s': could not open file `%s'\n"),
2448 ser,
2449 filename);
2450 GNUNET_free (ser);
2451 return GNUNET_OK;
2452 }
2443 deserialize_download (parent->h, 2453 deserialize_download (parent->h,
2444 rh, 2454 rh,
2445 parent, 2455 parent,
@@ -2591,9 +2601,14 @@ deserialize_download (struct GNUNET_FS_Handle *h,
2591 dr->is_pending = GNUNET_YES; 2601 dr->is_pending = GNUNET_YES;
2592 dr->next = dc->pending; 2602 dr->next = dc->pending;
2593 dc->pending = dr; 2603 dc->pending = dr;
2604 GNUNET_CONTAINER_multihashmap_put (dc->active,
2605 &dr->chk.query,
2606 dr,
2607 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2608
2594 dr = NULL; 2609 dr = NULL;
2595 } 2610 }
2596 dn = get_download_sync_filename (dc, ""); 2611 dn = get_download_sync_filename (dc, dc->serialization, ".dir");
2597 if (dn != NULL) 2612 if (dn != NULL)
2598 { 2613 {
2599 if (GNUNET_YES == 2614 if (GNUNET_YES ==
@@ -2602,20 +2617,25 @@ deserialize_download (struct GNUNET_FS_Handle *h,
2602 GNUNET_free (dn); 2617 GNUNET_free (dn);
2603 } 2618 }
2604 if (parent != NULL) 2619 if (parent != NULL)
2605 GNUNET_CONTAINER_DLL_insert (parent->child_head, 2620 {
2606 parent->child_tail, 2621 abort (); // for debugging for now
2607 dc); 2622 GNUNET_CONTAINER_DLL_insert (parent->child_head,
2623 parent->child_tail,
2624 dc);
2625 }
2608 if (search != NULL) 2626 if (search != NULL)
2609 { 2627 {
2610 dc->search = search; 2628 dc->search = search;
2611 search->download = dc; 2629 search->download = dc;
2612 } 2630 }
2613 if ( (parent == NULL) || 2631 if ( (parent == NULL) &&
2614 (search == NULL) ) 2632 (search == NULL) )
2615 dc->top = GNUNET_FS_make_top (dc->h, 2633 {
2616 &GNUNET_FS_download_signal_suspend_, 2634 dc->top = GNUNET_FS_make_top (dc->h,
2617 dc); 2635 &GNUNET_FS_download_signal_suspend_,
2618 signal_download_resume (dc); 2636 dc);
2637 signal_download_resume (dc);
2638 }
2619 GNUNET_free (uris); 2639 GNUNET_free (uris);
2620 return; 2640 return;
2621 cleanup: 2641 cleanup:
diff --git a/src/fs/fs_download.c b/src/fs/fs_download.c
index 473260601..dca419fd3 100644
--- a/src/fs/fs_download.c
+++ b/src/fs/fs_download.c
@@ -1359,6 +1359,8 @@ activate_fs_download (void *cls,
1359 struct GNUNET_FS_ProgressInfo pi; 1359 struct GNUNET_FS_ProgressInfo pi;
1360 1360
1361 GNUNET_assert (NULL != client); 1361 GNUNET_assert (NULL != client);
1362 GNUNET_assert (dc->client == NULL);
1363 GNUNET_assert (dc->th == NULL);
1362 dc->client = client; 1364 dc->client = client;
1363 GNUNET_CLIENT_receive (client, 1365 GNUNET_CLIENT_receive (client,
1364 &receive_results, 1366 &receive_results,
@@ -1369,14 +1371,12 @@ activate_fs_download (void *cls,
1369 GNUNET_CONTAINER_multihashmap_iterate (dc->active, 1371 GNUNET_CONTAINER_multihashmap_iterate (dc->active,
1370 &retry_entry, 1372 &retry_entry,
1371 dc); 1373 dc);
1372 if ( (dc->th == NULL) && 1374 dc->th = GNUNET_CLIENT_notify_transmit_ready (dc->client,
1373 (dc->client != NULL) ) 1375 sizeof (struct SearchMessage),
1374 dc->th = GNUNET_CLIENT_notify_transmit_ready (dc->client, 1376 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
1375 sizeof (struct SearchMessage), 1377 GNUNET_NO,
1376 GNUNET_CONSTANTS_SERVICE_TIMEOUT, 1378 &transmit_download_request,
1377 GNUNET_NO, 1379 dc);
1378 &transmit_download_request,
1379 dc);
1380} 1380}
1381 1381
1382 1382
@@ -1559,9 +1559,11 @@ GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
1559 dc->treedepth); 1559 dc->treedepth);
1560#endif 1560#endif
1561 if (parent == NULL) 1561 if (parent == NULL)
1562 dc->top = GNUNET_FS_make_top (dc->h, 1562 {
1563 &GNUNET_FS_download_signal_suspend_, 1563 dc->top = GNUNET_FS_make_top (dc->h,
1564 dc); 1564 &GNUNET_FS_download_signal_suspend_,
1565 dc);
1566 }
1565 pi.status = GNUNET_FS_STATUS_DOWNLOAD_START; 1567 pi.status = GNUNET_FS_STATUS_DOWNLOAD_START;
1566 pi.value.download.specifics.start.meta = meta; 1568 pi.value.download.specifics.start.meta = meta;
1567 GNUNET_FS_download_make_status_ (&pi, dc); 1569 GNUNET_FS_download_make_status_ (&pi, dc);
@@ -1707,6 +1709,7 @@ GNUNET_FS_download_start_from_search (struct GNUNET_FS_Handle *h,
1707void 1709void
1708GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc) 1710GNUNET_FS_download_start_downloading_ (struct GNUNET_FS_DownloadContext *dc)
1709{ 1711{
1712 GNUNET_assert (dc->job_queue == NULL);
1710 dc->job_queue = GNUNET_FS_queue_ (dc->h, 1713 dc->job_queue = GNUNET_FS_queue_ (dc->h,
1711 &activate_fs_download, 1714 &activate_fs_download,
1712 &deactivate_fs_download, 1715 &deactivate_fs_download,
diff --git a/src/fs/fs_publish.c b/src/fs/fs_publish.c
index 37d33ace1..6d3f4679d 100644
--- a/src/fs/fs_publish.c
+++ b/src/fs/fs_publish.c
@@ -1115,12 +1115,9 @@ fip_signal_stop(void *cls,
1115 1115
1116 if (fi->serialization != NULL) 1116 if (fi->serialization != NULL)
1117 { 1117 {
1118 if (0 != UNLINK (fi->serialization)) 1118 GNUNET_FS_remove_sync_file_ (sc->h,
1119 { 1119 GNUNET_FS_SYNC_PATH_FILE_INFO,
1120 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, 1120 fi->serialization);
1121 "unlink",
1122 fi->serialization);
1123 }
1124 GNUNET_free (fi->serialization); 1121 GNUNET_free (fi->serialization);
1125 fi->serialization = NULL; 1122 fi->serialization = NULL;
1126 } 1123 }
diff --git a/src/fs/test_fs_download_persistence.c b/src/fs/test_fs_download_persistence.c
index dda7369ef..82e19a797 100644
--- a/src/fs/test_fs_download_persistence.c
+++ b/src/fs/test_fs_download_persistence.c
@@ -175,7 +175,6 @@ static void *
175progress_cb (void *cls, 175progress_cb (void *cls,
176 const struct GNUNET_FS_ProgressInfo *event) 176 const struct GNUNET_FS_ProgressInfo *event)
177{ 177{
178
179 switch (event->status) 178 switch (event->status)
180 { 179 {
181 case GNUNET_FS_STATUS_PUBLISH_PROGRESS: 180 case GNUNET_FS_STATUS_PUBLISH_PROGRESS:
@@ -192,17 +191,17 @@ progress_cb (void *cls,
192 (unsigned long long) (FILESIZE * 1000LL / (1+GNUNET_TIME_absolute_get_duration (start).value) / 1024LL)); 191 (unsigned long long) (FILESIZE * 1000LL / (1+GNUNET_TIME_absolute_get_duration (start).value) / 1024LL));
193 fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst"); 192 fn = GNUNET_DISK_mktemp ("gnunet-download-test-dst");
194 start = GNUNET_TIME_absolute_get (); 193 start = GNUNET_TIME_absolute_get ();
195 download = GNUNET_FS_download_start (fs, 194 GNUNET_assert (download == NULL);
196 event->value.publish.specifics.completed.chk_uri, 195 GNUNET_FS_download_start (fs,
197 NULL, 196 event->value.publish.specifics.completed.chk_uri,
198 fn, NULL, 197 NULL,
199 0, 198 fn, NULL,
200 FILESIZE, 199 0,
201 1, 200 FILESIZE,
202 GNUNET_FS_DOWNLOAD_OPTION_NONE, 201 1,
203 "download", 202 GNUNET_FS_DOWNLOAD_OPTION_NONE,
204 NULL); 203 "download",
205 GNUNET_assert (download != NULL); 204 NULL);
206 break; 205 break;
207 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED: 206 case GNUNET_FS_STATUS_DOWNLOAD_COMPLETED:
208 consider_restart (event->status); 207 consider_restart (event->status);
@@ -241,6 +240,22 @@ progress_cb (void *cls,
241 &abort_download_task, 240 &abort_download_task,
242 NULL); 241 NULL);
243 break; 242 break;
243 case GNUNET_FS_STATUS_PUBLISH_SUSPEND:
244 GNUNET_assert (event->value.publish.sc == publish);
245 publish = NULL;
246 break;
247 case GNUNET_FS_STATUS_PUBLISH_RESUME:
248 GNUNET_assert (NULL == publish);
249 publish = event->value.publish.sc;
250 break;
251 case GNUNET_FS_STATUS_DOWNLOAD_SUSPEND:
252 GNUNET_assert (event->value.download.dc == download);
253 download = NULL;
254 break;
255 case GNUNET_FS_STATUS_DOWNLOAD_RESUME:
256 GNUNET_assert (NULL == download);
257 download = event->value.download.dc;
258 break;
244 case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE: 259 case GNUNET_FS_STATUS_DOWNLOAD_ACTIVE:
245 consider_restart (event->status); 260 consider_restart (event->status);
246 break; 261 break;
@@ -264,6 +279,7 @@ progress_cb (void *cls,
264 case GNUNET_FS_STATUS_DOWNLOAD_START: 279 case GNUNET_FS_STATUS_DOWNLOAD_START:
265 consider_restart (event->status); 280 consider_restart (event->status);
266 GNUNET_assert (download == NULL); 281 GNUNET_assert (download == NULL);
282 download = event->value.download.dc;
267 GNUNET_assert (0 == strcmp ("download", event->value.download.cctx)); 283 GNUNET_assert (0 == strcmp ("download", event->value.download.cctx));
268 GNUNET_assert (NULL == event->value.download.pctx); 284 GNUNET_assert (NULL == event->value.download.pctx);
269 GNUNET_assert (NULL != event->value.download.uri); 285 GNUNET_assert (NULL != event->value.download.uri);
@@ -273,12 +289,12 @@ progress_cb (void *cls,
273 GNUNET_assert (1 == event->value.download.anonymity); 289 GNUNET_assert (1 == event->value.download.anonymity);
274 break; 290 break;
275 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED: 291 case GNUNET_FS_STATUS_DOWNLOAD_STOPPED:
276 consider_restart (event->status);
277 GNUNET_assert (download == event->value.download.dc); 292 GNUNET_assert (download == event->value.download.dc);
278 GNUNET_SCHEDULER_add_continuation (sched, 293 GNUNET_SCHEDULER_add_continuation (sched,
279 &abort_publish_task, 294 &abort_publish_task,
280 NULL, 295 NULL,
281 GNUNET_SCHEDULER_REASON_PREREQ_DONE); 296 GNUNET_SCHEDULER_REASON_PREREQ_DONE);
297 download = NULL;
282 break; 298 break;
283 default: 299 default:
284 printf ("Unexpected event: %d\n", 300 printf ("Unexpected event: %d\n",
@@ -394,7 +410,6 @@ main (int argc, char *argv[])
394 struct GNUNET_GETOPT_CommandLineOption options[] = { 410 struct GNUNET_GETOPT_CommandLineOption options[] = {
395 GNUNET_GETOPT_OPTION_END 411 GNUNET_GETOPT_OPTION_END
396 }; 412 };
397
398 GNUNET_log_setup ("test_fs_download_persistence", 413 GNUNET_log_setup ("test_fs_download_persistence",
399#if VERBOSE 414#if VERBOSE
400 "DEBUG", 415 "DEBUG",
@@ -402,6 +417,7 @@ main (int argc, char *argv[])
402 "WARNING", 417 "WARNING",
403#endif 418#endif
404 NULL); 419 NULL);
420 GNUNET_DISK_directory_remove ("/tmp/gnunet-test-fs-download/");
405 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1, 421 GNUNET_PROGRAM_run ((sizeof (argvx) / sizeof (char *)) - 1,
406 argvx, "test-fs-download-persistence", 422 argvx, "test-fs-download-persistence",
407 "nohelp", options, &run, NULL); 423 "nohelp", options, &run, NULL);