aboutsummaryrefslogtreecommitdiff
path: root/src/fs/fs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/fs.c')
-rw-r--r--src/fs/fs.c59
1 files changed, 54 insertions, 5 deletions
diff --git a/src/fs/fs.c b/src/fs/fs.c
index e7a52d235..062870cd6 100644
--- a/src/fs/fs.c
+++ b/src/fs/fs.c
@@ -325,6 +325,42 @@ GNUNET_FS_make_file_reader_context_ (const char *filename)
325 325
326 326
327/** 327/**
328 * Function that provides data by copying from a buffer.
329 *
330 * @param cls closure (points to the buffer)
331 * @param offset offset to read from; it is possible
332 * that the caller might need to go backwards
333 * a bit at times
334 * @param max maximum number of bytes that should be
335 * copied to buf; readers are not allowed
336 * to provide less data unless there is an error;
337 * a value of "0" will be used at the end to allow
338 * the reader to clean up its internal state
339 * @param buf where the reader should write the data
340 * @param emsg location for the reader to store an error message
341 * @return number of bytes written, usually "max", 0 on error
342 */
343size_t
344GNUNET_FS_data_reader_copy_ (void *cls,
345 uint64_t offset,
346 size_t max,
347 void *buf,
348 char **emsg)
349{
350 char *data = cls;
351
352 if (max == 0)
353 {
354 GNUNET_free_non_null (data);
355 return 0;
356 }
357 memcpy (buf, &data[offset], max);
358 return max;
359}
360
361
362
363/**
328 * Return the full filename where we would store state information 364 * Return the full filename where we would store state information
329 * (for serialization/deserialization). 365 * (for serialization/deserialization).
330 * 366 *
@@ -525,11 +561,24 @@ deserialize_fi_node (struct GNUNET_FS_Handle *h,
525 ret->data.file.do_index = GNUNET_NO; 561 ret->data.file.do_index = GNUNET_NO;
526 ret->data.file.have_hash = GNUNET_NO; 562 ret->data.file.have_hash = GNUNET_NO;
527 ret->data.file.index_start_confirmed = GNUNET_NO; 563 ret->data.file.index_start_confirmed = GNUNET_NO;
528 /* FIXME: what's our approach for dealing with the 564 if (GNUNET_NO == ret->is_published)
529 'reader' and 'reader_cls' fields? I guess the only 565 {
530 good way would be to dump "small" files into 566 if (NULL == ret->filename)
531 'rh' and to not support serialization of "large" 567 {
532 files (!?) */ 568 ret->data.file.reader = &GNUNET_FS_data_reader_copy_;
569 ret->data.file.reader_cls = GNUNET_malloc_large (ret->data.file.file_size);
570 if (ret->data.file.reader_cls == NULL)
571 goto cleanup;
572 if (GNUNET_OK !=
573 GNUNET_BIO_read (rh, "file-data", ret->data.file.reader_cls, ret->data.file.file_size))
574 goto cleanup;
575 }
576 else
577 {
578 ret->data.file.reader = &GNUNET_FS_data_reader_file_;
579 ret->data.file.reader_cls = GNUNET_FS_make_file_reader_context_ (ret->filename);
580 }
581 }
533 break; 582 break;
534 case 1: /* file-index, no hash */ 583 case 1: /* file-index, no hash */
535 if (NULL == ret->filename) 584 if (NULL == ret->filename)