aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_validation.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2013-12-11 19:59:19 +0000
committerChristian Grothoff <christian@grothoff.org>2013-12-11 19:59:19 +0000
commitf2c269445edae0699527161c3dbd03e8888d1866 (patch)
tree8dfe56c699e8ec573f06ce8ed4f97adaaaa66f38 /src/transport/gnunet-service-transport_validation.c
parenta97077af00635389f9c8b4f4d8e5b9464b950d91 (diff)
downloadgnunet-f2c269445edae0699527161c3dbd03e8888d1866.tar.gz
gnunet-f2c269445edae0699527161c3dbd03e8888d1866.zip
-indentation, doxygen, logging
Diffstat (limited to 'src/transport/gnunet-service-transport_validation.c')
-rw-r--r--src/transport/gnunet-service-transport_validation.c179
1 files changed, 113 insertions, 66 deletions
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c
index f91ad8ae1..afe7ac467 100644
--- a/src/transport/gnunet-service-transport_validation.c
+++ b/src/transport/gnunet-service-transport_validation.c
@@ -465,10 +465,11 @@ timeout_hello_validation (void *cls,
465 * 465 *
466 * @param cls our 'struct ValidationEntry' 466 * @param cls our 'struct ValidationEntry'
467 * @param pid identity of the other peer 467 * @param pid identity of the other peer
468 * @param result GNUNET_OK if the connection is allowed, GNUNET_NO if not 468 * @param result #GNUNET_OK if the connection is allowed, #GNUNET_NO if not
469 */ 469 */
470static void 470static void
471transmit_ping_if_allowed (void *cls, const struct GNUNET_PeerIdentity *pid, 471transmit_ping_if_allowed (void *cls,
472 const struct GNUNET_PeerIdentity *pid,
472 int result) 473 int result)
473{ 474{
474 struct ValidationEntry *ve = cls; 475 struct ValidationEntry *ve = cls;
@@ -483,20 +484,26 @@ transmit_ping_if_allowed (void *cls, const struct GNUNET_PeerIdentity *pid,
483 uint16_t hsize; 484 uint16_t hsize;
484 485
485 ve->bc = NULL; 486 ve->bc = NULL;
486
487 if (GNUNET_NO == result) 487 if (GNUNET_NO == result)
488 { 488 {
489 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Blacklist denies to send PING to `%s' %s %s\n", 489 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
490 GNUNET_i2s (pid), GST_plugins_a2s (ve->address), ve->address->transport_name); 490 "Blacklist denies to send PING to `%s' %s %s\n",
491 return; 491 GNUNET_i2s (pid),
492 GST_plugins_a2s (ve->address),
493 ve->address->transport_name);
494 return;
492 } 495 }
493 496
494 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting plain PING to `%s' %s %s\n", 497 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
495 GNUNET_i2s (pid), GST_plugins_a2s (ve->address), ve->address->transport_name); 498 "Transmitting plain PING to `%s' %s %s\n",
499 GNUNET_i2s (pid),
500 GST_plugins_a2s (ve->address),
501 ve->address->transport_name);
496 502
497 next = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(), validation_delay); 503 next = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get(),
504 validation_delay);
498 if (next.abs_value_us > validation_next.abs_value_us) 505 if (next.abs_value_us > validation_next.abs_value_us)
499 validation_next = next; /* We're going to send a PING so delay next validation */ 506 validation_next = next; /* We're going to send a PING so delay next validation */
500 507
501 slen = strlen (ve->address->transport_name) + 1; 508 slen = strlen (ve->address->transport_name) + 1;
502 hello = GST_hello_get (); 509 hello = GST_hello_get ();
@@ -594,7 +601,8 @@ transmit_ping_if_allowed (void *cls, const struct GNUNET_PeerIdentity *pid,
594 * @param tc scheduler context (unused) 601 * @param tc scheduler context (unused)
595 */ 602 */
596static void 603static void
597revalidate_address (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 604revalidate_address (void *cls,
605 const struct GNUNET_SCHEDULER_TaskContext *tc)
598{ 606{
599 struct ValidationEntry *ve = cls; 607 struct ValidationEntry *ve = cls;
600 struct GNUNET_TIME_Relative canonical_delay; 608 struct GNUNET_TIME_Relative canonical_delay;
@@ -620,6 +628,11 @@ revalidate_address (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
620 if (delay.rel_value_us > 0) 628 if (delay.rel_value_us > 0)
621 { 629 {
622 /* should wait a bit longer */ 630 /* should wait a bit longer */
631 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
632 "Waiting for %s longer before validating address %s\n",
633 GNUNET_STRINGS_relative_time_to_string (delay,
634 GNUNET_YES),
635 GST_plugins_a2s (ve->address));
623 ve->revalidation_task = 636 ve->revalidation_task =
624 GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve); 637 GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve);
625 return; 638 return;
@@ -629,6 +642,11 @@ revalidate_address (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
629 (blocked_for.rel_value_us > 0)) 642 (blocked_for.rel_value_us > 0))
630 { 643 {
631 /* Validations are blocked, have to wait for blocked_for time */ 644 /* Validations are blocked, have to wait for blocked_for time */
645 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
646 "Validations blocked for another %s, delaying validating address %s\n",
647 GNUNET_STRINGS_relative_time_to_string (blocked_for,
648 GNUNET_YES),
649 GST_plugins_a2s (ve->address));
632 ve->revalidation_task = 650 ve->revalidation_task =
633 GNUNET_SCHEDULER_add_delayed (blocked_for, &revalidate_address, ve); 651 GNUNET_SCHEDULER_add_delayed (blocked_for, &revalidate_address, ve);
634 return; 652 return;
@@ -654,6 +672,11 @@ revalidate_address (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
654 (GNUNET_TIME_UNIT_MICROSECONDS, rdelay)); 672 (GNUNET_TIME_UNIT_MICROSECONDS, rdelay));
655 } 673 }
656 /* End debug code for mantis 0002726*/ 674 /* End debug code for mantis 0002726*/
675 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
676 "Validating now, next scheduled for %s, now validating address %s\n",
677 GNUNET_STRINGS_relative_time_to_string (blocked_for,
678 GNUNET_YES),
679 GST_plugins_a2s (ve->address));
657 ve->revalidation_task = 680 ve->revalidation_task =
658 GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve); 681 GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve);
659 682
@@ -725,10 +748,11 @@ find_validation_entry (const struct GNUNET_CRYPTO_EddsaPublicKey *public_key,
725 * @param cls original HELLO message 748 * @param cls original HELLO message
726 * @param address the address 749 * @param address the address
727 * @param expiration expiration time 750 * @param expiration expiration time
728 * @return GNUNET_OK (keep the address) 751 * @return #GNUNET_OK (keep the address)
729 */ 752 */
730static int 753static int
731add_valid_address (void *cls, const struct GNUNET_HELLO_Address *address, 754add_valid_address (void *cls,
755 const struct GNUNET_HELLO_Address *address,
732 struct GNUNET_TIME_Absolute expiration) 756 struct GNUNET_TIME_Absolute expiration)
733{ 757{
734 const struct GNUNET_HELLO_Message *hello = cls; 758 const struct GNUNET_HELLO_Message *hello = cls;
@@ -745,7 +769,9 @@ add_valid_address (void *cls, const struct GNUNET_HELLO_Address *address,
745 GNUNET_break (0); 769 GNUNET_break (0);
746 return GNUNET_OK; /* invalid HELLO !? */ 770 return GNUNET_OK; /* invalid HELLO !? */
747 } 771 }
748 if (0 == memcmp (&GST_my_identity, &pid, sizeof (struct GNUNET_PeerIdentity))) 772 if (0 == memcmp (&GST_my_identity,
773 &pid,
774 sizeof (struct GNUNET_PeerIdentity)))
749 { 775 {
750 /* Peerinfo returned own identity, skip validation */ 776 /* Peerinfo returned own identity, skip validation */
751 return GNUNET_OK; 777 return GNUNET_OK;
@@ -755,7 +781,12 @@ add_valid_address (void *cls, const struct GNUNET_HELLO_Address *address,
755 ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, expiration); 781 ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, expiration);
756 782
757 if (GNUNET_SCHEDULER_NO_TASK == ve->revalidation_task) 783 if (GNUNET_SCHEDULER_NO_TASK == ve->revalidation_task)
784 {
785 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
786 "Starting revalidations for valid address %s\n",
787 GST_plugins_a2s (ve->address));
758 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve); 788 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve);
789 }
759 790
760 ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); 791 ats.type = htonl (GNUNET_ATS_NETWORK_TYPE);
761 ats.value = htonl (ve->network); 792 ats.value = htonl (ve->network);
@@ -781,6 +812,9 @@ process_peerinfo_hello (void *cls, const struct GNUNET_PeerIdentity *peer,
781 GNUNET_assert (NULL != peer); 812 GNUNET_assert (NULL != peer);
782 if (NULL == hello) 813 if (NULL == hello)
783 return; 814 return;
815 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
816 "Handling HELLO for peer %s\n",
817 GNUNET_i2s (peer));
784 GNUNET_assert (NULL == 818 GNUNET_assert (NULL ==
785 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, 819 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO,
786 &add_valid_address, 820 &add_valid_address,
@@ -796,29 +830,30 @@ process_peerinfo_hello (void *cls, const struct GNUNET_PeerIdentity *peer,
796void 830void
797GST_validation_start (unsigned int max_fds) 831GST_validation_start (unsigned int max_fds)
798{ 832{
799 /** 833 /**
800 * Initialization for validation throttling 834 * Initialization for validation throttling
801 * 835 *
802 * We have a maximum number max_fds of connections we can use for validation 836 * We have a maximum number max_fds of connections we can use for validation
803 * We monitor the number of validations in parallel and start to throttle it 837 * We monitor the number of validations in parallel and start to throttle it
804 * when doing to many validations in parallel: 838 * when doing to many validations in parallel:
805 * if (running validations < (max_fds / 2)) 839 * if (running validations < (max_fds / 2))
806 * - "fast start": run validation immediately 840 * - "fast start": run validation immediately
807 * - have delay of (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2) 841 * - have delay of (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2)
808 * (300 sec / ~150 == ~2 sec.) between two validations 842 * (300 sec / ~150 == ~2 sec.) between two validations
809 */ 843 */
810 844
811 validation_next = GNUNET_TIME_absolute_get(); 845 validation_next = GNUNET_TIME_absolute_get();
812 validation_delay.rel_value_us = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2); 846 validation_delay.rel_value_us = (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT.rel_value_us) / (max_fds / 2);
813 validations_fast_start_threshold = (max_fds / 2); 847 validations_fast_start_threshold = (max_fds / 2);
814 validations_running = 0; 848 validations_running = 0;
815 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Validation uses a fast start threshold of %u connections and a delay between of %s\n ", 849 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Validation uses a fast start threshold of %u connections and a delay between of %s\n ",
816 validations_fast_start_threshold, 850 validations_fast_start_threshold,
817 GNUNET_STRINGS_relative_time_to_string (validation_delay, 851 GNUNET_STRINGS_relative_time_to_string (validation_delay,
818 GNUNET_YES)); 852 GNUNET_YES));
819 validation_map = GNUNET_CONTAINER_multipeermap_create (VALIDATION_MAP_SIZE, 853 validation_map = GNUNET_CONTAINER_multipeermap_create (VALIDATION_MAP_SIZE,
820 GNUNET_NO); 854 GNUNET_NO);
821 pnc = GNUNET_PEERINFO_notify (GST_cfg, GNUNET_YES, &process_peerinfo_hello, NULL); 855 pnc = GNUNET_PEERINFO_notify (GST_cfg, GNUNET_YES,
856 &process_peerinfo_hello, NULL);
822} 857}
823 858
824 859
@@ -1001,8 +1036,9 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
1001 gettext_noop 1036 gettext_noop
1002 ("# successful address checks during validation"), 1, 1037 ("# successful address checks during validation"), 1,
1003 GNUNET_NO); 1038 GNUNET_NO);
1004 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Address `%s' is one of my addresses, confirming PING\n", 1039 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1005 GST_plugins_a2s (&address)); 1040 "Address `%s' is one of my addresses, confirming PING\n",
1041 GST_plugins_a2s (&address));
1006 } 1042 }
1007 1043
1008 if (GNUNET_YES != GST_hello_test_address (&address, &sig_cache, &sig_cache_exp)) 1044 if (GNUNET_YES != GST_hello_test_address (&address, &sig_cache, &sig_cache_exp))
@@ -1161,7 +1197,7 @@ struct ValidateAddressContext
1161 * @param cls pointer to a 'struct ValidateAddressContext' 1197 * @param cls pointer to a 'struct ValidateAddressContext'
1162 * @param address the address 1198 * @param address the address
1163 * @param expiration expiration time 1199 * @param expiration expiration time
1164 * @return GNUNET_OK (keep the address) 1200 * @return #GNUNET_OK (keep the address)
1165 */ 1201 */
1166static int 1202static int
1167validate_address_iterator (void *cls, 1203validate_address_iterator (void *cls,
@@ -1172,10 +1208,19 @@ validate_address_iterator (void *cls,
1172 struct ValidationEntry *ve; 1208 struct ValidationEntry *ve;
1173 1209
1174 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us) 1210 if (0 == GNUNET_TIME_absolute_get_remaining (expiration).rel_value_us)
1211 {
1212 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1213 "Skipping expired address from HELLO\n");
1175 return GNUNET_OK; /* expired */ 1214 return GNUNET_OK; /* expired */
1215 }
1176 ve = find_validation_entry (&vac->public_key, address); 1216 ve = find_validation_entry (&vac->public_key, address);
1177 if (GNUNET_SCHEDULER_NO_TASK == ve->revalidation_task) 1217 if (GNUNET_SCHEDULER_NO_TASK == ve->revalidation_task)
1218 {
1219 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1220 "Starting validation for fresh address %s\n",
1221 GST_plugins_a2s (ve->address));
1178 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve); 1222 ve->revalidation_task = GNUNET_SCHEDULER_add_now (&revalidate_address, ve);
1223 }
1179 return GNUNET_OK; 1224 return GNUNET_OK;
1180} 1225}
1181 1226
@@ -1281,31 +1326,31 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1281 do_verify = GNUNET_YES; 1326 do_verify = GNUNET_YES;
1282 if (0 != GNUNET_TIME_absolute_get_remaining(ve->pong_sig_valid_until).rel_value_us) 1327 if (0 != GNUNET_TIME_absolute_get_remaining(ve->pong_sig_valid_until).rel_value_us)
1283 { 1328 {
1284 /* We have a cached and valid signature for this peer, 1329 /* We have a cached and valid signature for this peer,
1285 * try to compare instead of verify */ 1330 * try to compare instead of verify */
1286 if (0 == memcmp (&ve->pong_sig_cache, &pong->signature, sizeof (struct GNUNET_CRYPTO_EddsaSignature))) 1331 if (0 == memcmp (&ve->pong_sig_cache, &pong->signature, sizeof (struct GNUNET_CRYPTO_EddsaSignature)))
1287 { 1332 {
1288 /* signatures are identical, we can skip verification */ 1333 /* signatures are identical, we can skip verification */
1289 sig_res = GNUNET_OK; 1334 sig_res = GNUNET_OK;
1290 do_verify = GNUNET_NO; 1335 do_verify = GNUNET_NO;
1291 } 1336 }
1292 else 1337 else
1293 { 1338 {
1294 sig_res = GNUNET_SYSERR; 1339 sig_res = GNUNET_SYSERR;
1295 /* signatures do not match, we have to verify */ 1340 /* signatures do not match, we have to verify */
1296 } 1341 }
1297 } 1342 }
1298 1343
1299 if (GNUNET_YES == do_verify) 1344 if (GNUNET_YES == do_verify)
1300 { 1345 {
1301 /* Do expensive verification */ 1346 /* Do expensive verification */
1302 sig_res = GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, 1347 sig_res = GNUNET_CRYPTO_eddsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
1303 &pong->purpose, &pong->signature, 1348 &pong->purpose, &pong->signature,
1304 &ve->public_key); 1349 &ve->public_key);
1305 if (sig_res == GNUNET_SYSERR) 1350 if (sig_res == GNUNET_SYSERR)
1306 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1351 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1307 "Failed to verify: invalid signature on address %s:%s from peer `%s'\n", 1352 "Failed to verify: invalid signature on address %s:%s from peer `%s'\n",
1308 tname, GST_plugins_a2s (ve->address),GNUNET_i2s (sender)); 1353 tname, GST_plugins_a2s (ve->address),GNUNET_i2s (sender));
1309 } 1354 }
1310 1355
1311 if (sig_res == GNUNET_SYSERR) 1356 if (sig_res == GNUNET_SYSERR)
@@ -1330,17 +1375,19 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
1330 } 1375 }
1331 if (validations_running > 0) 1376 if (validations_running > 0)
1332 { 1377 {
1333 validations_running --; 1378 validations_running --;
1334 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1379 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1335 "Validation finished, %u validation processes running\n", 1380 "Validation finished, %u validation processes running\n",
1336 validations_running); 1381 validations_running);
1337 } 1382 }
1338 else 1383 else
1339 GNUNET_break (0); 1384 GNUNET_break (0);
1340 1385
1341 /* build HELLO to store in PEERINFO */ 1386 /* build HELLO to store in PEERINFO */
1342 ve->copied = GNUNET_NO; 1387 ve->copied = GNUNET_NO;
1343 hello = GNUNET_HELLO_create (&ve->public_key, &add_valid_peer_address, ve, GNUNET_NO); 1388 hello = GNUNET_HELLO_create (&ve->public_key,
1389 &add_valid_peer_address, ve,
1390 GNUNET_NO);
1344 GNUNET_PEERINFO_add_peer (GST_peerinfo, hello, NULL, NULL); 1391 GNUNET_PEERINFO_add_peer (GST_peerinfo, hello, NULL, NULL);
1345 GNUNET_free (hello); 1392 GNUNET_free (hello);
1346} 1393}
@@ -1456,8 +1503,8 @@ GST_validation_get_addresses (const struct GNUNET_PeerIdentity *target,
1456 * 1503 *
1457 * @param address the address 1504 * @param address the address
1458 * @param session the session 1505 * @param session the session
1459 * @param in_use GNUNET_YES if we are now using the address for a connection, 1506 * @param in_use #GNUNET_YES if we are now using the address for a connection,
1460 * GNUNET_NO if we are no longer using the address for a connection 1507 * #GNUNET_NO if we are no longer using the address for a connection
1461 * @param line line of caller just for DEBUGGING! 1508 * @param line line of caller just for DEBUGGING!
1462 */ 1509 */
1463void 1510void