aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_validation.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-07 13:09:39 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-07 13:09:39 +0000
commit63760db5bbd9c8b5cc2552b9705141f0d696b5d1 (patch)
tree1bf33f6ac7e77ef0b289fbd552a0722be37913ec /src/transport/gnunet-service-transport_validation.c
parent50ada5687201159d94ff49c6961df8ffe527f6bc (diff)
downloadgnunet-63760db5bbd9c8b5cc2552b9705141f0d696b5d1.tar.gz
gnunet-63760db5bbd9c8b5cc2552b9705141f0d696b5d1.zip
peerinfo get missing from validation, fixing
Diffstat (limited to 'src/transport/gnunet-service-transport_validation.c')
-rw-r--r--src/transport/gnunet-service-transport_validation.c253
1 files changed, 161 insertions, 92 deletions
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c
index d7e466523..c06725c58 100644
--- a/src/transport/gnunet-service-transport_validation.c
+++ b/src/transport/gnunet-service-transport_validation.c
@@ -244,11 +244,6 @@ struct CheckHelloValidatedContext
244 */ 244 */
245 const struct GNUNET_HELLO_Message *hello; 245 const struct GNUNET_HELLO_Message *hello;
246 246
247 /**
248 * Context for peerinfo iteration.
249 */
250 struct GNUNET_PEERINFO_IteratorContext *piter;
251
252}; 247};
253 248
254 249
@@ -274,95 +269,10 @@ static struct GNUNET_CONTAINER_MultiHashMap *validation_map;
274 */ 269 */
275static struct GNUNET_CONTAINER_MultiHashMap *notify_map; 270static struct GNUNET_CONTAINER_MultiHashMap *notify_map;
276 271
277
278/**
279 * Start the validation subsystem.
280 */
281void
282GST_validation_start ()
283{
284 validation_map = GNUNET_CONTAINER_multihashmap_create (VALIDATION_MAP_SIZE);
285 notify_map = GNUNET_CONTAINER_multihashmap_create (VALIDATION_MAP_SIZE);
286}
287
288
289/**
290 * Iterate over validation entries and free them.
291 *
292 * @param cls (unused)
293 * @param key peer identity (unused)
294 * @param value a 'struct ValidationEntry' to clean up
295 * @return GNUNET_YES (continue to iterate)
296 */
297static int
298cleanup_validation_entry (void *cls,
299 const GNUNET_HashCode *key,
300 void *value)
301{
302 struct ValidationEntry *ve = value;
303
304 GNUNET_free (ve->transport_name);
305 if (GNUNET_SCHEDULER_NO_TASK != ve->timeout_task)
306 {
307 GNUNET_SCHEDULER_cancel (ve->timeout_task);
308 ve->timeout_task = GNUNET_SCHEDULER_NO_TASK;
309 }
310 GNUNET_free (ve);
311 return GNUNET_OK;
312}
313
314
315/**
316 * Stop the validation subsystem.
317 */
318void
319GST_validation_stop ()
320{
321 struct CheckHelloValidatedContext *chvc;
322
323 GNUNET_CONTAINER_multihashmap_iterate (validation_map,
324 &cleanup_validation_entry,
325 NULL);
326 GNUNET_CONTAINER_multihashmap_destroy (validation_map);
327 validation_map = NULL;
328 GNUNET_assert (GNUNET_CONTAINER_multihashmap_size (notify_map) == 0);
329 GNUNET_CONTAINER_multihashmap_destroy (notify_map);
330 notify_map = NULL;
331 while (NULL != (chvc = chvc_head))
332 {
333 GNUNET_CONTAINER_DLL_remove (chvc_head,
334 chvc_tail,
335 chvc);
336 GNUNET_PEERINFO_iterate_cancel (chvc->piter);
337 GNUNET_free (chvc);
338 }
339}
340
341
342/** 272/**
343 * Address validation cleanup task (record no longer needed). 273 * Context for peerinfo iteration.
344 *
345 * @param cls the 'struct ValidationEntry'
346 * @param tc scheduler context (unused)
347 */ 274 */
348static void 275static struct GNUNET_PEERINFO_NotifyContext *pnc;
349timeout_hello_validation (void *cls,
350 const struct GNUNET_SCHEDULER_TaskContext *tc)
351{
352 struct ValidationEntry *va = cls;
353
354 va->timeout_task = GNUNET_SCHEDULER_NO_TASK;
355 GNUNET_STATISTICS_update (GST_stats,
356 gettext_noop ("# address records discarded"),
357 1,
358 GNUNET_NO);
359 GNUNET_break (GNUNET_OK ==
360 GNUNET_CONTAINER_multihashmap_remove (validation_map,
361 &va->pid.hashPubKey,
362 va));
363 GNUNET_free (va->transport_name);
364 GNUNET_free (va);
365}
366 276
367 277
368/** 278/**
@@ -476,6 +386,165 @@ find_validation_entry (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pub
476 386
477 387
478/** 388/**
389 * Iterator which adds the given address to the set of validated
390 * addresses.
391 *
392 * @param cls original HELLO message
393 * @param tname name of the transport
394 * @param expiration expiration time
395 * @param addr the address
396 * @param addrlen length of the address
397 * @return GNUNET_OK (keep the address)
398 */
399static int
400add_valid_address (void *cls,
401 const char *tname,
402 struct GNUNET_TIME_Absolute expiration,
403 const void *addr,
404 uint16_t addrlen)
405{
406 const struct GNUNET_HELLO_Message *hello = cls;
407 struct ValidationEntry *ve;
408 struct GNUNET_PeerIdentity pid;
409 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded public_key;
410
411 if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0)
412 return GNUNET_OK; /* expired */
413 if ( (GNUNET_OK !=
414 GNUNET_HELLO_get_id (hello, &pid)) ||
415 (GNUNET_OK !=
416 GNUNET_HELLO_get_key (hello, &public_key)) )
417 {
418 GNUNET_break (0);
419 return GNUNET_OK; /* invalid HELLO !? */
420 }
421
422 ve = find_validation_entry (&public_key, &pid, tname, addr, addrlen);
423 ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until,
424 expiration);
425 return GNUNET_OK;
426}
427
428
429/**
430 * Function called for any HELLO known to PEERINFO.
431 *
432 * @param cls unused
433 * @param peer id of the peer, NULL for last call
434 * @param hello hello message for the peer (can be NULL)
435 * @param error message
436 */
437static void
438process_peerinfo_hello (void *cls,
439 const struct GNUNET_PeerIdentity *peer,
440 const struct GNUNET_HELLO_Message *hello,
441 const char *err_msg)
442{
443 GNUNET_assert (NULL != peer);
444 if (NULL == hello)
445 return;
446 GNUNET_assert (NULL ==
447 GNUNET_HELLO_iterate_addresses (hello,
448 GNUNET_NO,
449 &add_valid_address,
450 (void*) hello));
451}
452
453
454/**
455 * Start the validation subsystem.
456 */
457void
458GST_validation_start ()
459{
460 validation_map = GNUNET_CONTAINER_multihashmap_create (VALIDATION_MAP_SIZE);
461 notify_map = GNUNET_CONTAINER_multihashmap_create (VALIDATION_MAP_SIZE);
462 pnc = GNUNET_PEERINFO_notify (GST_cfg,
463 &process_peerinfo_hello,
464 NULL);
465}
466
467
468/**
469 * Iterate over validation entries and free them.
470 *
471 * @param cls (unused)
472 * @param key peer identity (unused)
473 * @param value a 'struct ValidationEntry' to clean up
474 * @return GNUNET_YES (continue to iterate)
475 */
476static int
477cleanup_validation_entry (void *cls,
478 const GNUNET_HashCode *key,
479 void *value)
480{
481 struct ValidationEntry *ve = value;
482
483 GNUNET_free (ve->transport_name);
484 if (GNUNET_SCHEDULER_NO_TASK != ve->timeout_task)
485 {
486 GNUNET_SCHEDULER_cancel (ve->timeout_task);
487 ve->timeout_task = GNUNET_SCHEDULER_NO_TASK;
488 }
489 GNUNET_free (ve);
490 return GNUNET_OK;
491}
492
493
494/**
495 * Stop the validation subsystem.
496 */
497void
498GST_validation_stop ()
499{
500 struct CheckHelloValidatedContext *chvc;
501
502 GNUNET_CONTAINER_multihashmap_iterate (validation_map,
503 &cleanup_validation_entry,
504 NULL);
505 GNUNET_CONTAINER_multihashmap_destroy (validation_map);
506 validation_map = NULL;
507 GNUNET_assert (GNUNET_CONTAINER_multihashmap_size (notify_map) == 0);
508 GNUNET_CONTAINER_multihashmap_destroy (notify_map);
509 notify_map = NULL;
510 while (NULL != (chvc = chvc_head))
511 {
512 GNUNET_CONTAINER_DLL_remove (chvc_head,
513 chvc_tail,
514 chvc);
515 GNUNET_free (chvc);
516 }
517 GNUNET_PEERINFO_notify_cancel (pnc);
518}
519
520
521/**
522 * Address validation cleanup task (record no longer needed).
523 *
524 * @param cls the 'struct ValidationEntry'
525 * @param tc scheduler context (unused)
526 */
527static void
528timeout_hello_validation (void *cls,
529 const struct GNUNET_SCHEDULER_TaskContext *tc)
530{
531 struct ValidationEntry *va = cls;
532
533 va->timeout_task = GNUNET_SCHEDULER_NO_TASK;
534 GNUNET_STATISTICS_update (GST_stats,
535 gettext_noop ("# address records discarded"),
536 1,
537 GNUNET_NO);
538 GNUNET_break (GNUNET_OK ==
539 GNUNET_CONTAINER_multihashmap_remove (validation_map,
540 &va->pid.hashPubKey,
541 va));
542 GNUNET_free (va->transport_name);
543 GNUNET_free (va);
544}
545
546
547/**
479 * Send the given PONG to the given address. 548 * Send the given PONG to the given address.
480 * 549 *
481 * @param cls the PONG message 550 * @param cls the PONG message