aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_validation.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
commit5746309cb4be2073d550ad7a6885e918631dbc38 (patch)
tree89455bc4aadf977816b38df13f990372cd81d71a /src/transport/gnunet-service-transport_validation.c
parent6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff)
downloadgnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz
gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip
indentation
Diffstat (limited to 'src/transport/gnunet-service-transport_validation.c')
-rw-r--r--src/transport/gnunet-service-transport_validation.c147
1 files changed, 60 insertions, 87 deletions
diff --git a/src/transport/gnunet-service-transport_validation.c b/src/transport/gnunet-service-transport_validation.c
index f618a2b1a..9a3914814 100644
--- a/src/transport/gnunet-service-transport_validation.c
+++ b/src/transport/gnunet-service-transport_validation.c
@@ -361,13 +361,11 @@ find_validation_entry (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
361 ve->addr = (void *) &ve[1]; 361 ve->addr = (void *) &ve[1];
362 ve->public_key = *public_key; 362 ve->public_key = *public_key;
363 ve->pid = *neighbour; 363 ve->pid = *neighbour;
364 ve->challenge = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, 364 ve->challenge =
365 UINT32_MAX); 365 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE, UINT32_MAX);
366 memcpy (&ve[1], addr, addrlen); 366 memcpy (&ve[1], addr, addrlen);
367 ve->addrlen = addrlen; 367 ve->addrlen = addrlen;
368 GNUNET_CONTAINER_multihashmap_put (validation_map, 368 GNUNET_CONTAINER_multihashmap_put (validation_map, &neighbour->hashPubKey, ve,
369 &neighbour->hashPubKey,
370 ve,
371 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 369 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
372 return ve; 370 return ve;
373} 371}
@@ -385,10 +383,9 @@ find_validation_entry (const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
385 * @return GNUNET_OK (keep the address) 383 * @return GNUNET_OK (keep the address)
386 */ 384 */
387static int 385static int
388add_valid_address (void *cls, 386add_valid_address (void *cls, const char *tname,
389 const char *tname, 387 struct GNUNET_TIME_Absolute expiration, const void *addr,
390 struct GNUNET_TIME_Absolute expiration, 388 uint16_t addrlen)
391 const void *addr, uint16_t addrlen)
392{ 389{
393 const struct GNUNET_HELLO_Message *hello = cls; 390 const struct GNUNET_HELLO_Message *hello = cls;
394 struct ValidationEntry *ve; 391 struct ValidationEntry *ve;
@@ -397,8 +394,7 @@ add_valid_address (void *cls,
397 394
398 if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0) 395 if (GNUNET_TIME_absolute_get_remaining (expiration).rel_value == 0)
399 return GNUNET_OK; /* expired */ 396 return GNUNET_OK; /* expired */
400 if ((GNUNET_OK != 397 if ((GNUNET_OK != GNUNET_HELLO_get_id (hello, &pid)) ||
401 GNUNET_HELLO_get_id (hello, &pid)) ||
402 (GNUNET_OK != GNUNET_HELLO_get_key (hello, &public_key))) 398 (GNUNET_OK != GNUNET_HELLO_get_key (hello, &public_key)))
403 { 399 {
404 GNUNET_break (0); 400 GNUNET_break (0);
@@ -406,10 +402,8 @@ add_valid_address (void *cls,
406 } 402 }
407 ve = find_validation_entry (&public_key, &pid, tname, addr, addrlen); 403 ve = find_validation_entry (&public_key, &pid, tname, addr, addrlen);
408 ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, expiration); 404 ve->valid_until = GNUNET_TIME_absolute_max (ve->valid_until, expiration);
409 GNUNET_ATS_address_update (GST_ats, 405 GNUNET_ATS_address_update (GST_ats, &pid, ve->valid_until, tname, NULL, addr,
410 &pid, 406 addrlen, NULL, 0);
411 ve->valid_until,
412 tname, NULL, addr, addrlen, NULL, 0);
413 return GNUNET_OK; 407 return GNUNET_OK;
414} 408}
415 409
@@ -423,8 +417,7 @@ add_valid_address (void *cls,
423 * @param error message 417 * @param error message
424 */ 418 */
425static void 419static void
426process_peerinfo_hello (void *cls, 420process_peerinfo_hello (void *cls, const struct GNUNET_PeerIdentity *peer,
427 const struct GNUNET_PeerIdentity *peer,
428 const struct GNUNET_HELLO_Message *hello, 421 const struct GNUNET_HELLO_Message *hello,
429 const char *err_msg) 422 const char *err_msg)
430{ 423{
@@ -432,8 +425,7 @@ process_peerinfo_hello (void *cls,
432 if (NULL == hello) 425 if (NULL == hello)
433 return; 426 return;
434 GNUNET_assert (NULL == 427 GNUNET_assert (NULL ==
435 GNUNET_HELLO_iterate_addresses (hello, 428 GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO,
436 GNUNET_NO,
437 &add_valid_address, 429 &add_valid_address,
438 (void *) hello)); 430 (void *) hello));
439} 431}
@@ -517,8 +509,8 @@ timeout_hello_validation (void *cls,
517 509
518 ve->timeout_task = GNUNET_SCHEDULER_NO_TASK; 510 ve->timeout_task = GNUNET_SCHEDULER_NO_TASK;
519 GNUNET_STATISTICS_update (GST_stats, 511 GNUNET_STATISTICS_update (GST_stats,
520 gettext_noop ("# address records discarded"), 512 gettext_noop ("# address records discarded"), 1,
521 1, GNUNET_NO); 513 GNUNET_NO);
522 cleanup_validation_entry (NULL, &ve->pid.hashPubKey, ve); 514 cleanup_validation_entry (NULL, &ve->pid.hashPubKey, ve);
523} 515}
524 516
@@ -553,14 +545,9 @@ multicast_pong (void *cls,
553 papi = GST_plugins_find (plugin_name); 545 papi = GST_plugins_find (plugin_name);
554 if (papi == NULL) 546 if (papi == NULL)
555 return; 547 return;
556 (void) papi->send (papi->cls, 548 (void) papi->send (papi->cls, target, (const char *) pong,
557 target, 549 ntohs (pong->header.size), PONG_PRIORITY,
558 (const char *) pong, 550 HELLO_REVALIDATION_START_TIME, NULL, plugin_address,
559 ntohs (pong->header.size),
560 PONG_PRIORITY,
561 HELLO_REVALIDATION_START_TIME,
562 NULL,
563 plugin_address,
564 plugin_address_len, GNUNET_YES, NULL, NULL); 551 plugin_address_len, GNUNET_YES, NULL, NULL);
565} 552}
566 553
@@ -579,8 +566,7 @@ multicast_pong (void *cls,
579void 566void
580GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender, 567GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
581 const struct GNUNET_MessageHeader *hdr, 568 const struct GNUNET_MessageHeader *hdr,
582 const char *plugin_name, 569 const char *plugin_name, struct Session *session,
583 struct Session *session,
584 const void *sender_address, 570 const void *sender_address,
585 size_t sender_address_len) 571 size_t sender_address_len)
586{ 572{
@@ -601,15 +587,16 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
601 return; 587 return;
602 } 588 }
603 ping = (const struct TransportPingMessage *) hdr; 589 ping = (const struct TransportPingMessage *) hdr;
604 if (0 != memcmp (&ping->target, 590 if (0 !=
605 &GST_my_identity, sizeof (struct GNUNET_PeerIdentity))) 591 memcmp (&ping->target, &GST_my_identity,
592 sizeof (struct GNUNET_PeerIdentity)))
606 { 593 {
607 GNUNET_break_op (0); 594 GNUNET_break_op (0);
608 return; 595 return;
609 } 596 }
610 GNUNET_STATISTICS_update (GST_stats, 597 GNUNET_STATISTICS_update (GST_stats,
611 gettext_noop ("# PING messages received"), 598 gettext_noop ("# PING messages received"), 1,
612 1, GNUNET_NO); 599 GNUNET_NO);
613 addr = (const char *) &ping[1]; 600 addr = (const char *) &ping[1];
614 alen = ntohs (hdr->size) - sizeof (struct TransportPingMessage); 601 alen = ntohs (hdr->size) - sizeof (struct TransportPingMessage);
615 /* peer wants to confirm that this is one of our addresses, this is what is 602 /* peer wants to confirm that this is one of our addresses, this is what is
@@ -641,8 +628,8 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
641 pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG); 628 pong->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PONG);
642 pong->purpose.size = 629 pong->purpose.size =
643 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) + 630 htonl (sizeof (struct GNUNET_CRYPTO_RsaSignaturePurpose) +
644 sizeof (uint32_t) + 631 sizeof (uint32_t) + sizeof (struct GNUNET_TIME_AbsoluteNBO) +
645 sizeof (struct GNUNET_TIME_AbsoluteNBO) + alen + slen); 632 alen + slen);
646 pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN); 633 pong->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN);
647 pong->challenge = ping->challenge; 634 pong->challenge = ping->challenge;
648 pong->addrlen = htonl (alen + slen); 635 pong->addrlen = htonl (alen + slen);
@@ -659,8 +646,8 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
659 *sig_cache_exp = GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME); 646 *sig_cache_exp = GNUNET_TIME_relative_to_absolute (PONG_SIGNATURE_LIFETIME);
660 pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp); 647 pong->expiration = GNUNET_TIME_absolute_hton (*sig_cache_exp);
661 GNUNET_assert (GNUNET_OK == 648 GNUNET_assert (GNUNET_OK ==
662 GNUNET_CRYPTO_rsa_sign (GST_my_private_key, 649 GNUNET_CRYPTO_rsa_sign (GST_my_private_key, &pong->purpose,
663 &pong->purpose, sig_cache)); 650 sig_cache));
664 } 651 }
665 else 652 else
666 { 653 {
@@ -674,15 +661,11 @@ GST_validation_handle_ping (const struct GNUNET_PeerIdentity *sender,
674 if (papi == NULL) 661 if (papi == NULL)
675 ret = -1; 662 ret = -1;
676 else 663 else
677 ret = papi->send (papi->cls, 664 ret =
678 sender, 665 papi->send (papi->cls, sender, (const char *) pong,
679 (const char *) pong, 666 ntohs (pong->header.size), PONG_PRIORITY,
680 ntohs (pong->header.size), 667 HELLO_REVALIDATION_START_TIME, session, sender_address,
681 PONG_PRIORITY, 668 sender_address_len, GNUNET_SYSERR, NULL, NULL);
682 HELLO_REVALIDATION_START_TIME,
683 session,
684 sender_address,
685 sender_address_len, GNUNET_SYSERR, NULL, NULL);
686 if (ret != -1) 669 if (ret != -1)
687 { 670 {
688 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 671 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -733,8 +716,8 @@ struct ValidateAddressContext
733 * @param result GNUNET_OK if the connection is allowed, GNUNET_NO if not 716 * @param result GNUNET_OK if the connection is allowed, GNUNET_NO if not
734 */ 717 */
735static void 718static void
736transmit_ping_if_allowed (void *cls, 719transmit_ping_if_allowed (void *cls, const struct GNUNET_PeerIdentity *pid,
737 const struct GNUNET_PeerIdentity *pid, int result) 720 int result)
738{ 721{
739 struct ValidationEntry *ve = cls; 722 struct ValidationEntry *ve = cls;
740 struct TransportPingMessage ping; 723 struct TransportPingMessage ping;
@@ -746,8 +729,8 @@ transmit_ping_if_allowed (void *cls,
746 uint16_t hsize; 729 uint16_t hsize;
747 730
748 ve->bc = NULL; 731 ve->bc = NULL;
749 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 732 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Transmitting plain PING to `%s'\n",
750 "Transmitting plain PING to `%s'\n", GNUNET_i2s (pid)); 733 GNUNET_i2s (pid));
751 ping.header.size = htons (sizeof (struct TransportPingMessage)); 734 ping.header.size = htons (sizeof (struct TransportPingMessage));
752 ping.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PING); 735 ping.header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_PING);
753 ping.challenge = htonl (ve->challenge); 736 ping.challenge = htonl (ve->challenge);
@@ -780,13 +763,10 @@ transmit_ping_if_allowed (void *cls,
780 if (papi == NULL) 763 if (papi == NULL)
781 ret = -1; 764 ret = -1;
782 else 765 else
783 ret = papi->send (papi->cls, 766 ret =
784 pid, 767 papi->send (papi->cls, pid, message_buf, tsize, PING_PRIORITY,
785 message_buf, 768 HELLO_REVALIDATION_START_TIME, NULL /* no session */ ,
786 tsize, 769 ve->addr, ve->addrlen, GNUNET_YES, NULL, NULL);
787 PING_PRIORITY,
788 HELLO_REVALIDATION_START_TIME, NULL /* no session */ ,
789 ve->addr, ve->addrlen, GNUNET_YES, NULL, NULL);
790 } 770 }
791 if (-1 != ret) 771 if (-1 != ret)
792 { 772 {
@@ -811,10 +791,9 @@ transmit_ping_if_allowed (void *cls,
811 * @return GNUNET_OK (keep the address) 791 * @return GNUNET_OK (keep the address)
812 */ 792 */
813static int 793static int
814validate_address (void *cls, 794validate_address (void *cls, const char *tname,
815 const char *tname, 795 struct GNUNET_TIME_Absolute expiration, const void *addr,
816 struct GNUNET_TIME_Absolute expiration, 796 uint16_t addrlen)
817 const void *addr, uint16_t addrlen)
818{ 797{
819 const struct ValidateAddressContext *vac = cls; 798 const struct ValidateAddressContext *vac = cls;
820 const struct GNUNET_PeerIdentity *pid = &vac->pid; 799 const struct GNUNET_PeerIdentity *pid = &vac->pid;
@@ -861,18 +840,17 @@ revalidate_address (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
861 if (delay.rel_value > 0) 840 if (delay.rel_value > 0)
862 { 841 {
863 /* should wait a bit longer */ 842 /* should wait a bit longer */
864 ve->timeout_task = GNUNET_SCHEDULER_add_delayed (delay, 843 ve->timeout_task =
865 &revalidate_address, ve); 844 GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve);
866 return; 845 return;
867 } 846 }
868 GNUNET_STATISTICS_update (GST_stats, 847 GNUNET_STATISTICS_update (GST_stats,
869 gettext_noop ("# address revalidations started"), 848 gettext_noop ("# address revalidations started"), 1,
870 1, GNUNET_NO); 849 GNUNET_NO);
871 vac.pid = ve->pid; 850 vac.pid = ve->pid;
872 vac.public_key = ve->public_key; 851 vac.public_key = ve->public_key;
873 validate_address (&vac, 852 validate_address (&vac, ve->transport_name, ve->valid_until, ve->addr,
874 ve->transport_name, 853 (uint16_t) ve->addrlen);
875 ve->valid_until, ve->addr, (uint16_t) ve->addrlen);
876} 854}
877 855
878 856
@@ -888,8 +866,7 @@ add_valid_peer_address (void *cls, size_t max, void *buf)
888{ 866{
889 struct ValidationEntry *ve = cls; 867 struct ValidationEntry *ve = cls;
890 868
891 return GNUNET_HELLO_add_address (ve->transport_name, 869 return GNUNET_HELLO_add_address (ve->transport_name, ve->valid_until,
892 ve->valid_until,
893 ve->addr, ve->addrlen, buf, max); 870 ve->addr, ve->addrlen, buf, max);
894} 871}
895 872
@@ -921,8 +898,8 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
921 return; 898 return;
922 } 899 }
923 GNUNET_STATISTICS_update (GST_stats, 900 GNUNET_STATISTICS_update (GST_stats,
924 gettext_noop ("# PONG messages received"), 901 gettext_noop ("# PONG messages received"), 1,
925 1, GNUNET_NO); 902 GNUNET_NO);
926 pong = (const struct TransportPongMessage *) hdr; 903 pong = (const struct TransportPongMessage *) hdr;
927 addr = (const char *) &pong[1]; 904 addr = (const char *) &pong[1];
928 alen = ntohs (hdr->size) - sizeof (struct TransportPongMessage); 905 alen = ntohs (hdr->size) - sizeof (struct TransportPongMessage);
@@ -962,8 +939,8 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
962 } 939 }
963 if (GNUNET_OK != 940 if (GNUNET_OK !=
964 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN, 941 GNUNET_CRYPTO_rsa_verify (GNUNET_SIGNATURE_PURPOSE_TRANSPORT_PONG_OWN,
965 &pong->purpose, 942 &pong->purpose, &pong->signature,
966 &pong->signature, &ve->public_key)) 943 &ve->public_key))
967 { 944 {
968 GNUNET_break_op (0); 945 GNUNET_break_op (0);
969 return; 946 return;
@@ -983,9 +960,10 @@ GST_validation_handle_pong (const struct GNUNET_PeerIdentity *sender,
983 960
984 /* randomly delay by up to 1h to avoid synchronous validations */ 961 /* randomly delay by up to 1h to avoid synchronous validations */
985 rdelay = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 60 * 60); 962 rdelay = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 60 * 60);
986 delay = GNUNET_TIME_relative_add (HELLO_REVALIDATION_START_TIME, 963 delay =
987 GNUNET_TIME_relative_multiply 964 GNUNET_TIME_relative_add (HELLO_REVALIDATION_START_TIME,
988 (GNUNET_TIME_UNIT_SECONDS, rdelay)); 965 GNUNET_TIME_relative_multiply
966 (GNUNET_TIME_UNIT_SECONDS, rdelay));
989 ve->timeout_task = 967 ve->timeout_task =
990 GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve); 968 GNUNET_SCHEDULER_add_delayed (delay, &revalidate_address, ve);
991} 969}
@@ -1004,8 +982,7 @@ GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello)
1004 (const struct GNUNET_HELLO_Message *) hello; 982 (const struct GNUNET_HELLO_Message *) hello;
1005 struct ValidateAddressContext vac; 983 struct ValidateAddressContext vac;
1006 984
1007 if ((GNUNET_OK != 985 if ((GNUNET_OK != GNUNET_HELLO_get_id (hm, &vac.pid)) ||
1008 GNUNET_HELLO_get_id (hm, &vac.pid)) ||
1009 (GNUNET_OK != GNUNET_HELLO_get_key (hm, &vac.public_key))) 986 (GNUNET_OK != GNUNET_HELLO_get_key (hm, &vac.public_key)))
1010 { 987 {
1011 /* malformed HELLO */ 988 /* malformed HELLO */
@@ -1013,8 +990,7 @@ GST_validation_handle_hello (const struct GNUNET_MessageHeader *hello)
1013 return; 990 return;
1014 } 991 }
1015 GNUNET_assert (NULL == 992 GNUNET_assert (NULL ==
1016 GNUNET_HELLO_iterate_addresses (hm, 993 GNUNET_HELLO_iterate_addresses (hm, GNUNET_NO,
1017 GNUNET_NO,
1018 &validate_address, &vac)); 994 &validate_address, &vac));
1019} 995}
1020 996
@@ -1051,10 +1027,7 @@ iterate_addresses (void *cls, const GNUNET_HashCode * key, void *value)
1051 struct IteratorContext *ic = cls; 1027 struct IteratorContext *ic = cls;
1052 struct ValidationEntry *ve = value; 1028 struct ValidationEntry *ve = value;
1053 1029
1054 ic->cb (ic->cb_cls, 1030 ic->cb (ic->cb_cls, &ve->public_key, &ve->pid, ve->valid_until,
1055 &ve->public_key,
1056 &ve->pid,
1057 ve->valid_until,
1058 ve->validation_block, ve->transport_name, ve->addr, ve->addrlen); 1031 ve->validation_block, ve->transport_name, ve->addr, ve->addrlen);
1059 return GNUNET_OK; 1032 return GNUNET_OK;
1060} 1033}