aboutsummaryrefslogtreecommitdiff
path: root/src/fs/plugin_block_fs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs/plugin_block_fs.c')
-rw-r--r--src/fs/plugin_block_fs.c48
1 files changed, 11 insertions, 37 deletions
diff --git a/src/fs/plugin_block_fs.c b/src/fs/plugin_block_fs.c
index 6c574fca2..902519f15 100644
--- a/src/fs/plugin_block_fs.c
+++ b/src/fs/plugin_block_fs.c
@@ -28,7 +28,6 @@
28#include "gnunet_fs_service.h" 28#include "gnunet_fs_service.h"
29#include "block_fs.h" 29#include "block_fs.h"
30#include "gnunet_signatures.h" 30#include "gnunet_signatures.h"
31#include "gnunet_constants.h"
32#include "gnunet_block_group_lib.h" 31#include "gnunet_block_group_lib.h"
33 32
34 33
@@ -40,37 +39,6 @@
40 39
41 40
42/** 41/**
43 * How many bytes should a bloomfilter be if we have already seen
44 * entry_count responses? Note that #GNUNET_CONSTANTS_BLOOMFILTER_K
45 * gives us the number of bits set per entry. Furthermore, we should
46 * not re-size the filter too often (to keep it cheap).
47 *
48 * Since other peers will also add entries but not resize the filter,
49 * we should generally pick a slightly larger size than what the
50 * strict math would suggest.
51 *
52 * @param entry_count expected number of entries in the Bloom filter
53 * @return must be a power of two and smaller or equal to 2^15.
54 */
55static size_t
56compute_bloomfilter_size (unsigned int entry_count)
57{
58 size_t size;
59 unsigned int ideal = (entry_count * GNUNET_CONSTANTS_BLOOMFILTER_K) / 4;
60 uint16_t max = 1 << 15;
61
62 if (entry_count > max)
63 return max;
64 size = 8;
65 while ((size < max) && (size < ideal))
66 size *= 2;
67 if (size > max)
68 return max;
69 return size;
70}
71
72
73/**
74 * Create a new block group. 42 * Create a new block group.
75 * 43 *
76 * @param ctx block context in which the block group is created 44 * @param ctx block context in which the block group is created
@@ -96,14 +64,15 @@ block_plugin_fs_create_group (void *cls,
96 switch (type) 64 switch (type)
97 { 65 {
98 case GNUNET_BLOCK_TYPE_FS_DBLOCK: 66 case GNUNET_BLOCK_TYPE_FS_DBLOCK:
67 GNUNET_break (NULL == va_arg (va, const char *));
99 return NULL; 68 return NULL;
100 case GNUNET_BLOCK_TYPE_FS_IBLOCK: 69 case GNUNET_BLOCK_TYPE_FS_IBLOCK:
70 GNUNET_break (NULL == va_arg (va, const char *));
101 return NULL; 71 return NULL;
102 case GNUNET_BLOCK_TYPE_FS_UBLOCK: 72 case GNUNET_BLOCK_TYPE_FS_UBLOCK:
103 guard = va_arg (va, const char *); 73 guard = va_arg (va, const char *);
104 if (0 != memcmp (guard, 74 if (0 != strcmp (guard,
105 "fs-seen-set-size", 75 "seen-set-size"))
106 strlen ("fs-seen-set-size")))
107 { 76 {
108 /* va-args invalid! bad bug, complain! */ 77 /* va-args invalid! bad bug, complain! */
109 GNUNET_break (0); 78 GNUNET_break (0);
@@ -111,10 +80,12 @@ block_plugin_fs_create_group (void *cls,
111 } 80 }
112 else 81 else
113 { 82 {
114 size = compute_bloomfilter_size (va_arg (va, unsigned int)); 83 size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned int),
84 BLOOMFILTER_K);
115 } 85 }
116 if (0 == size) 86 if (0 == size)
117 size = raw_data_size; /* not for us to determine, use what we got! */ 87 size = raw_data_size; /* not for us to determine, use what we got! */
88 GNUNET_break (NULL == va_arg (va, const char *));
118 return GNUNET_BLOCK_GROUP_bf_create (cls, 89 return GNUNET_BLOCK_GROUP_bf_create (cls,
119 size, 90 size,
120 BLOOMFILTER_K, 91 BLOOMFILTER_K,
@@ -123,6 +94,7 @@ block_plugin_fs_create_group (void *cls,
123 raw_data, 94 raw_data,
124 raw_data_size); 95 raw_data_size);
125 default: 96 default:
97 GNUNET_break (NULL == va_arg (va, const char *));
126 GNUNET_break (0); 98 GNUNET_break (0);
127 return NULL; 99 return NULL;
128 } 100 }
@@ -137,6 +109,7 @@ block_plugin_fs_create_group (void *cls,
137 * be done with the #GNUNET_BLOCK_get_key() function. 109 * be done with the #GNUNET_BLOCK_get_key() function.
138 * 110 *
139 * @param cls closure 111 * @param cls closure
112 * @param ctx block context
140 * @param type block type 113 * @param type block type
141 * @param bg group to use for evaluation 114 * @param bg group to use for evaluation
142 * @param eo control flags 115 * @param eo control flags
@@ -149,6 +122,7 @@ block_plugin_fs_create_group (void *cls,
149 */ 122 */
150static enum GNUNET_BLOCK_EvaluationResult 123static enum GNUNET_BLOCK_EvaluationResult
151block_plugin_fs_evaluate (void *cls, 124block_plugin_fs_evaluate (void *cls,
125 struct GNUNET_BLOCK_Context *ctx,
152 enum GNUNET_BLOCK_Type type, 126 enum GNUNET_BLOCK_Type type,
153 struct GNUNET_BLOCK_Group *bg, 127 struct GNUNET_BLOCK_Group *bg,
154 enum GNUNET_BLOCK_EvaluationOptions eo, 128 enum GNUNET_BLOCK_EvaluationOptions eo,
@@ -302,7 +276,7 @@ libgnunet_plugin_block_fs_init (void *cls)
302void * 276void *
303libgnunet_plugin_block_fs_done (void *cls) 277libgnunet_plugin_block_fs_done (void *cls)
304{ 278{
305 struct GNUNET_TRANSPORT_PluginFunctions *api = cls; 279 struct GNUNET_BLOCK_PluginFunctions *api = cls;
306 280
307 GNUNET_free (api); 281 GNUNET_free (api);
308 return NULL; 282 return NULL;