diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/dhtu/plugin_dhtu_gnunet.c | 55 | ||||
-rw-r--r-- | src/hello/hello-uri.c | 20 | ||||
-rw-r--r-- | src/topology/gnunet-daemon-topology.c | 109 | ||||
-rw-r--r-- | src/transport/gnunet-service-tng.c | 176 |
4 files changed, 255 insertions, 105 deletions
diff --git a/src/dhtu/plugin_dhtu_gnunet.c b/src/dhtu/plugin_dhtu_gnunet.c index 665db4545..aca641d4e 100644 --- a/src/dhtu/plugin_dhtu_gnunet.c +++ b/src/dhtu/plugin_dhtu_gnunet.c | |||
@@ -193,11 +193,29 @@ gnunet_try_connect (void *cls, | |||
193 | { | 193 | { |
194 | struct Plugin *plugin = cls; | 194 | struct Plugin *plugin = cls; |
195 | enum GNUNET_NetworkType nt = 0; | 195 | enum GNUNET_NetworkType nt = 0; |
196 | 196 | char *addr; | |
197 | const char *eou; | ||
198 | int pfx_len; | ||
199 | |||
200 | eou = strstr (address, | ||
201 | "://"); | ||
202 | if (NULL == eou) | ||
203 | { | ||
204 | GNUNET_break (0); | ||
205 | return; | ||
206 | } | ||
207 | pfx_len = eou - address; | ||
208 | eou += 3; | ||
209 | GNUNET_asprintf (&addr, | ||
210 | "%.*s-%s", | ||
211 | pfx_len, | ||
212 | address, | ||
213 | eou); | ||
197 | GNUNET_TRANSPORT_application_validate (plugin->transport, | 214 | GNUNET_TRANSPORT_application_validate (plugin->transport, |
198 | pid, | 215 | pid, |
199 | nt, | 216 | nt, |
200 | address); | 217 | addr); |
218 | GNUNET_free (addr); | ||
201 | } | 219 | } |
202 | 220 | ||
203 | 221 | ||
@@ -356,6 +374,22 @@ core_disconnect_cb (void *cls, | |||
356 | } | 374 | } |
357 | 375 | ||
358 | 376 | ||
377 | static void | ||
378 | add_addr (void *cls, | ||
379 | const char *addr) | ||
380 | { | ||
381 | struct Plugin *plugin = cls; | ||
382 | |||
383 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG , | ||
384 | "peerinfo_cb addr %s\n", | ||
385 | addr); | ||
386 | plugin->env->address_add_cb (plugin->env->cls, | ||
387 | addr, | ||
388 | &plugin->src, | ||
389 | &plugin->src.app_ctx); | ||
390 | } | ||
391 | |||
392 | |||
359 | /** | 393 | /** |
360 | * Find the @a hello for our identity and then pass | 394 | * Find the @a hello for our identity and then pass |
361 | * it to the DHT as a URL. Note that we only | 395 | * it to the DHT as a URL. Note that we only |
@@ -387,16 +421,11 @@ peerinfo_cb (void *cls, | |||
387 | &plugin->my_identity)) | 421 | &plugin->my_identity)) |
388 | return; | 422 | return; |
389 | builder = GNUNET_HELLO_builder_from_msg (hello); | 423 | builder = GNUNET_HELLO_builder_from_msg (hello); |
390 | addr = GNUNET_HELLO_builder_to_url (builder, | 424 | GNUNET_HELLO_builder_iterate (builder, |
391 | plugin->my_priv); | 425 | (struct GNUNET_PeerIdentity *) peer, |
392 | if (NULL == addr) | 426 | add_addr, |
393 | return; | 427 | plugin); |
394 | plugin->env->address_add_cb (plugin->env->cls, | 428 | GNUNET_HELLO_builder_free (builder); |
395 | addr, | ||
396 | &plugin->src, | ||
397 | &plugin->src.app_ctx); | ||
398 | GNUNET_free (addr); | ||
399 | GNUNET_HELLO_Builder_free (builder); | ||
400 | } | 429 | } |
401 | 430 | ||
402 | 431 | ||
@@ -515,7 +544,7 @@ libgnunet_plugin_dhtu_gnunet_done (void *cls) | |||
515 | if (NULL != plugin->peerstore_notify) | 544 | if (NULL != plugin->peerstore_notify) |
516 | GNUNET_PEERSTORE_hello_changed_notify_cancel (plugin->peerstore_notify); | 545 | GNUNET_PEERSTORE_hello_changed_notify_cancel (plugin->peerstore_notify); |
517 | if (NULL != plugin->peerstore) | 546 | if (NULL != plugin->peerstore) |
518 | GNUNET_PEERSTORE_disconnect (peerstore, GNUNET_YES); | 547 | GNUNET_PEERSTORE_disconnect (plugin->peerstore, GNUNET_YES); |
519 | GPI_plugins_unload (); | 548 | GPI_plugins_unload (); |
520 | GNUNET_free (plugin->my_priv); | 549 | GNUNET_free (plugin->my_priv); |
521 | GNUNET_free (plugin); | 550 | GNUNET_free (plugin); |
diff --git a/src/hello/hello-uri.c b/src/hello/hello-uri.c index fb35ee353..4a8591ed1 100644 --- a/src/hello/hello-uri.c +++ b/src/hello/hello-uri.c | |||
@@ -446,12 +446,24 @@ GNUNET_HELLO_builder_from_block (const void *block, | |||
446 | 446 | ||
447 | 447 | ||
448 | struct GNUNET_TIME_Absolute | 448 | struct GNUNET_TIME_Absolute |
449 | GNUNET_HELLO_builder_get_expiration_time (struct GNUNET_HELLO_Builder *builder, | 449 | GNUNET_HELLO_builder_get_expiration_time (const struct |
450 | const struct GNUNET_MessageHeader *msg) | 450 | GNUNET_MessageHeader *msg) |
451 | { | 451 | { |
452 | struct BlockHeader *bh = (struct BlockHeader *) &msg[1]; | 452 | if (GNUNET_MESSAGE_TYPE_HELLO_URI == ntohs (msg->type)) |
453 | { | ||
454 | const struct HelloUriMessage *h = (struct HelloUriMessage *) msg; | ||
455 | const struct BlockHeader *bh = (const struct BlockHeader *) &h[1]; | ||
456 | |||
457 | return GNUNET_TIME_absolute_ntoh (bh->expiration_time); | ||
458 | } | ||
459 | else if (GNUNET_MESSAGE_TYPE_DHT_P2P_HELLO == ntohs (msg->type)) | ||
460 | { | ||
461 | const struct DhtHelloMessage *dht_hello = (struct DhtHelloMessage *) msg; | ||
453 | 462 | ||
454 | return GNUNET_TIME_absolute_ntoh (bh->expiration_time); | 463 | return GNUNET_TIME_absolute_ntoh (dht_hello->expiration_time); |
464 | } | ||
465 | else | ||
466 | GNUNET_break (0); | ||
455 | } | 467 | } |
456 | 468 | ||
457 | 469 | ||
diff --git a/src/topology/gnunet-daemon-topology.c b/src/topology/gnunet-daemon-topology.c index b28269a77..efe014776 100644 --- a/src/topology/gnunet-daemon-topology.c +++ b/src/topology/gnunet-daemon-topology.c | |||
@@ -126,6 +126,13 @@ struct Peer | |||
126 | 126 | ||
127 | 127 | ||
128 | /** | 128 | /** |
129 | * The task to delayed start the notification process intially. | ||
130 | * We like to give transport some time to give us our hello to distribute it. | ||
131 | */ | ||
132 | struct GNUNET_SCHEDULER_Task *peerstore_notify_task; | ||
133 | |||
134 | |||
135 | /** | ||
129 | * Our peerstore notification context. We use notification | 136 | * Our peerstore notification context. We use notification |
130 | * to instantly learn about new peers as they are discovered. | 137 | * to instantly learn about new peers as they are discovered. |
131 | */ | 138 | */ |
@@ -353,8 +360,8 @@ make_peer (const struct GNUNET_PeerIdentity *peer, | |||
353 | ret->is_friend = is_friend; | 360 | ret->is_friend = is_friend; |
354 | if (NULL != hello) | 361 | if (NULL != hello) |
355 | { | 362 | { |
356 | ret->hello = GNUNET_malloc (sizeof (hello)); | 363 | ret->hello = GNUNET_malloc (ntohs (hello->size)); |
357 | GNUNET_memcpy (ret->hello, hello, sizeof (hello)); | 364 | GNUNET_memcpy (ret->hello, hello, ntohs (hello->size)); |
358 | } | 365 | } |
359 | GNUNET_break (GNUNET_OK == | 366 | GNUNET_break (GNUNET_OK == |
360 | GNUNET_CONTAINER_multipeermap_put ( | 367 | GNUNET_CONTAINER_multipeermap_put ( |
@@ -504,10 +511,11 @@ schedule_next_hello (void *cls) | |||
504 | 511 | ||
505 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 512 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
506 | "schedule_next_hello 3\n"); | 513 | "schedule_next_hello 3\n"); |
507 | want = fah.result->hello->size; | 514 | want = ntohs (fah.result->hello->size); |
508 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 515 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
509 | "Sending HELLO with %u bytes", | 516 | "Sending HELLO with %u bytes for peer %s\n", |
510 | (unsigned int) want); | 517 | (unsigned int) want, |
518 | GNUNET_i2s (&pl->pid)); | ||
511 | env = GNUNET_MQ_msg_copy (fah.result->hello); | 519 | env = GNUNET_MQ_msg_copy (fah.result->hello); |
512 | GNUNET_MQ_send (pl->mq, env); | 520 | GNUNET_MQ_send (pl->mq, env); |
513 | 521 | ||
@@ -543,14 +551,12 @@ reschedule_hellos (void *cls, | |||
543 | const struct GNUNET_PeerIdentity *pid, | 551 | const struct GNUNET_PeerIdentity *pid, |
544 | void *value) | 552 | void *value) |
545 | { | 553 | { |
554 | (void *) cls; | ||
546 | struct Peer *peer = value; | 555 | struct Peer *peer = value; |
547 | struct Peer *skip = cls; | ||
548 | 556 | ||
549 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 557 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
550 | "Reschedule for `%s'\n", | 558 | "Reschedule for `%s'\n", |
551 | GNUNET_i2s (&peer->pid)); | 559 | GNUNET_i2s (&peer->pid)); |
552 | if (skip == peer) | ||
553 | return GNUNET_YES; | ||
554 | if (NULL == peer->mq) | 560 | if (NULL == peer->mq) |
555 | return GNUNET_YES; | 561 | return GNUNET_YES; |
556 | if (NULL != peer->hello_delay_task) | 562 | if (NULL != peer->hello_delay_task) |
@@ -712,7 +718,8 @@ address_iterator (void *cls, | |||
712 | { | 718 | { |
713 | int *flag = cls; | 719 | int *flag = cls; |
714 | 720 | ||
715 | *flag = GNUNET_YES; | 721 | *flag = *flag + 1; |
722 | //*flag = GNUNET_YES; | ||
716 | } | 723 | } |
717 | 724 | ||
718 | 725 | ||
@@ -725,57 +732,76 @@ address_iterator (void *cls, | |||
725 | static void | 732 | static void |
726 | consider_for_advertising (const struct GNUNET_MessageHeader *hello) | 733 | consider_for_advertising (const struct GNUNET_MessageHeader *hello) |
727 | { | 734 | { |
728 | int have_address; | 735 | int num_addresses_old; |
736 | int num_addresses_new; | ||
729 | struct GNUNET_HELLO_Builder *builder = GNUNET_HELLO_builder_from_msg (hello); | 737 | struct GNUNET_HELLO_Builder *builder = GNUNET_HELLO_builder_from_msg (hello); |
730 | struct GNUNET_PeerIdentity *pid; | 738 | struct GNUNET_PeerIdentity *pid = GNUNET_HELLO_builder_get_id (builder); |
731 | struct GNUNET_TIME_Absolute dt; | 739 | struct GNUNET_TIME_Absolute dt; |
732 | struct GNUNET_MQ_Envelope *env; | 740 | struct GNUNET_MQ_Envelope *env; |
733 | const struct GNUNET_MessageHeader *nh; | 741 | const struct GNUNET_MessageHeader *nh; |
734 | struct Peer *peer; | 742 | struct Peer *peer; |
735 | uint16_t size; | 743 | uint16_t size; |
736 | 744 | ||
737 | have_address = GNUNET_NO; | ||
738 | GNUNET_HELLO_builder_iterate (builder, | 745 | GNUNET_HELLO_builder_iterate (builder, |
739 | pid, | 746 | pid, |
740 | &address_iterator, | 747 | &address_iterator, |
741 | &have_address); | 748 | &num_addresses_new); |
742 | if (GNUNET_NO == have_address) | 749 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
750 | "consider 0 for %s\n", | ||
751 | GNUNET_i2s (pid)); | ||
752 | if (0 == num_addresses_new) | ||
753 | { | ||
754 | GNUNET_HELLO_builder_free (builder); | ||
743 | return; /* no point in advertising this one... */ | 755 | return; /* no point in advertising this one... */ |
744 | if (NULL == pid || 0 == GNUNET_memcmp (pid, &my_identity)) | 756 | } |
745 | return; /* that's me! */ | 757 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
746 | 758 | "consider 1\n"); | |
759 | if (NULL == pid) | ||
760 | { | ||
761 | GNUNET_HELLO_builder_free (builder); | ||
762 | return; | ||
763 | } | ||
764 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
765 | "consider 2\n"); | ||
747 | peer = GNUNET_CONTAINER_multipeermap_get (peers, pid); | 766 | peer = GNUNET_CONTAINER_multipeermap_get (peers, pid); |
748 | if (NULL == peer) | 767 | if (NULL == peer) |
749 | { | 768 | { |
750 | peer = make_peer (pid, hello, GNUNET_NO); | 769 | peer = make_peer (pid, hello, GNUNET_NO); |
751 | } | 770 | } |
752 | 771 | else if (NULL != peer->hello) | |
753 | if (NULL != peer->hello) | ||
754 | { | 772 | { |
755 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); | 773 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); |
756 | struct GNUNET_TIME_Absolute new_hello_exp = GNUNET_HELLO_builder_get_expiration_time (builder, | 774 | struct GNUNET_TIME_Absolute new_hello_exp = |
757 | hello); | 775 | GNUNET_HELLO_builder_get_expiration_time (hello); |
758 | struct GNUNET_HELLO_Builder *peer_builder = GNUNET_HELLO_builder_from_msg (peer->hello); | 776 | struct GNUNET_TIME_Absolute old_hello_exp = |
759 | struct GNUNET_TIME_Absolute old_hello_exp = GNUNET_HELLO_builder_get_expiration_time (peer_builder, | 777 | GNUNET_HELLO_builder_get_expiration_time (peer->hello); |
760 | peer->hello); | 778 | struct GNUNET_HELLO_Builder *builder_old = GNUNET_HELLO_builder_from_msg (peer->hello); |
761 | 779 | struct GNUNET_PeerIdentity *pid_old = GNUNET_HELLO_builder_get_id (builder_old); | |
762 | if (GNUNET_TIME_absolute_cmp (new_hello_exp, > , now) && GNUNET_TIME_absolute_cmp (new_hello_exp, > , old_hello_exp)) | 780 | |
781 | GNUNET_HELLO_builder_iterate (builder_old, | ||
782 | pid_old, | ||
783 | &address_iterator, | ||
784 | &num_addresses_old); | ||
785 | if (GNUNET_TIME_absolute_cmp (new_hello_exp, >, now) && | ||
786 | (GNUNET_TIME_absolute_cmp (new_hello_exp, >, old_hello_exp) || | ||
787 | num_addresses_old < num_addresses_new)) | ||
763 | { | 788 | { |
764 | GNUNET_free (peer->hello); | 789 | GNUNET_free (peer->hello); |
765 | size = sizeof (hello); | 790 | size = ntohs (hello->size); |
766 | peer->hello = GNUNET_malloc (size); | 791 | peer->hello = GNUNET_malloc (size); |
767 | GNUNET_memcpy (peer->hello, hello, size); | 792 | GNUNET_memcpy (peer->hello, hello, size); |
768 | } | 793 | } |
769 | else | 794 | else |
770 | { | 795 | { |
796 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
797 | "consider 3\n"); | ||
798 | GNUNET_HELLO_builder_free (builder); | ||
771 | return; | 799 | return; |
772 | } | 800 | } |
773 | GNUNET_HELLO_builder_free (builder); | ||
774 | GNUNET_HELLO_builder_free (peer_builder); | ||
775 | } | 801 | } |
776 | else | 802 | else |
777 | { | 803 | { |
778 | size = sizeof (hello); | 804 | size = ntohs (hello->size); |
779 | peer->hello = GNUNET_malloc (size); | 805 | peer->hello = GNUNET_malloc (size); |
780 | GNUNET_memcpy (peer->hello, hello, size); | 806 | GNUNET_memcpy (peer->hello, hello, size); |
781 | } | 807 | } |
@@ -790,7 +816,8 @@ consider_for_advertising (const struct GNUNET_MessageHeader *hello) | |||
790 | setup_filter (peer); | 816 | setup_filter (peer); |
791 | /* since we have a new HELLO to pick from, re-schedule all | 817 | /* since we have a new HELLO to pick from, re-schedule all |
792 | * HELLO requests that are not bound by the HELLO send rate! */ | 818 | * HELLO requests that are not bound by the HELLO send rate! */ |
793 | GNUNET_CONTAINER_multipeermap_iterate (peers, &reschedule_hellos, peer); | 819 | GNUNET_CONTAINER_multipeermap_iterate (peers, &reschedule_hellos, NULL); |
820 | GNUNET_HELLO_builder_free (builder); | ||
794 | } | 821 | } |
795 | 822 | ||
796 | 823 | ||
@@ -823,8 +850,6 @@ process_peer (void *cls, | |||
823 | return; | 850 | return; |
824 | } | 851 | } |
825 | GNUNET_assert (NULL != peer); | 852 | GNUNET_assert (NULL != peer); |
826 | if (0 == GNUNET_memcmp (&my_identity, peer)) | ||
827 | return; /* that's me! */ | ||
828 | if (NULL == hello) | 853 | if (NULL == hello) |
829 | { | 854 | { |
830 | /* free existing HELLO, if any */ | 855 | /* free existing HELLO, if any */ |
@@ -850,6 +875,15 @@ process_peer (void *cls, | |||
850 | attempt_connect (pos); | 875 | attempt_connect (pos); |
851 | } | 876 | } |
852 | 877 | ||
878 | static void | ||
879 | start_notify (void *cls) | ||
880 | { | ||
881 | (void *) cls; | ||
882 | |||
883 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Starting to process new hellos for gossiping.\n"); | ||
884 | peerstore_notify = | ||
885 | GNUNET_PEERSTORE_hello_changed_notify (ps, GNUNET_NO, &process_peer, NULL); | ||
886 | } | ||
853 | 887 | ||
854 | /** | 888 | /** |
855 | * Function called after #GNUNET_CORE_connect has succeeded | 889 | * Function called after #GNUNET_CORE_connect has succeeded |
@@ -871,8 +905,9 @@ core_init (void *cls, const struct GNUNET_PeerIdentity *my_id) | |||
871 | } | 905 | } |
872 | my_identity = *my_id; | 906 | my_identity = *my_id; |
873 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I am peer `%s'\n", GNUNET_i2s (my_id)); | 907 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I am peer `%s'\n", GNUNET_i2s (my_id)); |
874 | peerstore_notify = | 908 | peerstore_notify_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_MINUTES, |
875 | GNUNET_PEERSTORE_hello_changed_notify (ps, GNUNET_NO, &process_peer, NULL); | 909 | start_notify, |
910 | NULL); | ||
876 | } | 911 | } |
877 | 912 | ||
878 | 913 | ||
@@ -1030,6 +1065,10 @@ cleaning_task (void *cls) | |||
1030 | GNUNET_PEERSTORE_hello_changed_notify_cancel (peerstore_notify); | 1065 | GNUNET_PEERSTORE_hello_changed_notify_cancel (peerstore_notify); |
1031 | peerstore_notify = NULL; | 1066 | peerstore_notify = NULL; |
1032 | } | 1067 | } |
1068 | else if (NULL != peerstore_notify_task) | ||
1069 | { | ||
1070 | GNUNET_SCHEDULER_cancel (peerstore_notify_task); | ||
1071 | } | ||
1033 | if (NULL != handle) | 1072 | if (NULL != handle) |
1034 | { | 1073 | { |
1035 | GNUNET_CORE_disconnect (handle); | 1074 | GNUNET_CORE_disconnect (handle); |
diff --git a/src/transport/gnunet-service-tng.c b/src/transport/gnunet-service-tng.c index 5f2504c70..69dab525a 100644 --- a/src/transport/gnunet-service-tng.c +++ b/src/transport/gnunet-service-tng.c | |||
@@ -2045,9 +2045,9 @@ struct IncomingRequest | |||
2045 | struct IncomingRequest *prev; | 2045 | struct IncomingRequest *prev; |
2046 | 2046 | ||
2047 | /** | 2047 | /** |
2048 | * Handle for watching the peerstore for HELLOs for this peer. | 2048 | * Notify context for new HELLOs. |
2049 | */ | 2049 | */ |
2050 | struct GNUNET_PEERSTORE_WatchContext *wc; | 2050 | struct GNUNET_PEERSTORE_NotifyContext *nc; |
2051 | 2051 | ||
2052 | /** | 2052 | /** |
2053 | * Which peer is this about? | 2053 | * Which peer is this about? |
@@ -2072,9 +2072,9 @@ struct PeerRequest | |||
2072 | struct TransportClient *tc; | 2072 | struct TransportClient *tc; |
2073 | 2073 | ||
2074 | /** | 2074 | /** |
2075 | * Handle for watching the peerstore for HELLOs for this peer. | 2075 | * Notify context for new HELLOs. |
2076 | */ | 2076 | */ |
2077 | struct GNUNET_PEERSTORE_WatchContext *wc; | 2077 | struct GNUNET_PEERSTORE_NotifyContext *nc; |
2078 | 2078 | ||
2079 | /** | 2079 | /** |
2080 | * What kind of performance preference does this @e tc have? | 2080 | * What kind of performance preference does this @e tc have? |
@@ -2924,8 +2924,8 @@ free_incoming_request (struct IncomingRequest *ir) | |||
2924 | GNUNET_CONTAINER_DLL_remove (ir_head, ir_tail, ir); | 2924 | GNUNET_CONTAINER_DLL_remove (ir_head, ir_tail, ir); |
2925 | GNUNET_assert (ir_total > 0); | 2925 | GNUNET_assert (ir_total > 0); |
2926 | ir_total--; | 2926 | ir_total--; |
2927 | GNUNET_PEERSTORE_watch_cancel (ir->wc); | 2927 | GNUNET_PEERSTORE_hello_changed_notify_cancel (ir->nc); |
2928 | ir->wc = NULL; | 2928 | ir->nc = NULL; |
2929 | GNUNET_free (ir); | 2929 | GNUNET_free (ir); |
2930 | } | 2930 | } |
2931 | 2931 | ||
@@ -3902,8 +3902,8 @@ stop_peer_request (void *cls, | |||
3902 | struct TransportClient *tc = cls; | 3902 | struct TransportClient *tc = cls; |
3903 | struct PeerRequest *pr = value; | 3903 | struct PeerRequest *pr = value; |
3904 | 3904 | ||
3905 | GNUNET_PEERSTORE_watch_cancel (pr->wc); | 3905 | GNUNET_PEERSTORE_hello_changed_notify_cancel (pr->nc); |
3906 | pr->wc = NULL; | 3906 | pr->nc = NULL; |
3907 | GNUNET_assert ( | 3907 | GNUNET_assert ( |
3908 | GNUNET_YES == | 3908 | GNUNET_YES == |
3909 | GNUNET_CONTAINER_multipeermap_remove (tc->details.application.requests, | 3909 | GNUNET_CONTAINER_multipeermap_remove (tc->details.application.requests, |
@@ -4021,8 +4021,12 @@ notify_client_connect_info (void *cls, | |||
4021 | void *value) | 4021 | void *value) |
4022 | { | 4022 | { |
4023 | struct TransportClient *tc = cls; | 4023 | struct TransportClient *tc = cls; |
4024 | struct Neighbour *n = value; | ||
4025 | struct VirtualLink *vl = n->vl; | ||
4026 | |||
4027 | if ((NULL == vl) || (GNUNET_NO == vl->confirmed)) | ||
4028 | return GNUNET_OK; | ||
4024 | 4029 | ||
4025 | (void) value; | ||
4026 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 4030 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
4027 | "Telling new CORE client about existing connection to %s\n", | 4031 | "Telling new CORE client about existing connection to %s\n", |
4028 | GNUNET_i2s (pid)); | 4032 | GNUNET_i2s (pid)); |
@@ -5545,8 +5549,17 @@ store_pi (void *cls) | |||
5545 | struct GNUNET_TIME_Absolute expiration; | 5549 | struct GNUNET_TIME_Absolute expiration; |
5546 | enum GNUNET_GenericReturnValue add_result; | 5550 | enum GNUNET_GenericReturnValue add_result; |
5547 | struct GNUNET_MQ_Envelope *env; | 5551 | struct GNUNET_MQ_Envelope *env; |
5548 | const struct GNUNET_MessageHeader *msg = GNUNET_MQ_env_get_msg (env); | 5552 | const struct GNUNET_MessageHeader *msg; |
5549 | 5553 | const char *dash; | |
5554 | char *prefix = GNUNET_HELLO_address_to_prefix (ale->address); | ||
5555 | char *address_uri; | ||
5556 | |||
5557 | dash = strchr (ale->address, '-'); | ||
5558 | dash++; | ||
5559 | GNUNET_asprintf (&address_uri, | ||
5560 | "%s://%s", | ||
5561 | prefix, | ||
5562 | dash); | ||
5550 | ale->st = NULL; | 5563 | ale->st = NULL; |
5551 | expiration = GNUNET_TIME_relative_to_absolute (ale->expiration); | 5564 | expiration = GNUNET_TIME_relative_to_absolute (ale->expiration); |
5552 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 5565 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -5554,19 +5567,23 @@ store_pi (void *cls) | |||
5554 | ale->address, | 5567 | ale->address, |
5555 | GNUNET_STRINGS_absolute_time_to_string (expiration)); | 5568 | GNUNET_STRINGS_absolute_time_to_string (expiration)); |
5556 | add_result = GNUNET_HELLO_builder_add_address (GST_my_hello, | 5569 | add_result = GNUNET_HELLO_builder_add_address (GST_my_hello, |
5557 | ale->address); | 5570 | address_uri); |
5558 | env = GNUNET_HELLO_builder_to_env (GST_my_hello, | 5571 | env = GNUNET_HELLO_builder_to_env (GST_my_hello, |
5559 | GST_my_private_key, | 5572 | GST_my_private_key, |
5560 | GNUNET_TIME_UNIT_ZERO); | 5573 | GNUNET_TIME_UNIT_ZERO); |
5574 | msg = GNUNET_MQ_env_get_msg (env); | ||
5575 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
5576 | "store_pi 1\n"); | ||
5561 | if (GNUNET_YES == add_result) | 5577 | if (GNUNET_YES == add_result) |
5562 | shc = GNUNET_PEERSTORE_hello_add (peerstore, | 5578 | shc = GNUNET_PEERSTORE_hello_add (peerstore, |
5563 | msg, | 5579 | msg, |
5564 | shc_cont, | 5580 | shc_cont, |
5565 | shc); | 5581 | shc); |
5566 | else if (GNUNET_SYSERR == add_result) | 5582 | else if (GNUNET_SYSERR == add_result) |
5567 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 5583 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
5568 | "Error adding address to peerstore hello!\n"); | 5584 | "Error adding address to peerstore hello!\n"); |
5569 | 5585 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | |
5586 | "store_pi 2\n"); | ||
5570 | GNUNET_HELLO_sign_address (ale->address, | 5587 | GNUNET_HELLO_sign_address (ale->address, |
5571 | ale->nt, | 5588 | ale->nt, |
5572 | hello_mono_time, | 5589 | hello_mono_time, |
@@ -5585,6 +5602,8 @@ store_pi (void *cls) | |||
5585 | ale); | 5602 | ale); |
5586 | GNUNET_free (addr); | 5603 | GNUNET_free (addr); |
5587 | GNUNET_free (env); | 5604 | GNUNET_free (env); |
5605 | GNUNET_free (prefix); | ||
5606 | GNUNET_free (address_uri); | ||
5588 | if (NULL == ale->sc) | 5607 | if (NULL == ale->sc) |
5589 | { | 5608 | { |
5590 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 5609 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
@@ -8633,6 +8652,34 @@ start_address_validation (const struct GNUNET_PeerIdentity *pid, | |||
8633 | } | 8652 | } |
8634 | 8653 | ||
8635 | 8654 | ||
8655 | static void | ||
8656 | hello_for_incoming_cb (void *cls, | ||
8657 | const char *uri) | ||
8658 | { | ||
8659 | const struct GNUNET_PeerIdentity *peer = cls; | ||
8660 | int pfx_len; | ||
8661 | const char *eou; | ||
8662 | char *address; | ||
8663 | |||
8664 | eou = strstr (uri, | ||
8665 | "://"); | ||
8666 | pfx_len = eou - uri; | ||
8667 | eou += 3; | ||
8668 | GNUNET_asprintf (&address, | ||
8669 | "%.*s-%s", | ||
8670 | pfx_len, | ||
8671 | uri, | ||
8672 | eou); | ||
8673 | |||
8674 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
8675 | "helo for client %s\n", | ||
8676 | address); | ||
8677 | |||
8678 | start_address_validation (peer, address); | ||
8679 | GNUNET_free (address); | ||
8680 | } | ||
8681 | |||
8682 | |||
8636 | /** | 8683 | /** |
8637 | * Function called by PEERSTORE for each matching record. | 8684 | * Function called by PEERSTORE for each matching record. |
8638 | * | 8685 | * |
@@ -8642,11 +8689,12 @@ start_address_validation (const struct GNUNET_PeerIdentity *pid, | |||
8642 | */ | 8689 | */ |
8643 | static void | 8690 | static void |
8644 | handle_hello_for_incoming (void *cls, | 8691 | handle_hello_for_incoming (void *cls, |
8645 | const struct GNUNET_PEERSTORE_Record *record, | 8692 | const struct GNUNET_PeerIdentity *peer, |
8693 | const struct GNUNET_MessageHeader *hello, | ||
8646 | const char *emsg) | 8694 | const char *emsg) |
8647 | { | 8695 | { |
8648 | struct IncomingRequest *ir = cls; | 8696 | struct IncomingRequest *ir = cls; |
8649 | const char *val; | 8697 | struct GNUNET_HELLO_Builder *builder; |
8650 | 8698 | ||
8651 | if (NULL != emsg) | 8699 | if (NULL != emsg) |
8652 | { | 8700 | { |
@@ -8655,13 +8703,13 @@ handle_hello_for_incoming (void *cls, | |||
8655 | emsg); | 8703 | emsg); |
8656 | return; | 8704 | return; |
8657 | } | 8705 | } |
8658 | val = record->value; | 8706 | if (0 == GNUNET_memcmp (peer, &GST_my_identity)) |
8659 | if ((0 == record->value_size) || ('\0' != val[record->value_size - 1])) | ||
8660 | { | ||
8661 | GNUNET_break (0); | ||
8662 | return; | 8707 | return; |
8663 | } | 8708 | builder = GNUNET_HELLO_builder_new (peer); |
8664 | start_address_validation (&ir->pid, (const char *) record->value); | 8709 | GNUNET_HELLO_builder_iterate (builder, |
8710 | (struct GNUNET_PeerIdentity *) peer, | ||
8711 | hello_for_incoming_cb, | ||
8712 | (struct GNUNET_PeerIdentity *) peer); | ||
8665 | } | 8713 | } |
8666 | 8714 | ||
8667 | 8715 | ||
@@ -8762,12 +8810,11 @@ handle_validation_challenge ( | |||
8762 | ir = GNUNET_new (struct IncomingRequest); | 8810 | ir = GNUNET_new (struct IncomingRequest); |
8763 | ir->pid = sender; | 8811 | ir->pid = sender; |
8764 | GNUNET_CONTAINER_DLL_insert (ir_head, ir_tail, ir); | 8812 | GNUNET_CONTAINER_DLL_insert (ir_head, ir_tail, ir); |
8765 | ir->wc = GNUNET_PEERSTORE_watch (peerstore, | 8813 | |
8766 | "transport", | 8814 | ir->nc = GNUNET_PEERSTORE_hello_changed_notify (peerstore, |
8767 | &ir->pid, | 8815 | GNUNET_NO, |
8768 | GNUNET_PEERSTORE_HELLO_KEY, | 8816 | &handle_hello_for_incoming, |
8769 | &handle_hello_for_incoming, | 8817 | NULL); |
8770 | ir); | ||
8771 | ir_total++; | 8818 | ir_total++; |
8772 | /* Bound attempts we do in parallel here, might otherwise get excessive */ | 8819 | /* Bound attempts we do in parallel here, might otherwise get excessive */ |
8773 | while (ir_total > MAX_INCOMING_REQUEST) | 8820 | while (ir_total > MAX_INCOMING_REQUEST) |
@@ -8789,8 +8836,6 @@ struct CheckKnownChallengeContext | |||
8789 | * Set to a matching validation state, if one was found. | 8836 | * Set to a matching validation state, if one was found. |
8790 | */ | 8837 | */ |
8791 | struct ValidationState *vs; | 8838 | struct ValidationState *vs; |
8792 | |||
8793 | char *address_prefix; | ||
8794 | }; | 8839 | }; |
8795 | 8840 | ||
8796 | 8841 | ||
@@ -8812,8 +8857,7 @@ check_known_challenge (void *cls, | |||
8812 | struct ValidationState *vs = value; | 8857 | struct ValidationState *vs = value; |
8813 | 8858 | ||
8814 | (void) pid; | 8859 | (void) pid; |
8815 | if (0 != GNUNET_memcmp (&vs->challenge, ckac->challenge) || | 8860 | if (0 != GNUNET_memcmp (&vs->challenge, ckac->challenge)) |
8816 | NULL == strstr (vs->address, ckac->address_prefix)) | ||
8817 | return GNUNET_OK; | 8861 | return GNUNET_OK; |
8818 | ckac->vs = vs; | 8862 | ckac->vs = vs; |
8819 | return GNUNET_NO; | 8863 | return GNUNET_NO; |
@@ -8883,14 +8927,12 @@ handle_validation_response ( | |||
8883 | struct CommunicatorMessageContext *cmc = cls; | 8927 | struct CommunicatorMessageContext *cmc = cls; |
8884 | struct ValidationState *vs; | 8928 | struct ValidationState *vs; |
8885 | struct CheckKnownChallengeContext ckac = { .challenge = &tvr->challenge, | 8929 | struct CheckKnownChallengeContext ckac = { .challenge = &tvr->challenge, |
8886 | .vs = NULL, | 8930 | .vs = NULL}; |
8887 | .address_prefix = | ||
8888 | cmc->tc->details.communicator. | ||
8889 | address_prefix}; | ||
8890 | struct GNUNET_TIME_Absolute origin_time; | 8931 | struct GNUNET_TIME_Absolute origin_time; |
8891 | struct Queue *q; | 8932 | struct Queue *q; |
8892 | struct Neighbour *n; | 8933 | struct Neighbour *n; |
8893 | struct VirtualLink *vl; | 8934 | struct VirtualLink *vl; |
8935 | const struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get_monotonic (GST_cfg); | ||
8894 | 8936 | ||
8895 | /* check this is one of our challenges */ | 8937 | /* check this is one of our challenges */ |
8896 | (void) GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, | 8938 | (void) GNUNET_CONTAINER_multipeermap_get_multiple (validation_map, |
@@ -11210,6 +11252,34 @@ handle_suggest_cancel (void *cls, const struct ExpressPreferenceMessage *msg) | |||
11210 | } | 11252 | } |
11211 | 11253 | ||
11212 | 11254 | ||
11255 | static void | ||
11256 | hello_for_client_cb (void *cls, | ||
11257 | const char *uri) | ||
11258 | { | ||
11259 | const struct GNUNET_PeerIdentity *peer = cls; | ||
11260 | int pfx_len; | ||
11261 | const char *eou; | ||
11262 | char *address; | ||
11263 | |||
11264 | eou = strstr (uri, | ||
11265 | "://"); | ||
11266 | pfx_len = eou - uri; | ||
11267 | eou += 3; | ||
11268 | GNUNET_asprintf (&address, | ||
11269 | "%.*s-%s", | ||
11270 | pfx_len, | ||
11271 | uri, | ||
11272 | eou); | ||
11273 | |||
11274 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
11275 | "hello for client %s\n", | ||
11276 | address); | ||
11277 | |||
11278 | start_address_validation (peer, address); | ||
11279 | GNUNET_free (address); | ||
11280 | } | ||
11281 | |||
11282 | |||
11213 | /** | 11283 | /** |
11214 | * Function called by PEERSTORE for each matching record. | 11284 | * Function called by PEERSTORE for each matching record. |
11215 | * | 11285 | * |
@@ -11219,11 +11289,13 @@ handle_suggest_cancel (void *cls, const struct ExpressPreferenceMessage *msg) | |||
11219 | */ | 11289 | */ |
11220 | static void | 11290 | static void |
11221 | handle_hello_for_client (void *cls, | 11291 | handle_hello_for_client (void *cls, |
11222 | const struct GNUNET_PEERSTORE_Record *record, | 11292 | const struct GNUNET_PeerIdentity *peer, |
11293 | const struct GNUNET_MessageHeader *hello, | ||
11223 | const char *emsg) | 11294 | const char *emsg) |
11224 | { | 11295 | { |
11225 | struct PeerRequest *pr = cls; | 11296 | (void *) cls; |
11226 | const char *val; | 11297 | const char *val; |
11298 | struct GNUNET_HELLO_Builder *builder; | ||
11227 | 11299 | ||
11228 | if (NULL != emsg) | 11300 | if (NULL != emsg) |
11229 | { | 11301 | { |
@@ -11232,13 +11304,13 @@ handle_hello_for_client (void *cls, | |||
11232 | emsg); | 11304 | emsg); |
11233 | return; | 11305 | return; |
11234 | } | 11306 | } |
11235 | val = record->value; | 11307 | if (0 == GNUNET_memcmp (peer, &GST_my_identity)) |
11236 | if ((0 == record->value_size) || ('\0' != val[record->value_size - 1])) | ||
11237 | { | ||
11238 | GNUNET_break (0); | ||
11239 | return; | 11308 | return; |
11240 | } | 11309 | builder = GNUNET_HELLO_builder_new (peer); |
11241 | start_address_validation (&pr->pid, (const char *) record->value); | 11310 | GNUNET_HELLO_builder_iterate (builder, |
11311 | (struct GNUNET_PeerIdentity *) peer, | ||
11312 | hello_for_client_cb, | ||
11313 | NULL); | ||
11242 | } | 11314 | } |
11243 | 11315 | ||
11244 | 11316 | ||
@@ -11288,12 +11360,10 @@ handle_suggest (void *cls, const struct ExpressPreferenceMessage *msg) | |||
11288 | GNUNET_SERVICE_client_drop (tc->client); | 11360 | GNUNET_SERVICE_client_drop (tc->client); |
11289 | return; | 11361 | return; |
11290 | } | 11362 | } |
11291 | pr->wc = GNUNET_PEERSTORE_watch (peerstore, | 11363 | pr->nc = GNUNET_PEERSTORE_hello_changed_notify (peerstore, |
11292 | "transport", | 11364 | GNUNET_NO, |
11293 | &pr->pid, | 11365 | &handle_hello_for_client, |
11294 | GNUNET_PEERSTORE_HELLO_KEY, | 11366 | NULL); |
11295 | &handle_hello_for_client, | ||
11296 | pr); | ||
11297 | GNUNET_SERVICE_client_continue (tc->client); | 11367 | GNUNET_SERVICE_client_continue (tc->client); |
11298 | } | 11368 | } |
11299 | 11369 | ||
@@ -11592,7 +11662,6 @@ run (void *cls, | |||
11592 | GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); | 11662 | GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); |
11593 | GST_my_private_key = | 11663 | GST_my_private_key = |
11594 | GNUNET_CRYPTO_eddsa_key_create_from_configuration (GST_cfg); | 11664 | GNUNET_CRYPTO_eddsa_key_create_from_configuration (GST_cfg); |
11595 | GST_my_hello = GNUNET_HELLO_builder_new (&GST_my_identity); | ||
11596 | if (NULL == GST_my_private_key) | 11665 | if (NULL == GST_my_private_key) |
11597 | { | 11666 | { |
11598 | GNUNET_log ( | 11667 | GNUNET_log ( |
@@ -11607,6 +11676,7 @@ run (void *cls, | |||
11607 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 11676 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
11608 | "My identity is `%s'\n", | 11677 | "My identity is `%s'\n", |
11609 | GNUNET_i2s_full (&GST_my_identity)); | 11678 | GNUNET_i2s_full (&GST_my_identity)); |
11679 | GST_my_hello = GNUNET_HELLO_builder_new (&GST_my_identity); | ||
11610 | GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg); | 11680 | GST_stats = GNUNET_STATISTICS_create ("transport", GST_cfg); |
11611 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); | 11681 | GNUNET_SCHEDULER_add_shutdown (&shutdown_task, NULL); |
11612 | peerstore = GNUNET_PEERSTORE_connect (GST_cfg); | 11682 | peerstore = GNUNET_PEERSTORE_connect (GST_cfg); |