diff options
Diffstat (limited to 'src/gns/plugin_block_gns.c')
-rw-r--r-- | src/gns/plugin_block_gns.c | 176 |
1 files changed, 89 insertions, 87 deletions
diff --git a/src/gns/plugin_block_gns.c b/src/gns/plugin_block_gns.c index 71cd78a8e..f4f5f906c 100644 --- a/src/gns/plugin_block_gns.c +++ b/src/gns/plugin_block_gns.c | |||
@@ -56,37 +56,38 @@ | |||
56 | * by this @a type of block (this is not an error) | 56 | * by this @a type of block (this is not an error) |
57 | */ | 57 | */ |
58 | static struct GNUNET_BLOCK_Group * | 58 | static struct GNUNET_BLOCK_Group * |
59 | block_plugin_gns_create_group(void *cls, | 59 | block_plugin_gns_create_group (void *cls, |
60 | enum GNUNET_BLOCK_Type type, | 60 | enum GNUNET_BLOCK_Type type, |
61 | uint32_t nonce, | 61 | uint32_t nonce, |
62 | const void *raw_data, | 62 | const void *raw_data, |
63 | size_t raw_data_size, | 63 | size_t raw_data_size, |
64 | va_list va) | 64 | va_list va) |
65 | { | 65 | { |
66 | unsigned int bf_size; | 66 | unsigned int bf_size; |
67 | const char *guard; | 67 | const char *guard; |
68 | 68 | ||
69 | guard = va_arg(va, const char *); | 69 | guard = va_arg (va, const char *); |
70 | if (0 == strcmp(guard, | 70 | if (0 == strcmp (guard, |
71 | "seen-set-size")) | 71 | "seen-set-size")) |
72 | bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size(va_arg(va, unsigned int), | 72 | bf_size = GNUNET_BLOCK_GROUP_compute_bloomfilter_size (va_arg (va, unsigned |
73 | BLOOMFILTER_K); | 73 | int), |
74 | else if (0 == strcmp(guard, | 74 | BLOOMFILTER_K); |
75 | "filter-size")) | 75 | else if (0 == strcmp (guard, |
76 | bf_size = va_arg(va, unsigned int); | 76 | "filter-size")) |
77 | bf_size = va_arg (va, unsigned int); | ||
77 | else | 78 | else |
78 | { | 79 | { |
79 | GNUNET_break(0); | 80 | GNUNET_break (0); |
80 | bf_size = GNS_BF_SIZE; | 81 | bf_size = GNS_BF_SIZE; |
81 | } | 82 | } |
82 | GNUNET_break(NULL == va_arg(va, const char *)); | 83 | GNUNET_break (NULL == va_arg (va, const char *)); |
83 | return GNUNET_BLOCK_GROUP_bf_create(cls, | 84 | return GNUNET_BLOCK_GROUP_bf_create (cls, |
84 | bf_size, | 85 | bf_size, |
85 | BLOOMFILTER_K, | 86 | BLOOMFILTER_K, |
86 | type, | 87 | type, |
87 | nonce, | 88 | nonce, |
88 | raw_data, | 89 | raw_data, |
89 | raw_data_size); | 90 | raw_data_size); |
90 | } | 91 | } |
91 | 92 | ||
92 | 93 | ||
@@ -110,16 +111,16 @@ block_plugin_gns_create_group(void *cls, | |||
110 | * @return characterization of result | 111 | * @return characterization of result |
111 | */ | 112 | */ |
112 | static enum GNUNET_BLOCK_EvaluationResult | 113 | static enum GNUNET_BLOCK_EvaluationResult |
113 | block_plugin_gns_evaluate(void *cls, | 114 | block_plugin_gns_evaluate (void *cls, |
114 | struct GNUNET_BLOCK_Context *ctx, | 115 | struct GNUNET_BLOCK_Context *ctx, |
115 | enum GNUNET_BLOCK_Type type, | 116 | enum GNUNET_BLOCK_Type type, |
116 | struct GNUNET_BLOCK_Group *bg, | 117 | struct GNUNET_BLOCK_Group *bg, |
117 | enum GNUNET_BLOCK_EvaluationOptions eo, | 118 | enum GNUNET_BLOCK_EvaluationOptions eo, |
118 | const struct GNUNET_HashCode *query, | 119 | const struct GNUNET_HashCode *query, |
119 | const void *xquery, | 120 | const void *xquery, |
120 | size_t xquery_size, | 121 | size_t xquery_size, |
121 | const void *reply_block, | 122 | const void *reply_block, |
122 | size_t reply_block_size) | 123 | size_t reply_block_size) |
123 | { | 124 | { |
124 | const struct GNUNET_GNSRECORD_Block *block; | 125 | const struct GNUNET_GNSRECORD_Block *block; |
125 | struct GNUNET_HashCode h; | 126 | struct GNUNET_HashCode h; |
@@ -128,48 +129,50 @@ block_plugin_gns_evaluate(void *cls, | |||
128 | if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) | 129 | if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) |
129 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; | 130 | return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED; |
130 | if (NULL == reply_block) | 131 | if (NULL == reply_block) |
132 | { | ||
133 | if (0 != xquery_size) | ||
131 | { | 134 | { |
132 | if (0 != xquery_size) | 135 | GNUNET_break_op (0); |
133 | { | 136 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; |
134 | GNUNET_break_op(0); | ||
135 | return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID; | ||
136 | } | ||
137 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
138 | } | 137 | } |
138 | return GNUNET_BLOCK_EVALUATION_REQUEST_VALID; | ||
139 | } | ||
139 | 140 | ||
140 | /* this is a reply */ | 141 | /* this is a reply */ |
141 | if (reply_block_size < sizeof(struct GNUNET_GNSRECORD_Block)) | 142 | if (reply_block_size < sizeof(struct GNUNET_GNSRECORD_Block)) |
142 | { | 143 | { |
143 | GNUNET_break_op(0); | 144 | GNUNET_break_op (0); |
144 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 145 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
145 | } | 146 | } |
146 | block = reply_block; | 147 | block = reply_block; |
147 | if (ntohl(block->purpose.size) + sizeof(struct GNUNET_CRYPTO_EcdsaSignature) + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) != | 148 | if (ntohl (block->purpose.size) + sizeof(struct |
149 | GNUNET_CRYPTO_EcdsaSignature) | ||
150 | + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) != | ||
148 | reply_block_size) | 151 | reply_block_size) |
149 | { | 152 | { |
150 | GNUNET_break_op(0); | 153 | GNUNET_break_op (0); |
151 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 154 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
152 | } | 155 | } |
153 | GNUNET_CRYPTO_hash(&block->derived_key, | 156 | GNUNET_CRYPTO_hash (&block->derived_key, |
154 | sizeof(block->derived_key), | 157 | sizeof(block->derived_key), |
155 | &h); | 158 | &h); |
156 | if (0 != GNUNET_memcmp(&h, query)) | 159 | if (0 != GNUNET_memcmp (&h, query)) |
157 | { | 160 | { |
158 | GNUNET_break_op(0); | 161 | GNUNET_break_op (0); |
159 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 162 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
160 | } | 163 | } |
161 | if (GNUNET_OK != | 164 | if (GNUNET_OK != |
162 | GNUNET_GNSRECORD_block_verify(block)) | 165 | GNUNET_GNSRECORD_block_verify (block)) |
163 | { | 166 | { |
164 | GNUNET_break_op(0); | 167 | GNUNET_break_op (0); |
165 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 168 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
166 | } | 169 | } |
167 | GNUNET_CRYPTO_hash(reply_block, | 170 | GNUNET_CRYPTO_hash (reply_block, |
168 | reply_block_size, | 171 | reply_block_size, |
169 | &chash); | 172 | &chash); |
170 | if (GNUNET_YES == | 173 | if (GNUNET_YES == |
171 | GNUNET_BLOCK_GROUP_bf_test_and_set(bg, | 174 | GNUNET_BLOCK_GROUP_bf_test_and_set (bg, |
172 | &chash)) | 175 | &chash)) |
173 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; | 176 | return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE; |
174 | return GNUNET_BLOCK_EVALUATION_OK_MORE; | 177 | return GNUNET_BLOCK_EVALUATION_OK_MORE; |
175 | } | 178 | } |
@@ -187,25 +190,25 @@ block_plugin_gns_evaluate(void *cls, | |||
187 | * (or if extracting a key from a block of this type does not work) | 190 | * (or if extracting a key from a block of this type does not work) |
188 | */ | 191 | */ |
189 | static int | 192 | static int |
190 | block_plugin_gns_get_key(void *cls, | 193 | block_plugin_gns_get_key (void *cls, |
191 | enum GNUNET_BLOCK_Type type, | 194 | enum GNUNET_BLOCK_Type type, |
192 | const void *reply_block, | 195 | const void *reply_block, |
193 | size_t reply_block_size, | 196 | size_t reply_block_size, |
194 | struct GNUNET_HashCode *key) | 197 | struct GNUNET_HashCode *key) |
195 | { | 198 | { |
196 | const struct GNUNET_GNSRECORD_Block *block; | 199 | const struct GNUNET_GNSRECORD_Block *block; |
197 | 200 | ||
198 | if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) | 201 | if (type != GNUNET_BLOCK_TYPE_GNS_NAMERECORD) |
199 | return GNUNET_SYSERR; | 202 | return GNUNET_SYSERR; |
200 | if (reply_block_size < sizeof(struct GNUNET_GNSRECORD_Block)) | 203 | if (reply_block_size < sizeof(struct GNUNET_GNSRECORD_Block)) |
201 | { | 204 | { |
202 | GNUNET_break_op(0); | 205 | GNUNET_break_op (0); |
203 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; | 206 | return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; |
204 | } | 207 | } |
205 | block = reply_block; | 208 | block = reply_block; |
206 | GNUNET_CRYPTO_hash(&block->derived_key, | 209 | GNUNET_CRYPTO_hash (&block->derived_key, |
207 | sizeof(block->derived_key), | 210 | sizeof(block->derived_key), |
208 | key); | 211 | key); |
209 | return GNUNET_OK; | 212 | return GNUNET_OK; |
210 | } | 213 | } |
211 | 214 | ||
@@ -214,16 +217,15 @@ block_plugin_gns_get_key(void *cls, | |||
214 | * Entry point for the plugin. | 217 | * Entry point for the plugin. |
215 | */ | 218 | */ |
216 | void * | 219 | void * |
217 | libgnunet_plugin_block_gns_init(void *cls) | 220 | libgnunet_plugin_block_gns_init (void *cls) |
218 | { | 221 | { |
219 | static enum GNUNET_BLOCK_Type types[] = | 222 | static enum GNUNET_BLOCK_Type types[] = { |
220 | { | ||
221 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, | 223 | GNUNET_BLOCK_TYPE_GNS_NAMERECORD, |
222 | GNUNET_BLOCK_TYPE_ANY /* end of list */ | 224 | GNUNET_BLOCK_TYPE_ANY /* end of list */ |
223 | }; | 225 | }; |
224 | struct GNUNET_BLOCK_PluginFunctions *api; | 226 | struct GNUNET_BLOCK_PluginFunctions *api; |
225 | 227 | ||
226 | api = GNUNET_new(struct GNUNET_BLOCK_PluginFunctions); | 228 | api = GNUNET_new (struct GNUNET_BLOCK_PluginFunctions); |
227 | api->evaluate = &block_plugin_gns_evaluate; | 229 | api->evaluate = &block_plugin_gns_evaluate; |
228 | api->get_key = &block_plugin_gns_get_key; | 230 | api->get_key = &block_plugin_gns_get_key; |
229 | api->create_group = &block_plugin_gns_create_group; | 231 | api->create_group = &block_plugin_gns_create_group; |
@@ -236,11 +238,11 @@ libgnunet_plugin_block_gns_init(void *cls) | |||
236 | * Exit point from the plugin. | 238 | * Exit point from the plugin. |
237 | */ | 239 | */ |
238 | void * | 240 | void * |
239 | libgnunet_plugin_block_gns_done(void *cls) | 241 | libgnunet_plugin_block_gns_done (void *cls) |
240 | { | 242 | { |
241 | struct GNUNET_BLOCK_PluginFunctions *api = cls; | 243 | struct GNUNET_BLOCK_PluginFunctions *api = cls; |
242 | 244 | ||
243 | GNUNET_free(api); | 245 | GNUNET_free (api); |
244 | return NULL; | 246 | return NULL; |
245 | } | 247 | } |
246 | 248 | ||