diff options
Diffstat (limited to 'src/topology/gnunet-daemon-topology.c')
-rw-r--r-- | src/topology/gnunet-daemon-topology.c | 210 |
1 files changed, 90 insertions, 120 deletions
diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c index 91d0ed12d..8f86619fd 100644 --- a/src/topology/gnunet-daemon-topology.c +++ b/src/topology/gnunet-daemon-topology.c | |||
@@ -247,8 +247,8 @@ blacklist_check (void *cls, const struct GNUNET_PeerIdentity *pid) | |||
247 | pos = GNUNET_CONTAINER_multihashmap_get (peers, &pid->hashPubKey); | 247 | pos = GNUNET_CONTAINER_multihashmap_get (peers, &pid->hashPubKey); |
248 | if ((pos != NULL) && (pos->is_friend == GNUNET_YES)) | 248 | if ((pos != NULL) && (pos->is_friend == GNUNET_YES)) |
249 | return GNUNET_OK; | 249 | return GNUNET_OK; |
250 | GNUNET_STATISTICS_update (stats, | 250 | GNUNET_STATISTICS_update (stats, gettext_noop ("# peers blacklisted"), 1, |
251 | gettext_noop ("# peers blacklisted"), 1, GNUNET_NO); | 251 | GNUNET_NO); |
252 | return GNUNET_SYSERR; | 252 | return GNUNET_SYSERR; |
253 | } | 253 | } |
254 | 254 | ||
@@ -292,8 +292,8 @@ connect_completed_callback (void *cls, int success) | |||
292 | static int | 292 | static int |
293 | is_connection_allowed (struct Peer *peer) | 293 | is_connection_allowed (struct Peer *peer) |
294 | { | 294 | { |
295 | if (0 == memcmp (&my_identity, | 295 | if (0 == |
296 | &peer->pid, sizeof (struct GNUNET_PeerIdentity))) | 296 | memcmp (&my_identity, &peer->pid, sizeof (struct GNUNET_PeerIdentity))) |
297 | return GNUNET_SYSERR; /* disallow connections to self */ | 297 | return GNUNET_SYSERR; /* disallow connections to self */ |
298 | if (peer->is_friend) | 298 | if (peer->is_friend) |
299 | return GNUNET_OK; | 299 | return GNUNET_OK; |
@@ -355,8 +355,9 @@ free_peer (void *cls, const GNUNET_HashCode * pid, void *value) | |||
355 | * @param cls 'struct Peer' to greylist | 355 | * @param cls 'struct Peer' to greylist |
356 | * @param tc scheduler context | 356 | * @param tc scheduler context |
357 | */ | 357 | */ |
358 | static void | 358 | static void remove_from_greylist (void *cls, |
359 | remove_from_greylist (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 359 | const struct GNUNET_SCHEDULER_TaskContext |
360 | *tc); | ||
360 | 361 | ||
361 | 362 | ||
362 | /** | 363 | /** |
@@ -392,19 +393,18 @@ attempt_connect (struct Peer *pos) | |||
392 | pos->greylisted_until = GNUNET_TIME_relative_to_absolute (rem); | 393 | pos->greylisted_until = GNUNET_TIME_relative_to_absolute (rem); |
393 | if (pos->greylist_clean_task != GNUNET_SCHEDULER_NO_TASK) | 394 | if (pos->greylist_clean_task != GNUNET_SCHEDULER_NO_TASK) |
394 | GNUNET_SCHEDULER_cancel (pos->greylist_clean_task); | 395 | GNUNET_SCHEDULER_cancel (pos->greylist_clean_task); |
395 | pos->greylist_clean_task | 396 | pos->greylist_clean_task = |
396 | = GNUNET_SCHEDULER_add_delayed (rem, &remove_from_greylist, pos); | 397 | GNUNET_SCHEDULER_add_delayed (rem, &remove_from_greylist, pos); |
397 | #if DEBUG_TOPOLOGY | 398 | #if DEBUG_TOPOLOGY |
398 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 399 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking to connect to `%s'\n", |
399 | "Asking to connect to `%s'\n", GNUNET_i2s (&pos->pid)); | 400 | GNUNET_i2s (&pos->pid)); |
400 | #endif | 401 | #endif |
401 | GNUNET_STATISTICS_update (stats, | 402 | GNUNET_STATISTICS_update (stats, |
402 | gettext_noop ("# connect requests issued to core"), | 403 | gettext_noop ("# connect requests issued to core"), |
403 | 1, GNUNET_NO); | 404 | 1, GNUNET_NO); |
404 | pos->connect_req = GNUNET_CORE_peer_request_connect (handle, | 405 | pos->connect_req = |
405 | &pos->pid, | 406 | GNUNET_CORE_peer_request_connect (handle, &pos->pid, |
406 | &connect_completed_callback, | 407 | &connect_completed_callback, pos); |
407 | pos); | ||
408 | } | 408 | } |
409 | 409 | ||
410 | 410 | ||
@@ -429,11 +429,11 @@ remove_from_greylist (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
429 | } | 429 | } |
430 | else | 430 | else |
431 | { | 431 | { |
432 | pos->greylist_clean_task | 432 | pos->greylist_clean_task = |
433 | = GNUNET_SCHEDULER_add_delayed (rem, &remove_from_greylist, pos); | 433 | GNUNET_SCHEDULER_add_delayed (rem, &remove_from_greylist, pos); |
434 | } | 434 | } |
435 | if ((GNUNET_NO == pos->is_friend) && | 435 | if ((GNUNET_NO == pos->is_friend) && (GNUNET_NO == pos->is_connected) && |
436 | (GNUNET_NO == pos->is_connected) && (NULL == pos->hello)) | 436 | (NULL == pos->hello)) |
437 | { | 437 | { |
438 | free_peer (NULL, &pos->pid.hashPubKey, pos); | 438 | free_peer (NULL, &pos->pid.hashPubKey, pos); |
439 | return; | 439 | return; |
@@ -450,8 +450,7 @@ remove_from_greylist (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
450 | * @return the new entry | 450 | * @return the new entry |
451 | */ | 451 | */ |
452 | static struct Peer * | 452 | static struct Peer * |
453 | make_peer (const struct | 453 | make_peer (const struct GNUNET_PeerIdentity *peer, |
454 | GNUNET_PeerIdentity *peer, | ||
455 | const struct GNUNET_HELLO_Message *hello, int is_friend) | 454 | const struct GNUNET_HELLO_Message *hello, int is_friend) |
456 | { | 455 | { |
457 | struct Peer *ret; | 456 | struct Peer *ret; |
@@ -465,8 +464,7 @@ make_peer (const struct | |||
465 | memcpy (ret->hello, hello, GNUNET_HELLO_size (hello)); | 464 | memcpy (ret->hello, hello, GNUNET_HELLO_size (hello)); |
466 | } | 465 | } |
467 | GNUNET_break (GNUNET_OK == | 466 | GNUNET_break (GNUNET_OK == |
468 | GNUNET_CONTAINER_multihashmap_put (peers, | 467 | GNUNET_CONTAINER_multihashmap_put (peers, &peer->hashPubKey, |
469 | &peer->hashPubKey, | ||
470 | ret, | 468 | ret, |
471 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); | 469 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); |
472 | return ret; | 470 | return ret; |
@@ -599,8 +597,8 @@ schedule_next_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
599 | fah.max_size = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1; | 597 | fah.max_size = GNUNET_SERVER_MAX_MESSAGE_SIZE - 1; |
600 | fah.next_adv = GNUNET_TIME_UNIT_FOREVER_REL; | 598 | fah.next_adv = GNUNET_TIME_UNIT_FOREVER_REL; |
601 | GNUNET_CONTAINER_multihashmap_iterate (peers, &find_advertisable_hello, &fah); | 599 | GNUNET_CONTAINER_multihashmap_iterate (peers, &find_advertisable_hello, &fah); |
602 | pl->hello_delay_task | 600 | pl->hello_delay_task = |
603 | = GNUNET_SCHEDULER_add_delayed (fah.next_adv, &schedule_next_hello, pl); | 601 | GNUNET_SCHEDULER_add_delayed (fah.next_adv, &schedule_next_hello, pl); |
604 | if (fah.result == NULL) | 602 | if (fah.result == NULL) |
605 | return; | 603 | return; |
606 | next_want = GNUNET_HELLO_size (fah.result->hello); | 604 | next_want = GNUNET_HELLO_size (fah.result->hello); |
@@ -608,14 +606,11 @@ schedule_next_hello (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
608 | if (delay.rel_value == 0) | 606 | if (delay.rel_value == 0) |
609 | { | 607 | { |
610 | /* now! */ | 608 | /* now! */ |
611 | pl->hello_req = GNUNET_CORE_notify_transmit_ready (handle, | 609 | pl->hello_req = |
612 | GNUNET_YES, | 610 | GNUNET_CORE_notify_transmit_ready (handle, GNUNET_YES, 0, |
613 | 0, | 611 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, |
614 | GNUNET_CONSTANTS_SERVICE_TIMEOUT, | 612 | &pl->pid, next_want, |
615 | &pl->pid, | 613 | &hello_advertising_ready, pl); |
616 | next_want, | ||
617 | &hello_advertising_ready, | ||
618 | pl); | ||
619 | } | 614 | } |
620 | } | 615 | } |
621 | 616 | ||
@@ -650,8 +645,8 @@ reschedule_hellos (void *cls, const GNUNET_HashCode * pid, void *value) | |||
650 | GNUNET_SCHEDULER_cancel (peer->hello_delay_task); | 645 | GNUNET_SCHEDULER_cancel (peer->hello_delay_task); |
651 | peer->hello_delay_task = GNUNET_SCHEDULER_NO_TASK; | 646 | peer->hello_delay_task = GNUNET_SCHEDULER_NO_TASK; |
652 | } | 647 | } |
653 | peer->hello_delay_task | 648 | peer->hello_delay_task = |
654 | = GNUNET_SCHEDULER_add_now (&schedule_next_hello, peer); | 649 | GNUNET_SCHEDULER_add_now (&schedule_next_hello, peer); |
655 | return GNUNET_YES; | 650 | return GNUNET_YES; |
656 | } | 651 | } |
657 | 652 | ||
@@ -664,9 +659,7 @@ reschedule_hellos (void *cls, const GNUNET_HashCode * pid, void *value) | |||
664 | * @param atsi performance data | 659 | * @param atsi performance data |
665 | */ | 660 | */ |
666 | static void | 661 | static void |
667 | connect_notify (void *cls, | 662 | connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, |
668 | const struct | ||
669 | GNUNET_PeerIdentity *peer, | ||
670 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 663 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
671 | { | 664 | { |
672 | struct Peer *pos; | 665 | struct Peer *pos; |
@@ -680,8 +673,7 @@ connect_notify (void *cls, | |||
680 | return; | 673 | return; |
681 | 674 | ||
682 | connection_count++; | 675 | connection_count++; |
683 | GNUNET_STATISTICS_set (stats, | 676 | GNUNET_STATISTICS_set (stats, gettext_noop ("# peers connected"), |
684 | gettext_noop ("# peers connected"), | ||
685 | connection_count, GNUNET_NO); | 677 | connection_count, GNUNET_NO); |
686 | pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); | 678 | pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); |
687 | if (pos == NULL) | 679 | if (pos == NULL) |
@@ -702,8 +694,7 @@ connect_notify (void *cls, | |||
702 | (GNUNET_YES != friends_only)) | 694 | (GNUNET_YES != friends_only)) |
703 | whitelist_peers (); | 695 | whitelist_peers (); |
704 | friend_count++; | 696 | friend_count++; |
705 | GNUNET_STATISTICS_set (stats, | 697 | GNUNET_STATISTICS_set (stats, gettext_noop ("# friends connected"), |
706 | gettext_noop ("# friends connected"), | ||
707 | friend_count, GNUNET_NO); | 698 | friend_count, GNUNET_NO); |
708 | } | 699 | } |
709 | reschedule_hellos (NULL, &peer->hashPubKey, pos); | 700 | reschedule_hellos (NULL, &peer->hashPubKey, pos); |
@@ -784,14 +775,12 @@ disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
784 | GNUNET_SCHEDULER_cancel (pos->hello_delay_task); | 775 | GNUNET_SCHEDULER_cancel (pos->hello_delay_task); |
785 | pos->hello_delay_task = GNUNET_SCHEDULER_NO_TASK; | 776 | pos->hello_delay_task = GNUNET_SCHEDULER_NO_TASK; |
786 | } | 777 | } |
787 | GNUNET_STATISTICS_set (stats, | 778 | GNUNET_STATISTICS_set (stats, gettext_noop ("# peers connected"), |
788 | gettext_noop ("# peers connected"), | ||
789 | connection_count, GNUNET_NO); | 779 | connection_count, GNUNET_NO); |
790 | if (pos->is_friend) | 780 | if (pos->is_friend) |
791 | { | 781 | { |
792 | friend_count--; | 782 | friend_count--; |
793 | GNUNET_STATISTICS_set (stats, | 783 | GNUNET_STATISTICS_set (stats, gettext_noop ("# friends connected"), |
794 | gettext_noop ("# friends connected"), | ||
795 | friend_count, GNUNET_NO); | 784 | friend_count, GNUNET_NO); |
796 | } | 785 | } |
797 | if (((connection_count < target_connection_count) || | 786 | if (((connection_count < target_connection_count) || |
@@ -814,10 +803,9 @@ disconnect_notify (void *cls, const struct GNUNET_PeerIdentity *peer) | |||
814 | * @return GNUNET_SYSERR always, to terminate iteration | 803 | * @return GNUNET_SYSERR always, to terminate iteration |
815 | */ | 804 | */ |
816 | static int | 805 | static int |
817 | address_iterator (void *cls, | 806 | address_iterator (void *cls, const char *tname, |
818 | const char *tname, | 807 | struct GNUNET_TIME_Absolute expiration, const void *addr, |
819 | struct GNUNET_TIME_Absolute expiration, | 808 | uint16_t addrlen) |
820 | const void *addr, uint16_t addrlen) | ||
821 | { | 809 | { |
822 | int *flag = cls; | 810 | int *flag = cls; |
823 | 811 | ||
@@ -850,8 +838,8 @@ consider_for_advertising (const struct GNUNET_HELLO_Message *hello) | |||
850 | if (0 == memcmp (&pid, &my_identity, sizeof (struct GNUNET_PeerIdentity))) | 838 | if (0 == memcmp (&pid, &my_identity, sizeof (struct GNUNET_PeerIdentity))) |
851 | return; /* that's me! */ | 839 | return; /* that's me! */ |
852 | have_address = GNUNET_NO; | 840 | have_address = GNUNET_NO; |
853 | GNUNET_HELLO_iterate_addresses (hello, | 841 | GNUNET_HELLO_iterate_addresses (hello, GNUNET_NO, &address_iterator, |
854 | GNUNET_NO, &address_iterator, &have_address); | 842 | &have_address); |
855 | if (GNUNET_NO == have_address) | 843 | if (GNUNET_NO == have_address) |
856 | return; /* no point in advertising this one... */ | 844 | return; /* no point in advertising this one... */ |
857 | peer = GNUNET_CONTAINER_multihashmap_get (peers, &pid.hashPubKey); | 845 | peer = GNUNET_CONTAINER_multihashmap_get (peers, &pid.hashPubKey); |
@@ -867,8 +855,8 @@ consider_for_advertising (const struct GNUNET_HELLO_Message *hello) | |||
867 | } | 855 | } |
868 | #if DEBUG_TOPOLOGY | 856 | #if DEBUG_TOPOLOGY |
869 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 857 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
870 | "Found `%s' from peer `%s' for advertising\n", | 858 | "Found `%s' from peer `%s' for advertising\n", "HELLO", |
871 | "HELLO", GNUNET_i2s (&pid)); | 859 | GNUNET_i2s (&pid)); |
872 | #endif | 860 | #endif |
873 | if (peer->hello != NULL) | 861 | if (peer->hello != NULL) |
874 | { | 862 | { |
@@ -901,8 +889,7 @@ consider_for_advertising (const struct GNUNET_HELLO_Message *hello) | |||
901 | * @param err_msg NULL if successful, otherwise contains error message | 889 | * @param err_msg NULL if successful, otherwise contains error message |
902 | */ | 890 | */ |
903 | static void | 891 | static void |
904 | process_peer (void *cls, | 892 | process_peer (void *cls, const struct GNUNET_PeerIdentity *peer, |
905 | const struct GNUNET_PeerIdentity *peer, | ||
906 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) | 893 | const struct GNUNET_HELLO_Message *hello, const char *err_msg) |
907 | { | 894 | { |
908 | struct Peer *pos; | 895 | struct Peer *pos; |
@@ -932,11 +919,10 @@ process_peer (void *cls, | |||
932 | GNUNET_CONTAINER_bloomfilter_free (pos->filter); | 919 | GNUNET_CONTAINER_bloomfilter_free (pos->filter); |
933 | pos->filter = NULL; | 920 | pos->filter = NULL; |
934 | } | 921 | } |
935 | if ((!pos->is_connected) && | 922 | if ((!pos->is_connected) && (!pos->is_friend) && |
936 | (!pos->is_friend) && | ||
937 | (0 == | 923 | (0 == |
938 | GNUNET_TIME_absolute_get_remaining (pos-> | 924 | GNUNET_TIME_absolute_get_remaining (pos->greylisted_until). |
939 | greylisted_until).rel_value)) | 925 | rel_value)) |
940 | free_peer (NULL, &pos->pid.hashPubKey, pos); | 926 | free_peer (NULL, &pos->pid.hashPubKey, pos); |
941 | } | 927 | } |
942 | return; | 928 | return; |
@@ -949,22 +935,22 @@ process_peer (void *cls, | |||
949 | if (GNUNET_YES == pos->is_connected) | 935 | if (GNUNET_YES == pos->is_connected) |
950 | { | 936 | { |
951 | #if DEBUG_TOPOLOGY | 937 | #if DEBUG_TOPOLOGY |
952 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 938 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Already connected to peer `%s'\n", |
953 | "Already connected to peer `%s'\n", GNUNET_i2s (peer)); | 939 | GNUNET_i2s (peer)); |
954 | #endif | 940 | #endif |
955 | return; | 941 | return; |
956 | } | 942 | } |
957 | if (GNUNET_TIME_absolute_get_remaining (pos->greylisted_until).rel_value > 0) | 943 | if (GNUNET_TIME_absolute_get_remaining (pos->greylisted_until).rel_value > 0) |
958 | { | 944 | { |
959 | #if DEBUG_TOPOLOGY | 945 | #if DEBUG_TOPOLOGY |
960 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 946 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Already tried peer `%s' recently\n", |
961 | "Already tried peer `%s' recently\n", GNUNET_i2s (peer)); | 947 | GNUNET_i2s (peer)); |
962 | #endif | 948 | #endif |
963 | return; /* peer still greylisted */ | 949 | return; /* peer still greylisted */ |
964 | } | 950 | } |
965 | #if DEBUG_TOPOLOGY | 951 | #if DEBUG_TOPOLOGY |
966 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 952 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Considering connecting to peer `%s'\n", |
967 | "Considering connecting to peer `%s'\n", GNUNET_i2s (peer)); | 953 | GNUNET_i2s (peer)); |
968 | #endif | 954 | #endif |
969 | attempt_connect (pos); | 955 | attempt_connect (pos); |
970 | } | 956 | } |
@@ -980,8 +966,7 @@ process_peer (void *cls, | |||
980 | * @param publicKey public key of this peer, NULL if we failed | 966 | * @param publicKey public key of this peer, NULL if we failed |
981 | */ | 967 | */ |
982 | static void | 968 | static void |
983 | core_init (void *cls, | 969 | core_init (void *cls, struct GNUNET_CORE_Handle *server, |
984 | struct GNUNET_CORE_Handle *server, | ||
985 | const struct GNUNET_PeerIdentity *my_id, | 970 | const struct GNUNET_PeerIdentity *my_id, |
986 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) | 971 | const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey) |
987 | { | 972 | { |
@@ -1021,14 +1006,14 @@ read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1021 | GNUNET_CONFIGURATION_get_value_filename (cfg, "TOPOLOGY", "FRIENDS", &fn)) | 1006 | GNUNET_CONFIGURATION_get_value_filename (cfg, "TOPOLOGY", "FRIENDS", &fn)) |
1022 | { | 1007 | { |
1023 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1008 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1024 | _("Option `%s' in section `%s' not specified!\n"), | 1009 | _("Option `%s' in section `%s' not specified!\n"), "FRIENDS", |
1025 | "FRIENDS", "TOPOLOGY"); | 1010 | "TOPOLOGY"); |
1026 | return; | 1011 | return; |
1027 | } | 1012 | } |
1028 | if (GNUNET_OK != GNUNET_DISK_file_test (fn)) | 1013 | if (GNUNET_OK != GNUNET_DISK_file_test (fn)) |
1029 | GNUNET_DISK_fn_write (fn, NULL, 0, | 1014 | GNUNET_DISK_fn_write (fn, NULL, 0, |
1030 | GNUNET_DISK_PERM_USER_READ | 1015 | GNUNET_DISK_PERM_USER_READ | |
1031 | | GNUNET_DISK_PERM_USER_WRITE); | 1016 | GNUNET_DISK_PERM_USER_WRITE); |
1032 | if (0 != STAT (fn, &frstat)) | 1017 | if (0 != STAT (fn, &frstat)) |
1033 | { | 1018 | { |
1034 | if ((friends_only) || (minimum_friend_count > 0)) | 1019 | if ((friends_only) || (minimum_friend_count > 0)) |
@@ -1039,8 +1024,8 @@ read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1039 | } | 1024 | } |
1040 | if (frstat.st_size == 0) | 1025 | if (frstat.st_size == 0) |
1041 | { | 1026 | { |
1042 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1027 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, _("Friends file `%s' is empty.\n"), |
1043 | _("Friends file `%s' is empty.\n"), fn); | 1028 | fn); |
1044 | GNUNET_free (fn); | 1029 | GNUNET_free (fn); |
1045 | return; | 1030 | return; |
1046 | } | 1031 | } |
@@ -1071,8 +1056,8 @@ read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1071 | { | 1056 | { |
1072 | memcpy (&enc, &data[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); | 1057 | memcpy (&enc, &data[pos], sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded)); |
1073 | if (!isspace | 1058 | if (!isspace |
1074 | ((unsigned char) | 1059 | ((unsigned char) enc. |
1075 | enc.encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1])) | 1060 | encoding[sizeof (struct GNUNET_CRYPTO_HashAsciiEncoded) - 1])) |
1076 | { | 1061 | { |
1077 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 1062 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
1078 | _ | 1063 | _ |
@@ -1115,8 +1100,7 @@ read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1115 | } | 1100 | } |
1116 | GNUNET_free (data); | 1101 | GNUNET_free (data); |
1117 | GNUNET_free (fn); | 1102 | GNUNET_free (fn); |
1118 | GNUNET_STATISTICS_update (stats, | 1103 | GNUNET_STATISTICS_update (stats, gettext_noop ("# friends in configuration"), |
1119 | gettext_noop ("# friends in configuration"), | ||
1120 | entries_found, GNUNET_NO); | 1104 | entries_found, GNUNET_NO); |
1121 | if ((minimum_friend_count > entries_found) && (friends_only == GNUNET_NO)) | 1105 | if ((minimum_friend_count > entries_found) && (friends_only == GNUNET_NO)) |
1122 | { | 1106 | { |
@@ -1147,8 +1131,7 @@ read_friends_file (const struct GNUNET_CONFIGURATION_Handle *cfg) | |||
1147 | * GNUNET_SYSERR to close it (signal serious error) | 1131 | * GNUNET_SYSERR to close it (signal serious error) |
1148 | */ | 1132 | */ |
1149 | static int | 1133 | static int |
1150 | handle_encrypted_hello (void *cls, | 1134 | handle_encrypted_hello (void *cls, const struct GNUNET_PeerIdentity *other, |
1151 | const struct GNUNET_PeerIdentity *other, | ||
1152 | const struct GNUNET_MessageHeader *message, | 1135 | const struct GNUNET_MessageHeader *message, |
1153 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) | 1136 | const struct GNUNET_TRANSPORT_ATS_Information *atsi) |
1154 | { | 1137 | { |
@@ -1156,8 +1139,7 @@ handle_encrypted_hello (void *cls, | |||
1156 | struct GNUNET_PeerIdentity pid; | 1139 | struct GNUNET_PeerIdentity pid; |
1157 | 1140 | ||
1158 | #if DEBUG_TOPOLOGY | 1141 | #if DEBUG_TOPOLOGY |
1159 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1142 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received encrypted `%s' from peer `%s'", |
1160 | "Received encrypted `%s' from peer `%s'", | ||
1161 | "HELLO", GNUNET_i2s (other)); | 1143 | "HELLO", GNUNET_i2s (other)); |
1162 | #endif | 1144 | #endif |
1163 | if (GNUNET_OK != | 1145 | if (GNUNET_OK != |
@@ -1166,8 +1148,7 @@ handle_encrypted_hello (void *cls, | |||
1166 | GNUNET_break_op (0); | 1148 | GNUNET_break_op (0); |
1167 | return GNUNET_SYSERR; | 1149 | return GNUNET_SYSERR; |
1168 | } | 1150 | } |
1169 | GNUNET_STATISTICS_update (stats, | 1151 | GNUNET_STATISTICS_update (stats, gettext_noop ("# HELLO messages received"), |
1170 | gettext_noop ("# HELLO messages received"), | ||
1171 | 1, GNUNET_NO); | 1152 | 1, GNUNET_NO); |
1172 | peer = GNUNET_CONTAINER_multihashmap_get (peers, &pid.hashPubKey); | 1153 | peer = GNUNET_CONTAINER_multihashmap_get (peers, &pid.hashPubKey); |
1173 | if (peer == NULL) | 1154 | if (peer == NULL) |
@@ -1220,12 +1201,12 @@ hello_advertising_ready (void *cls, size_t size, void *buf) | |||
1220 | memcpy (buf, fah.result->hello, want); | 1201 | memcpy (buf, fah.result->hello, want); |
1221 | GNUNET_CONTAINER_bloomfilter_add (fah.result->filter, &pl->pid.hashPubKey); | 1202 | GNUNET_CONTAINER_bloomfilter_add (fah.result->filter, &pl->pid.hashPubKey); |
1222 | #if DEBUG_TOPOLOGY | 1203 | #if DEBUG_TOPOLOGY |
1223 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1204 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Sending `%s' with %u bytes", "HELLO", |
1224 | "Sending `%s' with %u bytes", "HELLO", (unsigned int) want); | 1205 | (unsigned int) want); |
1225 | #endif | 1206 | #endif |
1226 | GNUNET_STATISTICS_update (stats, | 1207 | GNUNET_STATISTICS_update (stats, |
1227 | gettext_noop ("# HELLO messages gossipped"), | 1208 | gettext_noop ("# HELLO messages gossipped"), 1, |
1228 | 1, GNUNET_NO); | 1209 | GNUNET_NO); |
1229 | } | 1210 | } |
1230 | 1211 | ||
1231 | if (pl->hello_delay_task != GNUNET_SCHEDULER_NO_TASK) | 1212 | if (pl->hello_delay_task != GNUNET_SCHEDULER_NO_TASK) |
@@ -1284,9 +1265,8 @@ cleaning_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1284 | * @param c configuration | 1265 | * @param c configuration |
1285 | */ | 1266 | */ |
1286 | static void | 1267 | static void |
1287 | run (void *cls, | 1268 | run (void *cls, char *const *args, const char *cfgfile, |
1288 | char *const *args, | 1269 | const struct GNUNET_CONFIGURATION_Handle *c) |
1289 | const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c) | ||
1290 | { | 1270 | { |
1291 | static struct GNUNET_CORE_MessageHandler handlers[] = { | 1271 | static struct GNUNET_CORE_MessageHandler handlers[] = { |
1292 | {&handle_encrypted_hello, GNUNET_MESSAGE_TYPE_HELLO, 0}, | 1272 | {&handle_encrypted_hello, GNUNET_MESSAGE_TYPE_HELLO, 0}, |
@@ -1296,21 +1276,17 @@ run (void *cls, | |||
1296 | 1276 | ||
1297 | cfg = c; | 1277 | cfg = c; |
1298 | stats = GNUNET_STATISTICS_create ("topology", cfg); | 1278 | stats = GNUNET_STATISTICS_create ("topology", cfg); |
1299 | autoconnect = GNUNET_CONFIGURATION_get_value_yesno (cfg, | 1279 | autoconnect = |
1300 | "TOPOLOGY", | 1280 | GNUNET_CONFIGURATION_get_value_yesno (cfg, "TOPOLOGY", "AUTOCONNECT"); |
1301 | "AUTOCONNECT"); | 1281 | friends_only = |
1302 | friends_only = GNUNET_CONFIGURATION_get_value_yesno (cfg, | 1282 | GNUNET_CONFIGURATION_get_value_yesno (cfg, "TOPOLOGY", "FRIENDS-ONLY"); |
1303 | "TOPOLOGY", | ||
1304 | "FRIENDS-ONLY"); | ||
1305 | if (GNUNET_OK != | 1283 | if (GNUNET_OK != |
1306 | GNUNET_CONFIGURATION_get_value_number (cfg, | 1284 | GNUNET_CONFIGURATION_get_value_number (cfg, "TOPOLOGY", "MINIMUM-FRIENDS", |
1307 | "TOPOLOGY", | 1285 | &opt)) |
1308 | "MINIMUM-FRIENDS", &opt)) | ||
1309 | opt = 0; | 1286 | opt = 0; |
1310 | minimum_friend_count = (unsigned int) opt; | 1287 | minimum_friend_count = (unsigned int) opt; |
1311 | if (GNUNET_OK != | 1288 | if (GNUNET_OK != |
1312 | GNUNET_CONFIGURATION_get_value_number (cfg, | 1289 | GNUNET_CONFIGURATION_get_value_number (cfg, "TOPOLOGY", |
1313 | "TOPOLOGY", | ||
1314 | "TARGET-CONNECTION-COUNT", &opt)) | 1290 | "TARGET-CONNECTION-COUNT", &opt)) |
1315 | opt = 16; | 1291 | opt = 16; |
1316 | target_connection_count = (unsigned int) opt; | 1292 | target_connection_count = (unsigned int) opt; |
@@ -1321,23 +1297,18 @@ run (void *cls, | |||
1321 | #if DEBUG_TOPOLOGY | 1297 | #if DEBUG_TOPOLOGY |
1322 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1298 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1323 | "Topology would like %u connections with at least %u friends (%s)\n", | 1299 | "Topology would like %u connections with at least %u friends (%s)\n", |
1324 | target_connection_count, | 1300 | target_connection_count, minimum_friend_count, |
1325 | minimum_friend_count, | ||
1326 | autoconnect ? "autoconnect enabled" : "autoconnect disabled"); | 1301 | autoconnect ? "autoconnect enabled" : "autoconnect disabled"); |
1327 | #endif | 1302 | #endif |
1328 | if ((friend_count < minimum_friend_count) && (blacklist == NULL)) | 1303 | if ((friend_count < minimum_friend_count) && (blacklist == NULL)) |
1329 | blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_check, NULL); | 1304 | blacklist = GNUNET_TRANSPORT_blacklist (cfg, &blacklist_check, NULL); |
1330 | transport = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL, NULL, NULL); | 1305 | transport = GNUNET_TRANSPORT_connect (cfg, NULL, NULL, NULL, NULL, NULL); |
1331 | handle = GNUNET_CORE_connect (cfg, | 1306 | handle = |
1332 | 1, | 1307 | GNUNET_CORE_connect (cfg, 1, NULL, &core_init, &connect_notify, |
1333 | NULL, | 1308 | &disconnect_notify, NULL, NULL, GNUNET_NO, NULL, |
1334 | &core_init, | 1309 | GNUNET_NO, handlers); |
1335 | &connect_notify, | 1310 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleaning_task, |
1336 | &disconnect_notify, | 1311 | NULL); |
1337 | NULL, | ||
1338 | NULL, GNUNET_NO, NULL, GNUNET_NO, handlers); | ||
1339 | GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, | ||
1340 | &cleaning_task, NULL); | ||
1341 | if (NULL == transport) | 1312 | if (NULL == transport) |
1342 | { | 1313 | { |
1343 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 1314 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -1370,13 +1341,12 @@ main (int argc, char *const *argv) | |||
1370 | }; | 1341 | }; |
1371 | int ret; | 1342 | int ret; |
1372 | 1343 | ||
1373 | ret = (GNUNET_OK == | 1344 | ret = |
1374 | GNUNET_PROGRAM_run (argc, | 1345 | (GNUNET_OK == |
1375 | argv, | 1346 | GNUNET_PROGRAM_run (argc, argv, "gnunet-daemon-topology", |
1376 | "gnunet-daemon-topology", | 1347 | _ |
1377 | _ | 1348 | ("GNUnet topology control (maintaining P2P mesh and F2F constraints)"), |
1378 | ("GNUnet topology control (maintaining P2P mesh and F2F constraints)"), | 1349 | options, &run, NULL)) ? 0 : 1; |
1379 | options, &run, NULL)) ? 0 : 1; | ||
1380 | return ret; | 1350 | return ret; |
1381 | } | 1351 | } |
1382 | 1352 | ||