2 This file is part of GNUnet.
3 (C) 2001, 2002, 2003, 2004, 2005, 2006, 2008, 2009 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 2, or (at your
8 option) any later version.
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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file fs/fs_download.c
22 * @brief download methods
23 * @author Christian Grothoff
26 * - location URI suppport (can wait, easy)
27 * - check if blocks exist already (can wait, easy)
28 * - handle recursive downloads (need directory &
29 * fs-level download-parallelism management, can wait)
30 * - check if iblocks can be computed from existing blocks (can wait, hard)
31 * - persistence (can wait)
34 #include "gnunet_constants.h"
35 #include "gnunet_fs_service.h"
39 #define DEBUG_DOWNLOAD GNUNET_YES
42 * We're storing the IBLOCKS after the
43 * DBLOCKS on disk (so that we only have
44 * to truncate the file once we're done).
46 * Given the offset of a block (with respect
47 * to the DBLOCKS) and its depth, return the
48 * offset where we would store this block
52 * @param fsize overall file size
53 * @param off offset of the block in the file
54 * @param depth depth of the block in the tree
55 * @param treedepth maximum depth of the tree
56 * @return off for DBLOCKS (depth == treedepth),
57 * otherwise an offset past the end
58 * of the file that does not overlap
59 * with the range for any other block
62 compute_disk_offset (uint64_t fsize,
65 unsigned int treedepth)
68 uint64_t lsize; /* what is the size of all IBlocks for depth "i"? */
69 uint64_t loff; /* where do IBlocks for depth "i" start? */
70 unsigned int ioff; /* which IBlock corresponds to "off" at depth "i"? */
72 if (depth == treedepth)
74 /* first IBlocks start at the end of file, rounded up
75 to full DBLOCK_SIZE */
76 loff = ((fsize + DBLOCK_SIZE - 1) / DBLOCK_SIZE) * DBLOCK_SIZE;
77 lsize = ( (fsize + DBLOCK_SIZE-1) / DBLOCK_SIZE) * sizeof (struct ContentHashKey);
78 GNUNET_assert (0 == (off % DBLOCK_SIZE));
79 ioff = (off / DBLOCK_SIZE);
80 for (i=treedepth-1;i>depth;i--)
83 lsize = (lsize + CHK_PER_INODE - 1) / CHK_PER_INODE;
84 GNUNET_assert (lsize > 0);
85 GNUNET_assert (0 == (ioff % CHK_PER_INODE));
86 ioff /= CHK_PER_INODE;
88 return loff + ioff * sizeof (struct ContentHashKey);
93 * Given a file of the specified treedepth and a block at the given
94 * offset and depth, calculate the offset for the CHK at the given
97 * @param offset the offset of the first
98 * DBLOCK in the subtree of the
100 * @param depth the depth of the IBLOCK in the tree
101 * @param treedepth overall depth of the tree
102 * @param k which CHK in the IBLOCK are we
104 * @return offset if k=0, otherwise an appropriately
105 * larger value (i.e., if depth = treedepth-1,
106 * the returned value should be offset+DBLOCK_SIZE)
109 compute_dblock_offset (uint64_t offset,
111 unsigned int treedepth,
115 uint64_t lsize; /* what is the size of the sum of all DBlocks
116 that a CHK at depth i corresponds to? */
118 if (depth == treedepth)
121 for (i=treedepth-1;i>depth;i--)
122 lsize *= CHK_PER_INODE;
123 return offset + k * lsize;
128 * Fill in all of the generic fields for
131 * @param pi structure to fill in
132 * @param dc overall download context
135 make_download_status (struct GNUNET_FS_ProgressInfo *pi,
136 struct GNUNET_FS_DownloadContext *dc)
138 pi->value.download.dc = dc;
139 pi->value.download.cctx
141 pi->value.download.pctx
142 = (dc->parent == NULL) ? NULL : dc->parent->client_info;
143 pi->value.download.uri
145 pi->value.download.filename
147 pi->value.download.size
149 pi->value.download.duration
150 = GNUNET_TIME_absolute_get_duration (dc->start_time);
151 pi->value.download.completed
153 pi->value.download.anonymity
158 * We're ready to transmit a search request to the
159 * file-sharing service. Do it. If there is
160 * more than one request pending, try to send
161 * multiple or request another transmission.
164 * @param size number of bytes available in buf
165 * @param buf where the callee should write the message
166 * @return number of bytes written to buf
169 transmit_download_request (void *cls,
175 * Schedule the download of the specified
178 * @param dc overall download this block belongs to
179 * @param chk content-hash-key of the block
180 * @param offset offset of the block in the file
181 * (for IBlocks, the offset is the lowest
182 * offset of any DBlock in the subtree under
184 * @param depth depth of the block, 0 is the root of the tree
187 schedule_block_download (struct GNUNET_FS_DownloadContext *dc,
188 const struct ContentHashKey *chk,
192 struct DownloadRequest *sm;
196 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
197 "Scheduling download at offset %llu and depth %u for `%s'\n",
198 (unsigned long long) offset,
200 GNUNET_h2s (&chk->query));
202 off = compute_disk_offset (GNUNET_ntohll (dc->uri->data.chk.file_length),
206 if ( (dc->old_file_size > off) &&
207 (dc->handle != NULL) &&
209 GNUNET_DISK_file_seek (dc->handle,
211 GNUNET_DISK_SEEK_SET) ) )
213 // FIXME: check if block exists on disk!
214 // (read block, encode, compare with
215 // query; if matches, simply return)
217 if (depth < dc->treedepth)
219 // FIXME: try if we could
220 // reconstitute this IBLOCK
221 // from the existing blocks on disk (can wait)
222 // (read block(s), encode, compare with
223 // query; if matches, simply return)
225 sm = GNUNET_malloc (sizeof (struct DownloadRequest));
229 sm->is_pending = GNUNET_YES;
230 sm->next = dc->pending;
232 GNUNET_CONTAINER_multihashmap_put (dc->active,
235 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
237 if ( (dc->th == NULL) &&
238 (dc->client != NULL) )
239 dc->th = GNUNET_CLIENT_notify_transmit_ready (dc->client,
240 sizeof (struct SearchMessage),
241 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
243 &transmit_download_request,
250 * We've lost our connection with the FS service.
251 * Re-establish it and re-transmit all of our
254 * @param dc download context that is having trouble
257 try_reconnect (struct GNUNET_FS_DownloadContext *dc);
261 * Compute how many bytes of data should be stored in
262 * the specified node.
264 * @param fsize overall file size
265 * @param totaldepth depth of the entire tree
266 * @param offset offset of the node
267 * @param depth depth of the node
268 * @return number of bytes stored in this node
271 calculate_block_size (uint64_t fsize,
272 unsigned int totaldepth,
282 GNUNET_assert (offset < fsize);
283 if (depth == totaldepth)
286 if (offset + ret > fsize)
287 ret = (size_t) (fsize - offset);
292 for (i = totaldepth-1; i > depth; i--)
293 rsize *= CHK_PER_INODE;
294 epos = offset + rsize * CHK_PER_INODE;
295 GNUNET_assert (epos > offset);
298 /* round up when computing #CHKs in our IBlock */
299 chks = (epos - offset + rsize - 1) / rsize;
300 GNUNET_assert (chks <= CHK_PER_INODE);
301 return chks * sizeof (struct ContentHashKey);
306 * Closure for iterator processing results.
308 struct ProcessResultClosure
314 GNUNET_HashCode query;
317 * Data found in P2P network.
322 * Our download context.
324 struct GNUNET_FS_DownloadContext *dc;
327 * Number of bytes in data.
340 * Iterator over entries in the pending requests in the 'active' map for the
341 * reply that we just got.
343 * @param cls closure (our 'struct ProcessResultClosure')
344 * @param key query for the given value / request
345 * @param value value in the hash map (a 'struct DownloadRequest')
346 * @return GNUNET_YES (we should continue to iterate); unless serious error
349 process_result_with_request (void *cls,
350 const GNUNET_HashCode * key,
353 struct ProcessResultClosure *prc = cls;
354 struct DownloadRequest *sm = value;
355 struct GNUNET_FS_DownloadContext *dc = prc->dc;
356 struct GNUNET_CRYPTO_AesSessionKey skey;
357 struct GNUNET_CRYPTO_AesInitializationVector iv;
359 struct GNUNET_FS_ProgressInfo pi;
363 struct ContentHashKey *chk;
366 if (prc->size != calculate_block_size (GNUNET_ntohll (dc->uri->data.chk.file_length),
372 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
373 "Internal error or bogus download URI (expected %u bytes, got %u)\n",
374 calculate_block_size (GNUNET_ntohll (dc->uri->data.chk.file_length),
380 dc->emsg = GNUNET_strdup ("Internal error or bogus download URI");
382 pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR;
383 make_download_status (&pi, dc);
384 pi.value.download.specifics.error.message = dc->emsg;
385 dc->client_info = dc->h->upcb (dc->h->upcb_cls,
387 /* abort all pending requests */
390 GNUNET_CLIENT_notify_transmit_ready_cancel (dc->th);
393 GNUNET_CLIENT_disconnect (dc->client);
397 GNUNET_assert (GNUNET_YES ==
398 GNUNET_CONTAINER_multihashmap_remove (dc->active,
401 GNUNET_CRYPTO_hash_to_aes_key (&sm->chk.key, &skey, &iv);
402 GNUNET_CRYPTO_aes_decrypt (prc->data,
408 if ( (NULL != dc->handle) &&
409 ( (sm->depth == dc->treedepth) ||
410 (0 == (dc->options & GNUNET_FS_DOWNLOAD_NO_TEMPORARIES)) ) )
412 off = compute_disk_offset (GNUNET_ntohll (dc->uri->data.chk.file_length),
418 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
419 "Saving decrypted block to disk at offset %llu\n",
420 (unsigned long long) off);
423 GNUNET_DISK_file_seek (dc->handle,
425 GNUNET_DISK_SEEK_SET) ) )
426 GNUNET_asprintf (&emsg,
427 _("Failed to seek to offset %llu in file `%s': %s\n"),
428 (unsigned long long) off,
431 else if (prc->size !=
432 GNUNET_DISK_file_write (dc->handle,
435 GNUNET_asprintf (&emsg,
436 _("Failed to write block of %u bytes at offset %llu in file `%s': %s\n"),
437 (unsigned int) prc->size,
438 (unsigned long long) off,
444 // FIXME: make persistent
447 pi.status = GNUNET_FS_STATUS_DOWNLOAD_ERROR;
448 make_download_status (&pi, dc);
449 pi.value.download.specifics.error.message = emsg;
450 dc->client_info = dc->h->upcb (dc->h->upcb_cls,
453 /* abort all pending requests */
456 GNUNET_CLIENT_notify_transmit_ready_cancel (dc->th);
459 GNUNET_CLIENT_disconnect (dc->client);
465 if (sm->depth == dc->treedepth)
468 if (sm->offset < dc->offset)
470 /* starting offset begins in the middle of pt,
471 do not count first bytes as progress */
472 GNUNET_assert (app > (dc->offset - sm->offset));
473 app -= (dc->offset - sm->offset);
475 if (sm->offset + prc->size > dc->offset + dc->length)
477 /* end of block is after relevant range,
478 do not count last bytes as progress */
479 GNUNET_assert (app > (sm->offset + prc->size) - (dc->offset + dc->length));
480 app -= (sm->offset + prc->size) - (dc->offset + dc->length);
482 dc->completed += app;
485 pi.status = GNUNET_FS_STATUS_DOWNLOAD_PROGRESS;
486 make_download_status (&pi, dc);
487 pi.value.download.specifics.progress.data = pt;
488 pi.value.download.specifics.progress.offset = sm->offset;
489 pi.value.download.specifics.progress.data_len = prc->size;
490 pi.value.download.specifics.progress.depth = sm->depth;
491 dc->client_info = dc->h->upcb (dc->h->upcb_cls,
493 GNUNET_assert (dc->completed <= dc->length);
494 if (dc->completed == dc->length)
497 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
498 "Download completed, truncating file to desired length %llu\n",
499 (unsigned long long) GNUNET_ntohll (dc->uri->data.chk.file_length));
501 /* truncate file to size (since we store IBlocks at the end) */
502 if (dc->handle != NULL)
504 GNUNET_DISK_file_close (dc->handle);
506 if (0 != truncate (dc->filename,
507 GNUNET_ntohll (dc->uri->data.chk.file_length)))
508 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
512 /* signal completion */
513 pi.status = GNUNET_FS_STATUS_DOWNLOAD_COMPLETED;
514 make_download_status (&pi, dc);
515 dc->client_info = dc->h->upcb (dc->h->upcb_cls,
517 GNUNET_assert (sm->depth == dc->treedepth);
519 // FIXME: make persistent
520 if (sm->depth == dc->treedepth)
526 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
527 "Triggering downloads of children (this block was at depth %u and offset %llu)\n",
529 (unsigned long long) sm->offset);
531 GNUNET_assert (0 == (prc->size % sizeof(struct ContentHashKey)));
532 chk = (struct ContentHashKey*) pt;
533 for (i=(prc->size / sizeof(struct ContentHashKey))-1;i>=0;i--)
535 off = compute_dblock_offset (sm->offset,
539 if ( (off + DBLOCK_SIZE >= dc->offset) &&
540 (off < dc->offset + dc->length) )
541 schedule_block_download (dc,
552 * Process a download result.
554 * @param dc our download context
555 * @param type type of the result
556 * @param data the (encrypted) response
557 * @param size size of data
560 process_result (struct GNUNET_FS_DownloadContext *dc,
565 struct ProcessResultClosure prc;
571 GNUNET_CRYPTO_hash (data, size, &prc.query);
573 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
574 "Received result for query `%s' from `%s'-service\n",
575 GNUNET_h2s (&prc.query),
578 GNUNET_CONTAINER_multihashmap_get_multiple (dc->active,
580 &process_result_with_request,
586 * Type of a function to call when we receive a message
590 * @param msg message received, NULL on timeout or fatal error
593 receive_results (void *cls,
594 const struct GNUNET_MessageHeader * msg)
596 struct GNUNET_FS_DownloadContext *dc = cls;
597 const struct PutMessage *cm;
600 if ( (NULL == msg) ||
601 (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_FS_PUT) ||
602 (sizeof (struct PutMessage) > ntohs(msg->size)) )
604 GNUNET_break (msg == NULL);
608 msize = ntohs(msg->size);
609 cm = (const struct PutMessage*) msg;
613 msize - sizeof (struct PutMessage));
614 if (dc->client == NULL)
615 return; /* fatal error */
616 /* continue receiving */
617 GNUNET_CLIENT_receive (dc->client,
620 GNUNET_TIME_UNIT_FOREVER_REL);
626 * We're ready to transmit a search request to the
627 * file-sharing service. Do it. If there is
628 * more than one request pending, try to send
629 * multiple or request another transmission.
632 * @param size number of bytes available in buf
633 * @param buf where the callee should write the message
634 * @return number of bytes written to buf
637 transmit_download_request (void *cls,
641 struct GNUNET_FS_DownloadContext *dc = cls;
643 struct SearchMessage *sm;
651 GNUNET_assert (size >= sizeof (struct SearchMessage));
654 while ( (dc->pending != NULL) &&
655 (size > msize + sizeof (struct SearchMessage)) )
658 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
659 "Transmitting download request for `%s' to `%s'-service\n",
660 GNUNET_h2s (&dc->pending->chk.query),
663 memset (sm, 0, sizeof (struct SearchMessage));
664 sm->header.size = htons (sizeof (struct SearchMessage));
665 sm->header.type = htons (GNUNET_MESSAGE_TYPE_FS_START_SEARCH);
666 if (dc->pending->depth == dc->treedepth)
667 sm->type = htonl (GNUNET_DATASTORE_BLOCKTYPE_DBLOCK);
669 sm->type = htonl (GNUNET_DATASTORE_BLOCKTYPE_IBLOCK);
670 sm->anonymity_level = htonl (dc->anonymity);
671 sm->target = dc->target.hashPubKey;
672 sm->query = dc->pending->chk.query;
673 dc->pending->is_pending = GNUNET_NO;
674 dc->pending = dc->pending->next;
675 msize += sizeof (struct SearchMessage);
678 if (dc->pending != NULL)
679 dc->th = GNUNET_CLIENT_notify_transmit_ready (dc->client,
680 sizeof (struct SearchMessage),
681 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
683 &transmit_download_request,
690 * Reconnect to the FS service and transmit our queries NOW.
692 * @param cls our download context
696 do_reconnect (void *cls,
697 const struct GNUNET_SCHEDULER_TaskContext *tc)
699 struct GNUNET_FS_DownloadContext *dc = cls;
700 struct GNUNET_CLIENT_Connection *client;
702 dc->task = GNUNET_SCHEDULER_NO_TASK;
703 client = GNUNET_CLIENT_connect (dc->h->sched,
708 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
709 "Connecting to `%s'-service failed, will try again.\n",
715 dc->th = GNUNET_CLIENT_notify_transmit_ready (client,
716 sizeof (struct SearchMessage),
717 GNUNET_CONSTANTS_SERVICE_TIMEOUT,
719 &transmit_download_request,
721 GNUNET_CLIENT_receive (client,
724 GNUNET_TIME_UNIT_FOREVER_REL);
729 * Add entries that are not yet pending back to the pending list.
731 * @param cls our download context
733 * @param entry entry of type "struct DownloadRequest"
737 retry_entry (void *cls,
738 const GNUNET_HashCode *key,
741 struct GNUNET_FS_DownloadContext *dc = cls;
742 struct DownloadRequest *dr = entry;
744 if (! dr->is_pending)
746 dr->next = dc->pending;
747 dr->is_pending = GNUNET_YES;
755 * We've lost our connection with the FS service.
756 * Re-establish it and re-transmit all of our
759 * @param dc download context that is having trouble
762 try_reconnect (struct GNUNET_FS_DownloadContext *dc)
765 if (NULL != dc->client)
769 GNUNET_CLIENT_notify_transmit_ready_cancel (dc->th);
772 GNUNET_CONTAINER_multihashmap_iterate (dc->active,
775 GNUNET_CLIENT_disconnect (dc->client);
779 = GNUNET_SCHEDULER_add_delayed (dc->h->sched,
780 GNUNET_TIME_UNIT_SECONDS,
787 * Download parts of a file. Note that this will store
788 * the blocks at the respective offset in the given file. Also, the
789 * download is still using the blocking of the underlying FS
790 * encoding. As a result, the download may *write* outside of the
791 * given boundaries (if offset and length do not match the 32k FS
792 * block boundaries). <p>
794 * This function should be used to focus a download towards a
795 * particular portion of the file (optimization), not to strictly
796 * limit the download to exactly those bytes.
798 * @param h handle to the file sharing subsystem
799 * @param uri the URI of the file (determines what to download); CHK or LOC URI
800 * @param meta known metadata for the file (can be NULL)
801 * @param filename where to store the file, maybe NULL (then no file is
802 * created on disk and data must be grabbed from the callbacks)
803 * @param offset at what offset should we start the download (typically 0)
804 * @param length how many bytes should be downloaded starting at offset
805 * @param anonymity anonymity level to use for the download
806 * @param options various options
807 * @param cctx initial value for the client context for this download
808 * @param parent parent download to associate this download with (use NULL
809 * for top-level downloads; useful for manually-triggered recursive downloads)
810 * @return context that can be used to control this download
812 struct GNUNET_FS_DownloadContext *
813 GNUNET_FS_download_start (struct GNUNET_FS_Handle *h,
814 const struct GNUNET_FS_Uri *uri,
815 const struct GNUNET_CONTAINER_MetaData *meta,
816 const char *filename,
820 enum GNUNET_FS_DownloadOptions options,
822 struct GNUNET_FS_DownloadContext *parent)
824 struct GNUNET_FS_ProgressInfo pi;
825 struct GNUNET_FS_DownloadContext *dc;
826 struct GNUNET_CLIENT_Connection *client;
828 GNUNET_assert (GNUNET_FS_uri_test_chk (uri));
829 if ( (offset + length < offset) ||
830 (offset + length > uri->data.chk.file_length) )
835 client = GNUNET_CLIENT_connect (h->sched,
840 // FIXME: add support for "loc" URIs!
842 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
843 "Starting download `%s' of %llu bytes\n",
845 (unsigned long long) length);
847 dc = GNUNET_malloc (sizeof(struct GNUNET_FS_DownloadContext));
851 dc->uri = GNUNET_FS_uri_dup (uri);
852 dc->meta = GNUNET_CONTAINER_meta_data_duplicate (meta);
853 dc->client_info = cctx;
854 if (NULL != filename)
856 dc->filename = GNUNET_strdup (filename);
857 if (GNUNET_YES == GNUNET_DISK_file_test (filename))
858 GNUNET_DISK_file_size (filename,
861 dc->handle = GNUNET_DISK_file_open (filename,
862 GNUNET_DISK_OPEN_READWRITE |
863 GNUNET_DISK_OPEN_CREATE,
864 GNUNET_DISK_PERM_USER_READ |
865 GNUNET_DISK_PERM_USER_WRITE |
866 GNUNET_DISK_PERM_GROUP_READ |
867 GNUNET_DISK_PERM_OTHER_READ);
868 if (dc->handle == NULL)
870 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
871 _("Download failed: could not open file `%s': %s\n"),
874 GNUNET_CONTAINER_meta_data_destroy (dc->meta);
875 GNUNET_FS_uri_destroy (dc->uri);
876 GNUNET_free (dc->filename);
877 GNUNET_CLIENT_disconnect (dc->client);
882 // FIXME: set "dc->target" for LOC uris!
885 dc->anonymity = anonymity;
886 dc->options = options;
887 dc->active = GNUNET_CONTAINER_multihashmap_create (2 * (length / DBLOCK_SIZE));
888 dc->treedepth = GNUNET_FS_compute_depth (GNUNET_ntohll(dc->uri->data.chk.file_length));
890 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
891 "Download tree has depth %u\n",
894 // FIXME: make persistent
895 schedule_block_download (dc,
896 &dc->uri->data.chk.chk,
898 1 /* 0 == CHK, 1 == top */);
899 GNUNET_CLIENT_receive (client,
902 GNUNET_TIME_UNIT_FOREVER_REL);
903 pi.status = GNUNET_FS_STATUS_DOWNLOAD_START;
904 make_download_status (&pi, dc);
905 pi.value.download.specifics.start.meta = meta;
906 dc->client_info = dc->h->upcb (dc->h->upcb_cls,
914 * Free entries in the map.
916 * @param cls unused (NULL)
918 * @param entry entry of type "struct DownloadRequest" which is freed
922 free_entry (void *cls,
923 const GNUNET_HashCode *key,
932 * Stop a download (aborts if download is incomplete).
934 * @param dc handle for the download
935 * @param do_delete delete files of incomplete downloads
938 GNUNET_FS_download_stop (struct GNUNET_FS_DownloadContext *dc,
941 struct GNUNET_FS_ProgressInfo pi;
943 // FIXME: make unpersistent
944 pi.status = GNUNET_FS_STATUS_DOWNLOAD_STOPPED;
945 make_download_status (&pi, dc);
946 dc->client_info = dc->h->upcb (dc->h->upcb_cls,
949 if (GNUNET_SCHEDULER_NO_TASK != dc->task)
950 GNUNET_SCHEDULER_cancel (dc->h->sched,
954 GNUNET_CLIENT_notify_transmit_ready_cancel (dc->th);
957 if (NULL != dc->client)
958 GNUNET_CLIENT_disconnect (dc->client);
959 GNUNET_CONTAINER_multihashmap_iterate (dc->active,
962 GNUNET_CONTAINER_multihashmap_destroy (dc->active);
963 if (dc->filename != NULL)
965 if (NULL != dc->handle)
966 GNUNET_DISK_file_close (dc->handle);
967 if ( (dc->completed != dc->length) &&
968 (GNUNET_YES == do_delete) )
970 if (0 != UNLINK (dc->filename))
971 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
975 GNUNET_free (dc->filename);
977 GNUNET_CONTAINER_meta_data_destroy (dc->meta);
978 GNUNET_FS_uri_destroy (dc->uri);
982 /* end of fs_download.c */