aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_validation.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-06-22 19:57:22 +0000
committerChristian Grothoff <christian@grothoff.org>2014-06-22 19:57:22 +0000
commit658f44879747d23c92e30ca004b04e2dddac73d8 (patch)
treec3e225cc738cc9588393c6de2b908b4f6e4b9f04 /src/transport/gnunet-service-transport_validation.c
parent58121840c21ad0a64d6e2b11dd01f50064ca1773 (diff)
downloadgnunet-658f44879747d23c92e30ca004b04e2dddac73d8.tar.gz
gnunet-658f44879747d23c92e30ca004b04e2dddac73d8.zip
-simplify logic a bit, doxygen, indentation
Diffstat (limited to 'src/transport/gnunet-service-transport_validation.c')
-rw-r--r--src/transport/gnunet-service-transport_validation.c102
1 files changed, 57 insertions, 45 deletions
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c
index 7c2675df3..6621ecc67 100644
--- a/src/transport/gnunet-service-transport_validation.c
+++ b/src/transport/gnunet-service-transport_validation.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2010-2013 Christian Grothoff (and other contributing authors) 3 (C) 2010-2014 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -24,6 +24,7 @@
24 * @author Christian Grothoff 24 * @author Christian Grothoff
25 */ 25 */
26#include "platform.h" 26#include "platform.h"
27#include "gnunet-service-transport_clients.h"
27#include "gnunet-service-transport_validation.h" 28#include "gnunet-service-transport_validation.h"
28#include "gnunet-service-transport_plugins.h" 29#include "gnunet-service-transport_plugins.h"
29#include "gnunet-service-transport_hello.h" 30#include "gnunet-service-transport_hello.h"
@@ -324,7 +325,6 @@ static struct GNUNET_CONTAINER_MultiPeerMap *validation_map;
324 */ 325 */
325static struct GNUNET_PEERINFO_NotifyContext *pnc; 326static struct GNUNET_PEERINFO_NotifyContext *pnc;
326 327
327
328/** 328/**
329 * Minimum delay between to validations 329 * Minimum delay between to validations
330 */ 330 */
@@ -345,8 +345,6 @@ static unsigned int validations_fast_start_threshold;
345 */ 345 */
346static struct GNUNET_TIME_Absolute validation_next; 346static struct GNUNET_TIME_Absolute validation_next;
347 347
348static GST_ValidationChangedCallback validation_entry_changed_cb;
349static void *validation_entry_changed_cb_cls;
350 348
351/** 349/**
352 * Context for the validation entry match function. 350 * Context for the validation entry match function.
@@ -369,14 +367,16 @@ struct ValidationEntryMatchContext
369/** 367/**
370 * Iterate over validation entries until a matching one is found. 368 * Iterate over validation entries until a matching one is found.
371 * 369 *
372 * @param cls the 'struct ValidationEntryMatchContext' 370 * @param cls the `struct ValidationEntryMatchContext *`
373 * @param key peer identity (unused) 371 * @param key peer identity (unused)
374 * @param value a 'struct ValidationEntry' to match 372 * @param value a `struct ValidationEntry *` to match
375 * @return GNUNET_YES if the entry does not match, 373 * @return #GNUNET_YES if the entry does not match,
376 * GNUNET_NO if the entry does match 374 * #GNUNET_NO if the entry does match
377 */ 375 */
378static int 376static int
379validation_entry_match (void *cls, const struct GNUNET_PeerIdentity * key, void *value) 377validation_entry_match (void *cls,
378 const struct GNUNET_PeerIdentity *key,
379 void *value)
380{ 380{
381 struct ValidationEntryMatchContext *vemc = cls; 381 struct ValidationEntryMatchContext *vemc = cls;
382 struct ValidationEntry *ve = value; 382 struct ValidationEntry *ve = value;
@@ -389,22 +389,25 @@ validation_entry_match (void *cls, const struct GNUNET_PeerIdentity * key, void
389 return GNUNET_YES; 389 return GNUNET_YES;
390} 390}
391 391
392
393/**
394 * A validation entry changed. Update the state and notify
395 * monitors.
396 *
397 * @param ve validation entry that changed
398 * @param state new state
399 */
392static void 400static void
393validation_entry_changed (struct ValidationEntry *ve, enum GNUNET_TRANSPORT_ValidationState state) 401validation_entry_changed (struct ValidationEntry *ve,
402 enum GNUNET_TRANSPORT_ValidationState state)
394{ 403{
395 char *t_sent = GNUNET_strdup(GNUNET_STRINGS_absolute_time_to_string(ve->send_time));
396 char *t_valid = GNUNET_strdup(GNUNET_STRINGS_absolute_time_to_string(ve->valid_until));
397 char *t_next = GNUNET_strdup(GNUNET_STRINGS_absolute_time_to_string(ve->next_validation));
398 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Validation entry changed for peer `%s' address `%s':\n\tSent: %s\n\tValid: %s\n\tNext: %s\n",
399 GNUNET_i2s(&ve->pid), GST_plugins_a2s(ve->address),
400 t_sent, t_valid, t_next);
401 ve->state = state; 404 ve->state = state;
402 405 GST_clients_broadcast_validation_notification (&ve->pid,
403 GNUNET_free (t_sent); 406 ve->address,
404 GNUNET_free (t_valid); 407 ve->send_time,
405 GNUNET_free (t_next); 408 ve->valid_until,
406 validation_entry_changed_cb (validation_entry_changed_cb_cls, &ve->pid, 409 ve->next_validation,
407 ve->address, ve->send_time, ve->valid_until, ve->next_validation, state); 410 state);
408} 411}
409 412
410 413
@@ -413,11 +416,13 @@ validation_entry_changed (struct ValidationEntry *ve, enum GNUNET_TRANSPORT_Vali
413 * 416 *
414 * @param cls (unused) 417 * @param cls (unused)
415 * @param key peer identity (unused) 418 * @param key peer identity (unused)
416 * @param value a 'struct ValidationEntry' to clean up 419 * @param value a `struct ValidationEntry *` to clean up
417 * @return GNUNET_YES (continue to iterate) 420 * @return #GNUNET_YES (continue to iterate)
418 */ 421 */
419static int 422static int
420cleanup_validation_entry (void *cls, const struct GNUNET_PeerIdentity * key, void *value) 423cleanup_validation_entry (void *cls,
424 const struct GNUNET_PeerIdentity *key,
425 void *value)
421{ 426{
422 struct ValidationEntry *ve = value; 427 struct ValidationEntry *ve = value;
423 428
@@ -579,8 +584,8 @@ transmit_ping_if_allowed (void *cls,
579 ret = -1; 584 ret = -1;
580 else 585 else
581 { 586 {
582 GNUNET_assert (papi->send != NULL); 587 GNUNET_assert (NULL != papi->send);
583 GNUNET_assert (papi->get_session != NULL); 588 GNUNET_assert (NULL != papi->get_session);
584 struct Session * session = papi->get_session(papi->cls, ve->address); 589 struct Session * session = papi->get_session(papi->cls, ve->address);
585 590
586 if (session != NULL) 591 if (session != NULL)
@@ -863,12 +868,10 @@ process_peerinfo_hello (void *cls, const struct GNUNET_PeerIdentity *peer,
863/** 868/**
864 * Start the validation subsystem. 869 * Start the validation subsystem.
865 * 870 *
866 * @param cb callback to call with changes to valdidation entries
867 * @param cb_cls cls for the callback
868 * @param max_fds maximum number of fds to use 871 * @param max_fds maximum number of fds to use
869 */ 872 */
870void 873void
871GST_validation_start (GST_ValidationChangedCallback cb, void *cb_cls, unsigned int max_fds) 874GST_validation_start (unsigned int max_fds)
872{ 875{
873 /** 876 /**
874 * Initialization for validation throttling 877 * Initialization for validation throttling
@@ -886,9 +889,8 @@ GST_validation_start (GST_ValidationChangedCallback cb, void *cb_cls, unsigned i
886 validation_delay.rel_value_us = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2); 889 validation_delay.rel_value_us = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2);
887 validations_fast_start_threshold = (max_fds / 2); 890 validations_fast_start_threshold = (max_fds / 2);
888 validations_running = 0; 891 validations_running = 0;
889 validation_entry_changed_cb = cb; 892 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
890 validation_entry_changed_cb_cls = cb_cls; 893 "Validation uses a fast start threshold of %u connections and a delay between of %s\n ",
891 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Validation uses a fast start threshold of %u connections and a delay between of %s\n ",
892 validations_fast_start_threshold, 894 validations_fast_start_threshold,
893 GNUNET_STRINGS_relative_time_to_string (validation_delay, 895 GNUNET_STRINGS_relative_time_to_string (validation_delay,
894 GNUNET_YES)); 896 GNUNET_YES));
@@ -1243,7 +1245,7 @@ struct ValidateAddressContext
1243 * Iterator callback to go over all addresses and try to validate them 1245 * Iterator callback to go over all addresses and try to validate them
1244 * (unless blocked or already validated). 1246 * (unless blocked or already validated).
1245 * 1247 *
1246 * @param cls pointer to a `struct ValidateAddressContext` 1248 * @param cls pointer to a `struct ValidateAddressContext *`
1247 * @param address the address 1249 * @param address the address
1248 * @param expiration expiration time 1250 * @param expiration expiration time
1249 * @return #GNUNET_OK (keep the address) 1251 * @return #GNUNET_OK (keep the address)
@@ -1277,14 +1279,16 @@ validate_address_iterator (void *cls,
1277/** 1279/**
1278 * Add the validated peer address to the HELLO. 1280 * Add the validated peer address to the HELLO.
1279 * 1281 *
1280 * @param cls the 'struct ValidationEntry' with the validated address 1282 * @param cls the `struct ValidationEntry *` with the validated address
1281 * @param max space in buf 1283 * @param max space in @a buf
1282 * @param buf where to add the address 1284 * @param buf where to add the address
1283 * @return number of bytes written, GNUNET_SYSERR to signal the 1285 * @return number of bytes written, #GNUNET_SYSERR to signal the
1284 * end of the iteration. 1286 * end of the iteration.
1285 */ 1287 */
1286static ssize_t 1288static ssize_t
1287add_valid_peer_address (void *cls, size_t max, void *buf) 1289add_valid_peer_address (void *cls,
1290 size_t max,
1291 void *buf)
1288{ 1292{
1289 struct ValidationEntry *ve = cls; 1293 struct ValidationEntry *ve = cls;
1290 1294
@@ -1375,7 +1379,7 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1375 1379
1376 sig_res = GNUNET_SYSERR; 1380 sig_res = GNUNET_SYSERR;
1377 do_verify = GNUNET_YES; 1381 do_verify = GNUNET_YES;
1378 if (0 != GNUNET_TIME_absolute_get_remaining(ve->pong_sig_valid_until).rel_value_us) 1382 if (0 != GNUNET_TIME_absolute_get_remaining (ve->pong_sig_valid_until).rel_value_us)
1379 { 1383 {
1380 /* We have a cached and valid signature for this peer, 1384 /* We have a cached and valid signature for this peer,
1381 * try to compare instead of verify */ 1385 * try to compare instead of verify */
@@ -1416,7 +1420,9 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1416 1420
1417 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1421 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1418 "Validation process successful for peer `%s' with plugin `%s' address `%s'\n", 1422 "Validation process successful for peer `%s' with plugin `%s' address `%s'\n",
1419 GNUNET_i2s (sender), tname, GST_plugins_a2s (ve->address)); 1423 GNUNET_i2s (sender),
1424 tname,
1425 GST_plugins_a2s (ve->address));
1420 /* validity achieved, remember it! */ 1426 /* validity achieved, remember it! */
1421 ve->expecting_pong = GNUNET_NO; 1427 ve->expecting_pong = GNUNET_NO;
1422 ve->valid_until = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION); 1428 ve->valid_until = GNUNET_TIME_relative_to_absolute (HELLO_ADDRESS_EXPIRATION);
@@ -1536,7 +1542,9 @@ struct IteratorContext
1536 * @return #GNUNET_OK (continue to iterate) 1542 * @return #GNUNET_OK (continue to iterate)
1537 */ 1543 */
1538static int 1544static int
1539iterate_addresses (void *cls, const struct GNUNET_PeerIdentity *key, void *value) 1545iterate_addresses (void *cls,
1546 const struct GNUNET_PeerIdentity *key,
1547 void *value)
1540{ 1548{
1541 struct IteratorContext *ic = cls; 1549 struct IteratorContext *ic = cls;
1542 struct ValidationEntry *ve = value; 1550 struct ValidationEntry *ve = value;
@@ -1553,7 +1561,7 @@ iterate_addresses (void *cls, const struct GNUNET_PeerIdentity *key, void *value
1553 * 1561 *
1554 * @param target peer information is requested for 1562 * @param target peer information is requested for
1555 * @param cb function to call; will not be called after this function returns 1563 * @param cb function to call; will not be called after this function returns
1556 * @param cb_cls closure for 'cb' 1564 * @param cb_cls closure for @a cb
1557 */ 1565 */
1558void 1566void
1559GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target, 1567GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target,
@@ -1662,11 +1670,12 @@ struct ValidationIteratorContext
1662 GST_ValidationChangedCallback cb; 1670 GST_ValidationChangedCallback cb;
1663 1671
1664 /** 1672 /**
1665 * Closure for 'cb'. 1673 * Closure for @e cb.
1666 */ 1674 */
1667 void *cb_cls; 1675 void *cb_cls;
1668}; 1676};
1669 1677
1678
1670static int 1679static int
1671validation_entries_iterate (void *cls, 1680validation_entries_iterate (void *cls,
1672 const struct GNUNET_PeerIdentity *key, 1681 const struct GNUNET_PeerIdentity *key,
@@ -1690,7 +1699,8 @@ validation_entries_iterate (void *cls,
1690 * @param cb_cls closure for cb 1699 * @param cb_cls closure for cb
1691 */ 1700 */
1692void 1701void
1693GST_validation_iterate (GST_ValidationChangedCallback cb, void *cb_cls) 1702GST_validation_iterate (GST_ValidationChangedCallback cb,
1703 void *cb_cls)
1694{ 1704{
1695 struct ValidationIteratorContext ic; 1705 struct ValidationIteratorContext ic;
1696 1706
@@ -1698,7 +1708,9 @@ GST_validation_iterate (GST_ValidationChangedCallback cb, void *cb_cls)
1698 return; /* can happen during shutdown */ 1708 return; /* can happen during shutdown */
1699 ic.cb = cb; 1709 ic.cb = cb;
1700 ic.cb_cls = cb_cls; 1710 ic.cb_cls = cb_cls;
1701 GNUNET_CONTAINER_multipeermap_iterate (validation_map, &validation_entries_iterate, &ic); 1711 GNUNET_CONTAINER_multipeermap_iterate (validation_map,
1712 &validation_entries_iterate,
1713 &ic);
1702} 1714}
1703 1715
1704/* end of file gnunet-service-transport_validation.c */ 1716/* end of file gnunet-service-transport_validation.c */