aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--TODO3
-rw-r--r--src/fs/fs.c59
-rw-r--r--src/fs/fs.h24
-rw-r--r--src/fs/fs_file_information.c37
-rw-r--r--src/include/gnunet_common.h16
-rw-r--r--src/util/common_allocation.c32
6 files changed, 112 insertions, 59 deletions
diff --git a/TODO b/TODO
index e65b3b940..0b24b0347 100644
--- a/TODO
+++ b/TODO
@@ -1,6 +1,7 @@
10.9.0pre1: 10.9.0pre1:
2* FS: [CG] 2* FS: [CG]
3 - persistence support (publish, unindex, search, download) 3 - persistence support (unindex, search, download)
4 - persistence testing (publish)
4 - gnunet-service-fs (hot-path routing, load-based routing, nitpicks) 5 - gnunet-service-fs (hot-path routing, load-based routing, nitpicks)
5 - [gnunet-service-fs.c:208]: member 'LocalGetContext::results_bf_size' is never used 6 - [gnunet-service-fs.c:208]: member 'LocalGetContext::results_bf_size' is never used
6 - [gnunet-service-fs.c:501]: member 'PendingRequest::used_pids_size' is never used 7 - [gnunet-service-fs.c:501]: member 'PendingRequest::used_pids_size' is never used
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)
diff --git a/src/fs/fs.h b/src/fs/fs.h
index 953e1e51b..2e870bb3b 100644
--- a/src/fs/fs.h
+++ b/src/fs/fs.h
@@ -602,6 +602,30 @@ void *
602GNUNET_FS_make_file_reader_context_ (const char *filename); 602GNUNET_FS_make_file_reader_context_ (const char *filename);
603 603
604 604
605
606/**
607 * Function that provides data by copying from a buffer.
608 *
609 * @param cls closure (points to the buffer)
610 * @param offset offset to read from; it is possible
611 * that the caller might need to go backwards
612 * a bit at times
613 * @param max maximum number of bytes that should be
614 * copied to buf; readers are not allowed
615 * to provide less data unless there is an error;
616 * a value of "0" will be used at the end to allow
617 * the reader to clean up its internal state
618 * @param buf where the reader should write the data
619 * @param emsg location for the reader to store an error message
620 * @return number of bytes written, usually "max", 0 on error
621 */
622size_t
623GNUNET_FS_data_reader_copy_(void *cls,
624 uint64_t offset,
625 size_t max,
626 void *buf,
627 char **emsg);
628
605/** 629/**
606 * Notification of FS that a search probe has made progress. 630 * Notification of FS that a search probe has made progress.
607 * This function is used INSTEAD of the client's event handler 631 * This function is used INSTEAD of the client's event handler
diff --git a/src/fs/fs_file_information.c b/src/fs/fs_file_information.c
index df5593f75..df53bcc1c 100644
--- a/src/fs/fs_file_information.c
+++ b/src/fs/fs_file_information.c
@@ -131,41 +131,6 @@ GNUNET_FS_file_information_create_from_file (struct GNUNET_FS_Handle *h,
131 131
132 132
133/** 133/**
134 * Function that provides data by copying from a buffer.
135 *
136 * @param cls closure (points to the buffer)
137 * @param offset offset to read from; it is possible
138 * that the caller might need to go backwards
139 * a bit at times
140 * @param max maximum number of bytes that should be
141 * copied to buf; readers are not allowed
142 * to provide less data unless there is an error;
143 * a value of "0" will be used at the end to allow
144 * the reader to clean up its internal state
145 * @param buf where the reader should write the data
146 * @param emsg location for the reader to store an error message
147 * @return number of bytes written, usually "max", 0 on error
148 */
149static size_t
150data_reader_copy(void *cls,
151 uint64_t offset,
152 size_t max,
153 void *buf,
154 char **emsg)
155{
156 char *data = cls;
157
158 if (max == 0)
159 {
160 GNUNET_free (data);
161 return 0;
162 }
163 memcpy (buf, &data[offset], max);
164 return max;
165}
166
167
168/**
169 * Create an entry for a file in a publish-structure. 134 * Create an entry for a file in a publish-structure.
170 * 135 *
171 * @param h handle to the file sharing subsystem 136 * @param h handle to the file sharing subsystem
@@ -205,7 +170,7 @@ GNUNET_FS_file_information_create_from_data (struct GNUNET_FS_Handle *h,
205 return GNUNET_FS_file_information_create_from_reader (h, 170 return GNUNET_FS_file_information_create_from_reader (h,
206 client_info, 171 client_info,
207 length, 172 length,
208 &data_reader_copy, 173 &GNUNET_FS_data_reader_copy_,
209 data, 174 data,
210 keywords, 175 keywords,
211 meta, 176 meta,
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h
index d7842a519..cb2ed4c0c 100644
--- a/src/include/gnunet_common.h
+++ b/src/include/gnunet_common.h
@@ -322,7 +322,7 @@ unsigned long long GNUNET_htonll (unsigned long long n);
322 * 322 *
323 * @param size the number of bytes to allocate, must be 323 * @param size the number of bytes to allocate, must be
324 * smaller than 40 MB. 324 * smaller than 40 MB.
325 * @return pointer to size bytes of memory 325 * @return pointer to size bytes of memory, never NULL (!)
326 */ 326 */
327#define GNUNET_malloc(size) GNUNET_xmalloc_(size, __FILE__, __LINE__) 327#define GNUNET_malloc(size) GNUNET_xmalloc_(size, __FILE__, __LINE__)
328 328
@@ -331,7 +331,7 @@ unsigned long long GNUNET_htonll (unsigned long long n);
331 * The memory will be zero'ed out. 331 * The memory will be zero'ed out.
332 * 332 *
333 * @param size the number of bytes to allocate 333 * @param size the number of bytes to allocate
334 * @return pointer to size bytes of memory 334 * @return pointer to size bytes of memory, NULL if we do not have enough memory
335 */ 335 */
336#define GNUNET_malloc_large(size) GNUNET_xmalloc_unchecked_(size, __FILE__, __LINE__) 336#define GNUNET_malloc_large(size) GNUNET_xmalloc_unchecked_(size, __FILE__, __LINE__)
337 337
@@ -452,16 +452,16 @@ void *GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber);
452 452
453 453
454/** 454/**
455 * Allocate memory. This function does not check if the 455 * Allocate memory. This function does not check if the allocation
456 * allocation request is within reasonable bounds, allowing 456 * request is within reasonable bounds, allowing allocations larger
457 * allocations larger than 40 MB. If you don't expect the 457 * than 40 MB. If you don't expect the possibility of very large
458 * possibility of very large allocations, use GNUNET_malloc instead. 458 * allocations, use GNUNET_malloc instead. The memory will be zero'ed
459 * The memory will be zero'ed out. 459 * out.
460 * 460 *
461 * @param size number of bytes to allocate 461 * @param size number of bytes to allocate
462 * @param filename where is this call being made (for debugging) 462 * @param filename where is this call being made (for debugging)
463 * @param linenumber line where this call is being made (for debugging) 463 * @param linenumber line where this call is being made (for debugging)
464 * @return allocated memory, never NULL 464 * @return pointer to size bytes of memory, NULL if we do not have enough memory
465 */ 465 */
466void *GNUNET_xmalloc_unchecked_ (size_t size, 466void *GNUNET_xmalloc_unchecked_ (size_t size,
467 const char *filename, int linenumber); 467 const char *filename, int linenumber);
diff --git a/src/util/common_allocation.c b/src/util/common_allocation.c
index 5be7caaa7..e62c12d08 100644
--- a/src/util/common_allocation.c
+++ b/src/util/common_allocation.c
@@ -47,19 +47,36 @@ static LONG mem_used = 0;
47 * this function (or GNUNET_malloc) to allocate more than several MB 47 * this function (or GNUNET_malloc) to allocate more than several MB
48 * of memory, if you are possibly needing a very large chunk use 48 * of memory, if you are possibly needing a very large chunk use
49 * GNUNET_xmalloc_unchecked_ instead. 49 * GNUNET_xmalloc_unchecked_ instead.
50 * @param filename where in the code was the call to GNUNET_array_grow 50 * @param filename where in the code was the call to GNUNET_malloc
51 * @param linenumber where in the code was the call to GNUNET_array_grow 51 * @param linenumber where in the code was the call to GNUNET_malloc
52 * @return pointer to size bytes of memory 52 * @return pointer to size bytes of memory
53 */ 53 */
54void * 54void *
55GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber) 55GNUNET_xmalloc_ (size_t size, const char *filename, int linenumber)
56{ 56{
57 void *ret;
57 /* As a security precaution, we generally do not allow very large 58 /* As a security precaution, we generally do not allow very large
58 allocations using the default 'GNUNET_malloc' macro */ 59 allocations using the default 'GNUNET_malloc' macro */
59 GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber); 60 GNUNET_assert_at (size <= GNUNET_MAX_MALLOC_CHECKED, filename, linenumber);
60 return GNUNET_xmalloc_unchecked_ (size, filename, linenumber); 61 ret = GNUNET_xmalloc_unchecked_ (size, filename, linenumber);
62 if (ret == NULL)
63 {
64 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc");
65 abort ();
66 }
67 return ret;
61} 68}
62 69
70
71/**
72 * Wrapper around malloc. Allocates size bytes of memory.
73 * The memory will be zero'ed out.
74 *
75 * @param size the number of bytes to allocate
76 * @param filename where in the code was the call to GNUNET_malloc_large
77 * @param linenumber where in the code was the call to GNUNET_malloc_large
78 * @return pointer to size bytes of memory, NULL if we do not have enough memory
79 */
63void * 80void *
64GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber) 81GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber)
65{ 82{
@@ -74,10 +91,7 @@ GNUNET_xmalloc_unchecked_ (size_t size, const char *filename, int linenumber)
74 GNUNET_assert_at (size < INT_MAX, filename, linenumber); 91 GNUNET_assert_at (size < INT_MAX, filename, linenumber);
75 result = malloc (size); 92 result = malloc (size);
76 if (result == NULL) 93 if (result == NULL)
77 { 94 return NULL;
78 GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "malloc");
79 abort ();
80 }
81 memset (result, 0, size); 95 memset (result, 0, size);
82 96
83#ifdef W32_MEM_LIMIT 97#ifdef W32_MEM_LIMIT
@@ -148,8 +162,8 @@ GNUNET_xfree_ (void *ptr, const char *filename, int linenumber)
148 * Dup a string (same semantics as strdup). 162 * Dup a string (same semantics as strdup).
149 * 163 *
150 * @param str the string to dup 164 * @param str the string to dup
151 * @param filename where in the code was the call to GNUNET_array_grow 165 * @param filename where in the code was the call to GNUNET_strdup
152 * @param linenumber where in the code was the call to GNUNET_array_grow 166 * @param linenumber where in the code was the call to GNUNET_strdup
153 * @return strdup(str) 167 * @return strdup(str)
154 */ 168 */
155char * 169char *