aboutsummaryrefslogtreecommitdiff
path: root/src/dht/plugin_block_dht.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht/plugin_block_dht.c')
-rw-r--r--src/dht/plugin_block_dht.c325
1 files changed, 177 insertions, 148 deletions
diff --git a/src/dht/plugin_block_dht.c b/src/dht/plugin_block_dht.c
index 7c6fb9ed6..a6a2104ce 100644
--- a/src/dht/plugin_block_dht.c
+++ b/src/dht/plugin_block_dht.c
@@ -116,45 +116,51 @@ block_plugin_dht_evaluate (void *cls,
116 const void *reply_block, 116 const void *reply_block,
117 size_t reply_block_size) 117 size_t reply_block_size)
118{ 118{
119 const struct GNUNET_HELLO_Message *hello; 119 switch (type)
120 struct GNUNET_PeerIdentity pid;
121 const struct GNUNET_MessageHeader *msg;
122 struct GNUNET_HashCode phash;
123
124 if (type != GNUNET_BLOCK_TYPE_DHT_HELLO)
125 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
126 if (0 != xquery_size)
127 {
128 GNUNET_break_op (0);
129 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
130 }
131 if (NULL == reply_block)
132 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
133 if (reply_block_size < sizeof(struct GNUNET_MessageHeader))
134 {
135 GNUNET_break_op (0);
136 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
137 }
138 msg = reply_block;
139 if (reply_block_size != ntohs (msg->size))
140 {
141 GNUNET_break_op (0);
142 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
143 }
144 hello = reply_block;
145 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid))
146 { 120 {
147 GNUNET_break_op (0); 121 case GNUNET_BLOCK_TYPE_DHT_HELLO:
148 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID; 122 {
123 const struct GNUNET_HELLO_Message *hello;
124 struct GNUNET_PeerIdentity pid;
125 const struct GNUNET_MessageHeader *msg;
126 struct GNUNET_HashCode phash;
127
128 if (0 != xquery_size)
129 {
130 GNUNET_break_op (0);
131 return GNUNET_BLOCK_EVALUATION_REQUEST_INVALID;
132 }
133 if (NULL == reply_block)
134 return GNUNET_BLOCK_EVALUATION_REQUEST_VALID;
135 if (reply_block_size < sizeof(struct GNUNET_MessageHeader))
136 {
137 GNUNET_break_op (0);
138 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
139 }
140 msg = reply_block;
141 if (reply_block_size != ntohs (msg->size))
142 {
143 GNUNET_break_op (0);
144 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
145 }
146 hello = reply_block;
147 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid))
148 {
149 GNUNET_break_op (0);
150 return GNUNET_BLOCK_EVALUATION_RESULT_INVALID;
151 }
152 GNUNET_CRYPTO_hash (&pid,
153 sizeof(pid),
154 &phash);
155 if (GNUNET_YES ==
156 GNUNET_BLOCK_GROUP_bf_test_and_set (group,
157 &phash))
158 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
159 return GNUNET_BLOCK_EVALUATION_OK_MORE;
160 }
161 default:
162 return GNUNET_BLOCK_EVALUATION_TYPE_NOT_SUPPORTED;
149 } 163 }
150 GNUNET_CRYPTO_hash (&pid,
151 sizeof(pid),
152 &phash);
153 if (GNUNET_YES ==
154 GNUNET_BLOCK_GROUP_bf_test_and_set (group,
155 &phash))
156 return GNUNET_BLOCK_EVALUATION_OK_DUPLICATE;
157 return GNUNET_BLOCK_EVALUATION_OK_MORE;
158} 164}
159 165
160 166
@@ -171,19 +177,23 @@ block_plugin_dht_evaluate (void *cls,
171 */ 177 */
172static enum GNUNET_GenericReturnValue 178static enum GNUNET_GenericReturnValue
173block_plugin_dht_check_query (void *cls, 179block_plugin_dht_check_query (void *cls,
174 enum GNUNET_BLOCK_Type type, 180 enum GNUNET_BLOCK_Type type,
175 const struct GNUNET_HashCode *query, 181 const struct GNUNET_HashCode *query,
176 const void *xquery, 182 const void *xquery,
177 size_t xquery_size) 183 size_t xquery_size)
178{ 184{
179 if (type != GNUNET_BLOCK_TYPE_DHT_HELLO) 185 switch (type)
180 return GNUNET_SYSERR;
181 if (0 != xquery_size)
182 { 186 {
183 GNUNET_break_op (0); 187 case GNUNET_BLOCK_TYPE_DHT_HELLO:
184 return GNUNET_NO; 188 if (0 != xquery_size)
189 {
190 GNUNET_break_op (0);
191 return GNUNET_NO;
192 }
193 return GNUNET_OK;
194 default:
195 return GNUNET_SYSERR;
185 } 196 }
186 return GNUNET_OK;
187} 197}
188 198
189 199
@@ -199,37 +209,43 @@ block_plugin_dht_check_query (void *cls,
199 */ 209 */
200static enum GNUNET_GenericReturnValue 210static enum GNUNET_GenericReturnValue
201block_plugin_dht_check_block (void *cls, 211block_plugin_dht_check_block (void *cls,
202 enum GNUNET_BLOCK_Type type, 212 enum GNUNET_BLOCK_Type type,
203 const struct GNUNET_HashCode *query, 213 const struct GNUNET_HashCode *query,
204 const void *block, 214 const void *block,
205 size_t block_size) 215 size_t block_size)
206{ 216{
207 const struct GNUNET_HELLO_Message *hello; 217 switch (type)
208 struct GNUNET_PeerIdentity pid;
209 const struct GNUNET_MessageHeader *msg;
210
211 if (type != GNUNET_BLOCK_TYPE_DHT_HELLO)
212 return GNUNET_SYSERR;
213 if (block_size < sizeof(struct GNUNET_MessageHeader))
214 {
215 GNUNET_break_op (0);
216 return GNUNET_NO;
217 }
218 msg = block;
219 if (block_size != ntohs (msg->size))
220 {
221 GNUNET_break_op (0);
222 return GNUNET_NO;
223 }
224 hello = block;
225 if (GNUNET_OK !=
226 GNUNET_HELLO_get_id (hello,
227 &pid))
228 { 218 {
229 GNUNET_break_op (0); 219 case GNUNET_BLOCK_TYPE_DHT_HELLO:
230 return GNUNET_NO; 220 {
221 const struct GNUNET_HELLO_Message *hello;
222 struct GNUNET_PeerIdentity pid;
223 const struct GNUNET_MessageHeader *msg;
224
225 if (block_size < sizeof(struct GNUNET_MessageHeader))
226 {
227 GNUNET_break_op (0);
228 return GNUNET_NO;
229 }
230 msg = block;
231 if (block_size != ntohs (msg->size))
232 {
233 GNUNET_break_op (0);
234 return GNUNET_NO;
235 }
236 hello = block;
237 if (GNUNET_OK !=
238 GNUNET_HELLO_get_id (hello,
239 &pid))
240 {
241 GNUNET_break_op (0);
242 return GNUNET_NO;
243 }
244 return GNUNET_OK;
245 }
246 default:
247 return GNUNET_SYSERR;
231 } 248 }
232 return GNUNET_OK;
233} 249}
234 250
235 251
@@ -251,49 +267,55 @@ block_plugin_dht_check_block (void *cls,
251 */ 267 */
252static enum GNUNET_BLOCK_ReplyEvaluationResult 268static enum GNUNET_BLOCK_ReplyEvaluationResult
253block_plugin_dht_check_reply ( 269block_plugin_dht_check_reply (
254 void *cls, 270 void *cls,
255 enum GNUNET_BLOCK_Type type, 271 enum GNUNET_BLOCK_Type type,
256 struct GNUNET_BLOCK_Group *group, 272 struct GNUNET_BLOCK_Group *group,
257 const struct GNUNET_HashCode *query, 273 const struct GNUNET_HashCode *query,
258 const void *xquery, 274 const void *xquery,
259 size_t xquery_size, 275 size_t xquery_size,
260 const void *reply_block, 276 const void *reply_block,
261 size_t reply_block_size) 277 size_t reply_block_size)
262{ 278{
263 const struct GNUNET_HELLO_Message *hello; 279 switch (type)
264 struct GNUNET_PeerIdentity pid;
265 const struct GNUNET_MessageHeader *msg;
266 struct GNUNET_HashCode phash;
267
268 if (type != GNUNET_BLOCK_TYPE_DHT_HELLO)
269 return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED;
270 if (reply_block_size < sizeof(struct GNUNET_MessageHeader))
271 {
272 GNUNET_break_op (0);
273 return GNUNET_BLOCK_REPLY_INVALID;
274 }
275 msg = reply_block;
276 if (reply_block_size != ntohs (msg->size))
277 {
278 GNUNET_break_op (0);
279 return GNUNET_BLOCK_REPLY_INVALID;
280 }
281 hello = reply_block;
282 if (GNUNET_OK !=
283 GNUNET_HELLO_get_id (hello,
284 &pid))
285 { 280 {
286 GNUNET_break_op (0); 281 case GNUNET_BLOCK_TYPE_DHT_HELLO:
287 return GNUNET_BLOCK_REPLY_INVALID; 282 {
283 const struct GNUNET_HELLO_Message *hello;
284 struct GNUNET_PeerIdentity pid;
285 const struct GNUNET_MessageHeader *msg;
286 struct GNUNET_HashCode phash;
287
288 if (reply_block_size < sizeof(struct GNUNET_MessageHeader))
289 {
290 GNUNET_break_op (0);
291 return GNUNET_BLOCK_REPLY_INVALID;
292 }
293 msg = reply_block;
294 if (reply_block_size != ntohs (msg->size))
295 {
296 GNUNET_break_op (0);
297 return GNUNET_BLOCK_REPLY_INVALID;
298 }
299 hello = reply_block;
300 if (GNUNET_OK !=
301 GNUNET_HELLO_get_id (hello,
302 &pid))
303 {
304 GNUNET_break_op (0);
305 return GNUNET_BLOCK_REPLY_INVALID;
306 }
307 GNUNET_CRYPTO_hash (&pid,
308 sizeof(pid),
309 &phash);
310 if (GNUNET_YES ==
311 GNUNET_BLOCK_GROUP_bf_test_and_set (group,
312 &phash))
313 return GNUNET_BLOCK_REPLY_OK_DUPLICATE;
314 return GNUNET_BLOCK_REPLY_OK_MORE;
315 }
316 default:
317 return GNUNET_BLOCK_REPLY_TYPE_NOT_SUPPORTED;
288 } 318 }
289 GNUNET_CRYPTO_hash (&pid,
290 sizeof(pid),
291 &phash);
292 if (GNUNET_YES ==
293 GNUNET_BLOCK_GROUP_bf_test_and_set (group,
294 &phash))
295 return GNUNET_BLOCK_REPLY_OK_DUPLICATE;
296 return GNUNET_BLOCK_REPLY_OK_MORE;
297} 319}
298 320
299 321
@@ -315,41 +337,47 @@ block_plugin_dht_get_key (void *cls,
315 size_t block_size, 337 size_t block_size,
316 struct GNUNET_HashCode *key) 338 struct GNUNET_HashCode *key)
317{ 339{
318 const struct GNUNET_MessageHeader *msg; 340 switch (type)
319 const struct GNUNET_HELLO_Message *hello;
320 struct GNUNET_PeerIdentity *pid;
321
322 if (type != GNUNET_BLOCK_TYPE_DHT_HELLO)
323 return GNUNET_SYSERR;
324 if (block_size < sizeof(struct GNUNET_MessageHeader))
325 {
326 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
327 "block-dht",
328 _ ("Block not of type %u\n"),
329 GNUNET_BLOCK_TYPE_DHT_HELLO);
330 return GNUNET_NO;
331 }
332 msg = block;
333 if (block_size != ntohs (msg->size))
334 {
335 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
336 "block-dht",
337 _ ("Size mismatch for block with type %u\n"),
338 GNUNET_BLOCK_TYPE_DHT_HELLO);
339 return GNUNET_NO;
340 }
341 hello = block;
342 memset (key, 0, sizeof(*key));
343 pid = (struct GNUNET_PeerIdentity *) key;
344 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, pid))
345 { 341 {
346 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 342 case GNUNET_BLOCK_TYPE_DHT_HELLO:
347 "block-dht", 343 {
348 _ ("Block of type %u is malformed\n"), 344 const struct GNUNET_MessageHeader *msg;
349 GNUNET_BLOCK_TYPE_DHT_HELLO); 345 const struct GNUNET_HELLO_Message *hello;
350 return GNUNET_NO; 346 struct GNUNET_PeerIdentity *pid;
347
348 if (block_size < sizeof(struct GNUNET_MessageHeader))
349 {
350 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
351 "block-dht",
352 _ ("Block not of type %u\n"),
353 GNUNET_BLOCK_TYPE_DHT_HELLO);
354 return GNUNET_NO;
355 }
356 msg = block;
357 if (block_size != ntohs (msg->size))
358 {
359 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
360 "block-dht",
361 _ ("Size mismatch for block with type %u\n"),
362 GNUNET_BLOCK_TYPE_DHT_HELLO);
363 return GNUNET_NO;
364 }
365 hello = block;
366 memset (key, 0, sizeof(*key));
367 pid = (struct GNUNET_PeerIdentity *) key;
368 if (GNUNET_OK != GNUNET_HELLO_get_id (hello, pid))
369 {
370 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
371 "block-dht",
372 _ ("Block of type %u is malformed\n"),
373 GNUNET_BLOCK_TYPE_DHT_HELLO);
374 return GNUNET_NO;
375 }
376 return GNUNET_OK;
377 }
378 default:
379 return GNUNET_SYSERR;
351 } 380 }
352 return GNUNET_OK;
353} 381}
354 382
355 383
@@ -361,6 +389,7 @@ libgnunet_plugin_block_dht_init (void *cls)
361{ 389{
362 static enum GNUNET_BLOCK_Type types[] = { 390 static enum GNUNET_BLOCK_Type types[] = {
363 GNUNET_BLOCK_TYPE_DHT_HELLO, 391 GNUNET_BLOCK_TYPE_DHT_HELLO,
392 // FIXME: add GNUNET_BLOCK_TYPE_DHT_URL_HELLO,
364 GNUNET_BLOCK_TYPE_ANY /* end of list */ 393 GNUNET_BLOCK_TYPE_ANY /* end of list */
365 }; 394 };
366 struct GNUNET_BLOCK_PluginFunctions *api; 395 struct GNUNET_BLOCK_PluginFunctions *api;