aboutsummaryrefslogtreecommitdiff
path: root/src/dv/gnunet-service-dv.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dv/gnunet-service-dv.c')
-rw-r--r--src/dv/gnunet-service-dv.c2271
1 files changed, 1255 insertions, 1016 deletions
diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c
index 3f52ddf2c..4b68f69b1 100644
--- a/src/dv/gnunet-service-dv.c
+++ b/src/dv/gnunet-service-dv.c
@@ -158,7 +158,7 @@ struct PendingMessage
158 /** 158 /**
159 * Actual message to be sent; // avoid allocation 159 * Actual message to be sent; // avoid allocation
160 */ 160 */
161 const struct GNUNET_MessageHeader *msg; // msg = (cast) &pm[1]; // memcpy (&pm[1], data, len); 161 const struct GNUNET_MessageHeader *msg; // msg = (cast) &pm[1]; // memcpy (&pm[1], data, len);
162 162
163}; 163};
164 164
@@ -568,7 +568,7 @@ static const struct GNUNET_CONFIGURATION_Handle *cfg;
568 * this client will never change, although if the plugin dies 568 * this client will never change, although if the plugin dies
569 * and returns for some reason it may happen. 569 * and returns for some reason it may happen.
570 */ 570 */
571static struct GNUNET_SERVER_Client * client_handle; 571static struct GNUNET_SERVER_Client *client_handle;
572 572
573/** 573/**
574 * Task to run when we shut down, cleaning up all our trash 574 * Task to run when we shut down, cleaning up all our trash
@@ -582,7 +582,7 @@ static char *my_short_id;
582/** 582/**
583 * Transmit handle to the plugin. 583 * Transmit handle to the plugin.
584 */ 584 */
585static struct GNUNET_CONNECTION_TransmitHandle * plugin_transmit_handle; 585static struct GNUNET_CONNECTION_TransmitHandle *plugin_transmit_handle;
586 586
587/** 587/**
588 * Head of DLL for client messages 588 * Head of DLL for client messages
@@ -602,7 +602,7 @@ static struct GNUNET_PEERINFO_Handle *peerinfo_handle;
602/** 602/**
603 * Transmit handle to core service. 603 * Transmit handle to core service.
604 */ 604 */
605static struct GNUNET_CORE_TransmitHandle * core_transmit_handle; 605static struct GNUNET_CORE_TransmitHandle *core_transmit_handle;
606 606
607/** 607/**
608 * Head of DLL for core messages 608 * Head of DLL for core messages
@@ -682,18 +682,18 @@ find_destination (void *cls,
682 * respective neighbor. 682 * respective neighbor.
683 */ 683 */
684static int 684static int
685find_specific_id (void *cls, 685find_specific_id (void *cls, const GNUNET_HashCode * key, void *value)
686 const GNUNET_HashCode *key,
687 void *value)
688{ 686{
689 struct FindIDContext *fdc = cls; 687 struct FindIDContext *fdc = cls;
690 struct DistantNeighbor *dn = value; 688 struct DistantNeighbor *dn = value;
691 689
692 if (memcmp(&dn->referrer->identity, fdc->via, sizeof(struct GNUNET_PeerIdentity)) == 0) 690 if (memcmp
693 { 691 (&dn->referrer->identity, fdc->via,
694 fdc->tid = dn->referrer_id; 692 sizeof (struct GNUNET_PeerIdentity)) == 0)
695 return GNUNET_NO; 693 {
696 } 694 fdc->tid = dn->referrer_id;
695 return GNUNET_NO;
696 }
697 return GNUNET_YES; 697 return GNUNET_YES;
698} 698}
699 699
@@ -704,18 +704,17 @@ find_specific_id (void *cls,
704 * want to remove those that may be accessible via a different 704 * want to remove those that may be accessible via a different
705 * route. 705 * route.
706 */ 706 */
707static int find_distant_peer (void *cls, 707static int
708 const GNUNET_HashCode * key, 708find_distant_peer (void *cls, const GNUNET_HashCode * key, void *value)
709 void *value)
710{ 709{
711 struct FindDestinationContext *fdc = cls; 710 struct FindDestinationContext *fdc = cls;
712 struct DistantNeighbor *distant = value; 711 struct DistantNeighbor *distant = value;
713 712
714 if (fdc->tid == distant->referrer_id) 713 if (fdc->tid == distant->referrer_id)
715 { 714 {
716 fdc->dest = distant; 715 fdc->dest = distant;
717 return GNUNET_NO; 716 return GNUNET_NO;
718 } 717 }
719 return GNUNET_YES; 718 return GNUNET_YES;
720} 719}
721 720
@@ -730,8 +729,8 @@ static int find_distant_peer (void *cls,
730 * @param buf where the callee should write the message 729 * @param buf where the callee should write the message
731 * @return number of bytes written to buf 730 * @return number of bytes written to buf
732 */ 731 */
733size_t transmit_to_plugin (void *cls, 732size_t
734 size_t size, void *buf) 733transmit_to_plugin (void *cls, size_t size, void *buf)
735{ 734{
736 char *cbuf = buf; 735 char *cbuf = buf;
737 struct PendingMessage *reply; 736 struct PendingMessage *reply;
@@ -739,31 +738,35 @@ size_t transmit_to_plugin (void *cls,
739 size_t msize; 738 size_t msize;
740 739
741 if (buf == NULL) 740 if (buf == NULL)
742 { 741 {
743 /* client disconnected */ 742 /* client disconnected */
744#if DEBUG_DV_MESSAGES 743#if DEBUG_DV_MESSAGES
745 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "%s: %s buffer was NULL (client disconnect?)\n", my_short_id, "transmit_to_plugin"); 744 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
745 "%s: %s buffer was NULL (client disconnect?)\n", my_short_id,
746 "transmit_to_plugin");
746#endif 747#endif
747 return 0; 748 return 0;
748 } 749 }
749 plugin_transmit_handle = NULL; 750 plugin_transmit_handle = NULL;
750 off = 0; 751 off = 0;
751 while ( (NULL != (reply = plugin_pending_head)) && 752 while ((NULL != (reply = plugin_pending_head)) &&
752 (size >= off + (msize = ntohs (reply->msg->size)))) 753 (size >= off + (msize = ntohs (reply->msg->size))))
753 { 754 {
754 GNUNET_CONTAINER_DLL_remove (plugin_pending_head, 755 GNUNET_CONTAINER_DLL_remove (plugin_pending_head,
755 plugin_pending_tail, 756 plugin_pending_tail, reply);
756 reply); 757 memcpy (&cbuf[off], reply->msg, msize);
757 memcpy (&cbuf[off], reply->msg, msize); 758 GNUNET_free (reply);
758 GNUNET_free (reply); 759 off += msize;
759 off += msize; 760 }
760 }
761 761
762 if (plugin_pending_head != NULL) 762 if (plugin_pending_head != NULL)
763 plugin_transmit_handle = GNUNET_SERVER_notify_transmit_ready (client_handle, 763 plugin_transmit_handle = GNUNET_SERVER_notify_transmit_ready (client_handle,
764 ntohs(plugin_pending_head->msg->size), 764 ntohs
765 (plugin_pending_head->msg->
766 size),
765 GNUNET_TIME_UNIT_FOREVER_REL, 767 GNUNET_TIME_UNIT_FOREVER_REL,
766 &transmit_to_plugin, NULL); 768 &transmit_to_plugin,
769 NULL);
767 770
768 return off; 771 return off;
769} 772}
@@ -778,11 +781,11 @@ size_t transmit_to_plugin (void *cls,
778 * @param distant_neighbor the original sender of the message 781 * @param distant_neighbor the original sender of the message
779 * @param cost the cost to the original sender of the message 782 * @param cost the cost to the original sender of the message
780 */ 783 */
781void send_to_plugin(const struct GNUNET_PeerIdentity * sender, 784void
782 const struct GNUNET_MessageHeader *message, 785send_to_plugin (const struct GNUNET_PeerIdentity *sender,
783 size_t message_size, 786 const struct GNUNET_MessageHeader *message,
784 struct GNUNET_PeerIdentity *distant_neighbor, 787 size_t message_size,
785 size_t cost) 788 struct GNUNET_PeerIdentity *distant_neighbor, size_t cost)
786{ 789{
787 struct GNUNET_DV_MessageReceived *received_msg; 790 struct GNUNET_DV_MessageReceived *received_msg;
788 struct PendingMessage *pending_message; 791 struct PendingMessage *pending_message;
@@ -792,85 +795,96 @@ void send_to_plugin(const struct GNUNET_PeerIdentity * sender,
792 int size; 795 int size;
793 796
794#if DEBUG_DV 797#if DEBUG_DV
795 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "send_to_plugin called with peer %s as sender\n", GNUNET_i2s(distant_neighbor)); 798 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
799 "send_to_plugin called with peer %s as sender\n",
800 GNUNET_i2s (distant_neighbor));
796#endif 801#endif
797 802
798 if (memcmp(sender, distant_neighbor, sizeof(struct GNUNET_PeerIdentity)) != 0) 803 if (memcmp (sender, distant_neighbor, sizeof (struct GNUNET_PeerIdentity)) !=
804 0)
799 { 805 {
800 sender_address_len = sizeof(struct GNUNET_PeerIdentity) * 2; 806 sender_address_len = sizeof (struct GNUNET_PeerIdentity) * 2;
801 sender_address = GNUNET_malloc(sender_address_len); 807 sender_address = GNUNET_malloc (sender_address_len);
802 memcpy(sender_address, distant_neighbor, sizeof(struct GNUNET_PeerIdentity)); 808 memcpy (sender_address, distant_neighbor,
803 memcpy(&sender_address[sizeof(struct GNUNET_PeerIdentity)], sender, sizeof(struct GNUNET_PeerIdentity)); 809 sizeof (struct GNUNET_PeerIdentity));
810 memcpy (&sender_address[sizeof (struct GNUNET_PeerIdentity)], sender,
811 sizeof (struct GNUNET_PeerIdentity));
804 } 812 }
805 else 813 else
806 { 814 {
807 sender_address_len = sizeof(struct GNUNET_PeerIdentity); 815 sender_address_len = sizeof (struct GNUNET_PeerIdentity);
808 sender_address = GNUNET_malloc(sender_address_len); 816 sender_address = GNUNET_malloc (sender_address_len);
809 memcpy(sender_address, sender, sizeof(struct GNUNET_PeerIdentity)); 817 memcpy (sender_address, sender, sizeof (struct GNUNET_PeerIdentity));
810 } 818 }
811 819
812 size = sizeof(struct GNUNET_DV_MessageReceived) + sender_address_len + message_size; 820 size =
813 received_msg = GNUNET_malloc(size); 821 sizeof (struct GNUNET_DV_MessageReceived) + sender_address_len +
814 received_msg->header.size = htons(size); 822 message_size;
815 received_msg->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_RECEIVE); 823 received_msg = GNUNET_malloc (size);
816 received_msg->distance = htonl(cost); 824 received_msg->header.size = htons (size);
817 received_msg->msg_len = htonl(message_size); 825 received_msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_RECEIVE);
826 received_msg->distance = htonl (cost);
827 received_msg->msg_len = htonl (message_size);
818 /* Set the sender in this message to be the original sender! */ 828 /* Set the sender in this message to be the original sender! */
819 memcpy(&received_msg->sender, distant_neighbor, sizeof(struct GNUNET_PeerIdentity)); 829 memcpy (&received_msg->sender, distant_neighbor,
830 sizeof (struct GNUNET_PeerIdentity));
820 /* Copy the intermediate sender to the end of the message, this is how the transport identifies this peer */ 831 /* Copy the intermediate sender to the end of the message, this is how the transport identifies this peer */
821 memcpy(&received_msg[1], sender_address, sender_address_len); 832 memcpy (&received_msg[1], sender_address, sender_address_len);
822 GNUNET_free(sender_address); 833 GNUNET_free (sender_address);
823 /* Copy the actual message after the sender */ 834 /* Copy the actual message after the sender */
824 packed_msg_start = (char *)&received_msg[1]; 835 packed_msg_start = (char *) &received_msg[1];
825 packed_msg_start = &packed_msg_start[sender_address_len]; 836 packed_msg_start = &packed_msg_start[sender_address_len];
826 memcpy(packed_msg_start, message, message_size); 837 memcpy (packed_msg_start, message, message_size);
827 pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + size); 838 pending_message = GNUNET_malloc (sizeof (struct PendingMessage) + size);
828 pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1]; 839 pending_message->msg = (struct GNUNET_MessageHeader *) &pending_message[1];
829 memcpy(&pending_message[1], received_msg, size); 840 memcpy (&pending_message[1], received_msg, size);
830 GNUNET_free(received_msg); 841 GNUNET_free (received_msg);
831 842
832 GNUNET_CONTAINER_DLL_insert_after(plugin_pending_head, plugin_pending_tail, plugin_pending_tail, pending_message); 843 GNUNET_CONTAINER_DLL_insert_after (plugin_pending_head, plugin_pending_tail,
844 plugin_pending_tail, pending_message);
833 845
834 if (client_handle != NULL) 846 if (client_handle != NULL)
847 {
848 if (plugin_transmit_handle == NULL)
835 { 849 {
836 if (plugin_transmit_handle == NULL) 850 plugin_transmit_handle =
837 { 851 GNUNET_SERVER_notify_transmit_ready (client_handle, size,
838 plugin_transmit_handle = GNUNET_SERVER_notify_transmit_ready (client_handle, 852 GNUNET_TIME_UNIT_FOREVER_REL,
839 size, GNUNET_TIME_UNIT_FOREVER_REL, 853 &transmit_to_plugin, NULL);
840 &transmit_to_plugin, NULL);
841 }
842 } 854 }
855 }
843 else 856 else
844 { 857 {
845 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to queue message for plugin, client_handle not yet set (how?)!\n"); 858 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
846 } 859 "Failed to queue message for plugin, client_handle not yet set (how?)!\n");
860 }
847} 861}
848 862
849/* Declare here so retry_core_send is aware of it */ 863/* Declare here so retry_core_send is aware of it */
850size_t core_transmit_notify (void *cls, 864size_t core_transmit_notify (void *cls, size_t size, void *buf);
851 size_t size, void *buf);
852 865
853/** 866/**
854 * Try to send another message from our core sending list 867 * Try to send another message from our core sending list
855 */ 868 */
856static void 869static void
857try_core_send (void *cls, 870try_core_send (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
858 const struct GNUNET_SCHEDULER_TaskContext *tc)
859{ 871{
860 struct PendingMessage *pending; 872 struct PendingMessage *pending;
873
861 pending = core_pending_head; 874 pending = core_pending_head;
862 875
863 if (core_transmit_handle != NULL) 876 if (core_transmit_handle != NULL)
864 return; /* Message send already in progress */ 877 return; /* Message send already in progress */
865 878
866 if ((pending != NULL) && (coreAPI != NULL)) 879 if ((pending != NULL) && (coreAPI != NULL))
867 core_transmit_handle = GNUNET_CORE_notify_transmit_ready (coreAPI, 880 core_transmit_handle = GNUNET_CORE_notify_transmit_ready (coreAPI,
868 GNUNET_YES, 881 GNUNET_YES,
869 pending->importance, 882 pending->importance,
870 pending->timeout, 883 pending->timeout,
871 &pending->recipient, 884 &pending->recipient,
872 pending->msg_size, 885 pending->msg_size,
873 &core_transmit_notify, NULL); 886 &core_transmit_notify,
887 NULL);
874} 888}
875 889
876 890
@@ -885,8 +899,8 @@ try_core_send (void *cls,
885 * @param buf where the callee should write the message 899 * @param buf where the callee should write the message
886 * @return number of bytes written to buf 900 * @return number of bytes written to buf
887 */ 901 */
888size_t core_transmit_notify (void *cls, 902size_t
889 size_t size, void *buf) 903core_transmit_notify (void *cls, size_t size, void *buf)
890{ 904{
891 char *cbuf = buf; 905 char *cbuf = buf;
892 struct PendingMessage *pending; 906 struct PendingMessage *pending;
@@ -895,58 +909,65 @@ size_t core_transmit_notify (void *cls,
895 size_t msize; 909 size_t msize;
896 910
897 if (buf == NULL) 911 if (buf == NULL)
898 { 912 {
899 /* client disconnected */ 913 /* client disconnected */
900#if DEBUG_DV 914#if DEBUG_DV
901 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s': buffer was NULL\n", "DHT"); 915 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "`%s': buffer was NULL\n", "DHT");
902#endif 916#endif
903 return 0; 917 return 0;
904 } 918 }
905 919
906 core_transmit_handle = NULL; 920 core_transmit_handle = NULL;
907 off = 0; 921 off = 0;
908 pending = core_pending_head; 922 pending = core_pending_head;
909 if ( (pending != NULL) && 923 if ((pending != NULL) && (size >= (msize = ntohs (pending->msg->size))))
910 (size >= (msize = ntohs (pending->msg->size)))) 924 {
911 {
912#if DEBUG_DV 925#if DEBUG_DV
913 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "`%s' : transmit_notify (core) called with size %d\n", "dv service", msize); 926 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
927 "`%s' : transmit_notify (core) called with size %d\n",
928 "dv service", msize);
914#endif 929#endif
915 GNUNET_CONTAINER_DLL_remove (core_pending_head, 930 GNUNET_CONTAINER_DLL_remove (core_pending_head, core_pending_tail, pending);
916 core_pending_tail, 931 if (pending->send_result != NULL) /* Will only be non-null if a real client asked for this send */
917 pending); 932 {
918 if (pending->send_result != NULL) /* Will only be non-null if a real client asked for this send */ 933 client_reply =
934 GNUNET_malloc (sizeof (struct PendingMessage) +
935 sizeof (struct GNUNET_DV_SendResultMessage));
936 client_reply->msg = (struct GNUNET_MessageHeader *) &client_reply[1];
937 memcpy (&client_reply[1], pending->send_result,
938 sizeof (struct GNUNET_DV_SendResultMessage));
939 GNUNET_free (pending->send_result);
940
941 GNUNET_CONTAINER_DLL_insert_after (plugin_pending_head,
942 plugin_pending_tail,
943 plugin_pending_tail, client_reply);
944 if (client_handle != NULL)
945 {
946 if (plugin_transmit_handle == NULL)
947 {
948 plugin_transmit_handle =
949 GNUNET_SERVER_notify_transmit_ready (client_handle,
950 sizeof (struct
951 GNUNET_DV_SendResultMessage),
952 GNUNET_TIME_UNIT_FOREVER_REL,
953 &transmit_to_plugin, NULL);
954 }
955 else
919 { 956 {
920 client_reply = GNUNET_malloc(sizeof(struct PendingMessage) + sizeof(struct GNUNET_DV_SendResultMessage)); 957 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
921 client_reply->msg = (struct GNUNET_MessageHeader *)&client_reply[1]; 958 "Failed to queue message for plugin, must be one in progress already!!\n");
922 memcpy(&client_reply[1], pending->send_result, sizeof(struct GNUNET_DV_SendResultMessage));
923 GNUNET_free(pending->send_result);
924
925 GNUNET_CONTAINER_DLL_insert_after(plugin_pending_head, plugin_pending_tail, plugin_pending_tail, client_reply);
926 if (client_handle != NULL)
927 {
928 if (plugin_transmit_handle == NULL)
929 {
930 plugin_transmit_handle = GNUNET_SERVER_notify_transmit_ready (client_handle,
931 sizeof(struct GNUNET_DV_SendResultMessage),
932 GNUNET_TIME_UNIT_FOREVER_REL,
933 &transmit_to_plugin, NULL);
934 }
935 else
936 {
937 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to queue message for plugin, must be one in progress already!!\n");
938 }
939 }
940 } 959 }
941 memcpy (&cbuf[off], pending->msg, msize); 960 }
942 GNUNET_free (pending);
943 off += msize;
944 } 961 }
945 /*reply = core_pending_head;*/ 962 memcpy (&cbuf[off], pending->msg, msize);
963 GNUNET_free (pending);
964 off += msize;
965 }
966 /*reply = core_pending_head; */
946 967
947 GNUNET_SCHEDULER_add_now(&try_core_send, NULL); 968 GNUNET_SCHEDULER_add_now (&try_core_send, NULL);
948 /*if (reply != NULL) 969 /*if (reply != NULL)
949 core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, GNUNET_YES, reply->importance, reply->timeout, &reply->recipient, reply->msg_size, &core_transmit_notify, NULL);*/ 970 * core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, GNUNET_YES, reply->importance, reply->timeout, &reply->recipient, reply->msg_size, &core_transmit_notify, NULL); */
950 971
951 return off; 972 return off;
952} 973}
@@ -971,6 +992,7 @@ send_message_via (const struct GNUNET_PeerIdentity *sender,
971 struct DistantNeighbor *source; 992 struct DistantNeighbor *source;
972 struct PendingMessage *pending_message; 993 struct PendingMessage *pending_message;
973 struct FindIDContext find_context; 994 struct FindIDContext find_context;
995
974#if DEBUG_DV 996#if DEBUG_DV
975 char shortname[5]; 997 char shortname[5];
976#endif 998#endif
@@ -980,70 +1002,76 @@ send_message_via (const struct GNUNET_PeerIdentity *sender,
980 find_context.dest = send_context->distant_peer; 1002 find_context.dest = send_context->distant_peer;
981 find_context.via = recipient; 1003 find_context.via = recipient;
982 find_context.tid = 0; 1004 find_context.tid = 0;
983 GNUNET_CONTAINER_multihashmap_get_multiple (extended_neighbors, &send_context->distant_peer->hashPubKey, 1005 GNUNET_CONTAINER_multihashmap_get_multiple (extended_neighbors,
1006 &send_context->
1007 distant_peer->hashPubKey,
984 &find_specific_id, &find_context); 1008 &find_specific_id, &find_context);
985 1009
986 if (find_context.tid == 0) 1010 if (find_context.tid == 0)
987 { 1011 {
988 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: find_specific_id failed to find peer!\n", my_short_id); 1012 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
989 /* target unknown to us, drop! */ 1013 "%s: find_specific_id failed to find peer!\n", my_short_id);
990 return GNUNET_SYSERR; 1014 /* target unknown to us, drop! */
991 } 1015 return GNUNET_SYSERR;
1016 }
992 recipient_id = find_context.tid; 1017 recipient_id = find_context.tid;
993 1018
994 if (0 == (memcmp (&my_identity, 1019 if (0 == (memcmp (&my_identity, sender, sizeof (struct GNUNET_PeerIdentity))))
995 sender, sizeof (struct GNUNET_PeerIdentity))))
996 { 1020 {
997 sender_id = 0; 1021 sender_id = 0;
998 source = GNUNET_CONTAINER_multihashmap_get (extended_neighbors, 1022 source = GNUNET_CONTAINER_multihashmap_get (extended_neighbors,
999 &sender->hashPubKey); 1023 &sender->hashPubKey);
1000 if (source != NULL) 1024 if (source != NULL)
1001 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: send_message_via found %s, myself in extended peer list???\n", my_short_id, GNUNET_i2s(&source->identity)); 1025 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1026 "%s: send_message_via found %s, myself in extended peer list???\n",
1027 my_short_id, GNUNET_i2s (&source->identity));
1002 } 1028 }
1003 else 1029 else
1004 { 1030 {
1005 source = GNUNET_CONTAINER_multihashmap_get (extended_neighbors, 1031 source = GNUNET_CONTAINER_multihashmap_get (extended_neighbors,
1006 &sender->hashPubKey); 1032 &sender->hashPubKey);
1007 if (source == NULL) 1033 if (source == NULL)
1008 { 1034 {
1009 /* sender unknown to us, drop! */ 1035 /* sender unknown to us, drop! */
1010 return GNUNET_SYSERR; 1036 return GNUNET_SYSERR;
1011 } 1037 }
1012 sender_id = source->our_id; 1038 sender_id = source->our_id;
1013 } 1039 }
1014 1040
1015 pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + msg_size); 1041 pending_message = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size);
1016 pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1]; 1042 pending_message->msg = (struct GNUNET_MessageHeader *) &pending_message[1];
1017 pending_message->send_result = send_context->send_result; 1043 pending_message->send_result = send_context->send_result;
1018 memcpy(&pending_message->recipient, recipient, sizeof(struct GNUNET_PeerIdentity)); 1044 memcpy (&pending_message->recipient, recipient,
1045 sizeof (struct GNUNET_PeerIdentity));
1019 pending_message->msg_size = msg_size; 1046 pending_message->msg_size = msg_size;
1020 pending_message->importance = send_context->importance; 1047 pending_message->importance = send_context->importance;
1021 pending_message->timeout = send_context->timeout; 1048 pending_message->timeout = send_context->timeout;
1022 toSend = (p2p_dv_MESSAGE_Data *)pending_message->msg; 1049 toSend = (p2p_dv_MESSAGE_Data *) pending_message->msg;
1023 toSend->header.size = htons (msg_size); 1050 toSend->header.size = htons (msg_size);
1024 toSend->header.type = htons (GNUNET_MESSAGE_TYPE_DV_DATA); 1051 toSend->header.type = htons (GNUNET_MESSAGE_TYPE_DV_DATA);
1025 toSend->sender = htonl (sender_id); 1052 toSend->sender = htonl (sender_id);
1026 toSend->recipient = htonl (recipient_id); 1053 toSend->recipient = htonl (recipient_id);
1027#if DEBUG_DV_MESSAGES 1054#if DEBUG_DV_MESSAGES
1028 toSend->uid = send_context->uid; /* Still sent around in network byte order */ 1055 toSend->uid = send_context->uid; /* Still sent around in network byte order */
1029#else 1056#else
1030 toSend->uid = htonl(0); 1057 toSend->uid = htonl (0);
1031#endif 1058#endif
1032 1059
1033 memcpy (&toSend[1], send_context->message, send_context->message_size); 1060 memcpy (&toSend[1], send_context->message, send_context->message_size);
1034 1061
1035#if DEBUG_DV 1062#if DEBUG_DV
1036 memcpy(&shortname, GNUNET_i2s(send_context->distant_peer), 4); 1063 memcpy (&shortname, GNUNET_i2s (send_context->distant_peer), 4);
1037 shortname[4] = '\0'; 1064 shortname[4] = '\0';
1038 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Notifying core of send to destination `%s' via `%s' size %u\n", "DV", &shortname, GNUNET_i2s(recipient), msg_size); 1065 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1066 "%s: Notifying core of send to destination `%s' via `%s' size %u\n",
1067 "DV", &shortname, GNUNET_i2s (recipient), msg_size);
1039#endif 1068#endif
1040 1069
1041 GNUNET_CONTAINER_DLL_insert_after (core_pending_head, 1070 GNUNET_CONTAINER_DLL_insert_after (core_pending_head,
1042 core_pending_tail, 1071 core_pending_tail,
1043 core_pending_tail, 1072 core_pending_tail, pending_message);
1044 pending_message);
1045 1073
1046 GNUNET_SCHEDULER_add_now(try_core_send, NULL); 1074 GNUNET_SCHEDULER_add_now (try_core_send, NULL);
1047 1075
1048 return GNUNET_YES; 1076 return GNUNET_YES;
1049} 1077}
@@ -1059,17 +1087,15 @@ send_message_via (const struct GNUNET_PeerIdentity *sender,
1059 * @return GNUNET_YES to continue iteration, GNUNET_NO to stop 1087 * @return GNUNET_YES to continue iteration, GNUNET_NO to stop
1060 */ 1088 */
1061static int 1089static int
1062find_least_cost_peer (void *cls, 1090find_least_cost_peer (void *cls, const GNUNET_HashCode * key, void *value)
1063 const GNUNET_HashCode *key,
1064 void *value)
1065{ 1091{
1066 struct FindLeastCostContext *find_context = cls; 1092 struct FindLeastCostContext *find_context = cls;
1067 struct DistantNeighbor *dn = value; 1093 struct DistantNeighbor *dn = value;
1068 1094
1069 if (dn->cost < find_context->least_cost) 1095 if (dn->cost < find_context->least_cost)
1070 { 1096 {
1071 find_context->target = dn; 1097 find_context->target = dn;
1072 } 1098 }
1073 if (dn->cost == DIRECT_NEIGHBOR_COST) 1099 if (dn->cost == DIRECT_NEIGHBOR_COST)
1074 return GNUNET_NO; 1100 return GNUNET_NO;
1075 return GNUNET_YES; 1101 return GNUNET_YES;
@@ -1088,14 +1114,13 @@ find_least_cost_peer (void *cls,
1088 * @param timeout how long to possibly delay sending this message 1114 * @param timeout how long to possibly delay sending this message
1089 */ 1115 */
1090static int 1116static int
1091send_message (const struct GNUNET_PeerIdentity * recipient, 1117send_message (const struct GNUNET_PeerIdentity *recipient,
1092 const struct GNUNET_PeerIdentity * sender, 1118 const struct GNUNET_PeerIdentity *sender,
1093 const struct DistantNeighbor * specific_neighbor, 1119 const struct DistantNeighbor *specific_neighbor,
1094 const struct GNUNET_MessageHeader * message, 1120 const struct GNUNET_MessageHeader *message,
1095 size_t message_size, 1121 size_t message_size,
1096 unsigned int importance, 1122 unsigned int importance,
1097 unsigned int uid, 1123 unsigned int uid, struct GNUNET_TIME_Relative timeout)
1098 struct GNUNET_TIME_Relative timeout)
1099{ 1124{
1100 p2p_dv_MESSAGE_Data *toSend; 1125 p2p_dv_MESSAGE_Data *toSend;
1101 unsigned int msg_size; 1126 unsigned int msg_size;
@@ -1106,6 +1131,7 @@ send_message (const struct GNUNET_PeerIdentity * recipient,
1106 struct DistantNeighbor *source; 1131 struct DistantNeighbor *source;
1107 struct PendingMessage *pending_message; 1132 struct PendingMessage *pending_message;
1108 struct FindLeastCostContext find_least_ctx; 1133 struct FindLeastCostContext find_least_ctx;
1134
1109#if DEBUG_DV_PEER_NUMBERS 1135#if DEBUG_DV_PEER_NUMBERS
1110 struct GNUNET_CRYPTO_HashAsciiEncoded encPeerFrom; 1136 struct GNUNET_CRYPTO_HashAsciiEncoded encPeerFrom;
1111 struct GNUNET_CRYPTO_HashAsciiEncoded encPeerTo; 1137 struct GNUNET_CRYPTO_HashAsciiEncoded encPeerTo;
@@ -1122,84 +1148,97 @@ send_message (const struct GNUNET_PeerIdentity * recipient,
1122 * over all known peers, just those that apply. 1148 * over all known peers, just those that apply.
1123 */ 1149 */
1124 GNUNET_CONTAINER_multihashmap_get_multiple (extended_neighbors, 1150 GNUNET_CONTAINER_multihashmap_get_multiple (extended_neighbors,
1125 &recipient->hashPubKey, &find_least_cost_peer, &find_least_ctx); 1151 &recipient->hashPubKey,
1152 &find_least_cost_peer,
1153 &find_least_ctx);
1126 target = find_least_ctx.target; 1154 target = find_least_ctx.target;
1127 1155
1128 if (target == NULL) 1156 if (target == NULL)
1129 { 1157 {
1130 /* target unknown to us, drop! */ 1158 /* target unknown to us, drop! */
1131 return GNUNET_SYSERR; 1159 return GNUNET_SYSERR;
1132 } 1160 }
1133 recipient_id = target->referrer_id; 1161 recipient_id = target->referrer_id;
1134 1162
1135 source = GNUNET_CONTAINER_multihashmap_get (extended_neighbors, 1163 source = GNUNET_CONTAINER_multihashmap_get (extended_neighbors,
1136 &sender->hashPubKey); 1164 &sender->hashPubKey);
1137 if (source == NULL) 1165 if (source == NULL)
1166 {
1167 if (0 != (memcmp (&my_identity,
1168 sender, sizeof (struct GNUNET_PeerIdentity))))
1138 { 1169 {
1139 if (0 != (memcmp (&my_identity, 1170 /* sender unknown to us, drop! */
1140 sender, sizeof (struct GNUNET_PeerIdentity)))) 1171 return GNUNET_SYSERR;
1141 {
1142 /* sender unknown to us, drop! */
1143 return GNUNET_SYSERR;
1144 }
1145 sender_id = 0; /* 0 == us */
1146 } 1172 }
1173 sender_id = 0; /* 0 == us */
1174 }
1147 else 1175 else
1148 { 1176 {
1149 /* find out the number that we use when we gossip about 1177 /* find out the number that we use when we gossip about
1150 the sender */ 1178 * the sender */
1151 sender_id = source->our_id; 1179 sender_id = source->our_id;
1152 } 1180 }
1153 1181
1154#if DEBUG_DV_PEER_NUMBERS 1182#if DEBUG_DV_PEER_NUMBERS
1155 GNUNET_CRYPTO_hash_to_enc (&source->identity.hashPubKey, &encPeerFrom); 1183 GNUNET_CRYPTO_hash_to_enc (&source->identity.hashPubKey, &encPeerFrom);
1156 GNUNET_CRYPTO_hash_to_enc (&target->referrer->identity.hashPubKey, &encPeerVia); 1184 GNUNET_CRYPTO_hash_to_enc (&target->referrer->identity.hashPubKey,
1185 &encPeerVia);
1157 encPeerFrom.encoding[4] = '\0'; 1186 encPeerFrom.encoding[4] = '\0';
1158 encPeerVia.encoding[4] = '\0'; 1187 encPeerVia.encoding[4] = '\0';
1159#endif 1188#endif
1160 if ((sender_id != 0) && (0 == memcmp(&source->identity, &target->referrer->identity, sizeof(struct GNUNET_PeerIdentity)))) 1189 if ((sender_id != 0) &&
1161 { 1190 (0 ==
1162 return 0; 1191 memcmp (&source->identity, &target->referrer->identity,
1163 } 1192 sizeof (struct GNUNET_PeerIdentity))))
1193 {
1194 return 0;
1195 }
1164 1196
1165 cost = target->cost; 1197 cost = target->cost;
1166 pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + msg_size); 1198 pending_message = GNUNET_malloc (sizeof (struct PendingMessage) + msg_size);
1167 pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1]; 1199 pending_message->msg = (struct GNUNET_MessageHeader *) &pending_message[1];
1168 pending_message->send_result = NULL; 1200 pending_message->send_result = NULL;
1169 pending_message->importance = importance; 1201 pending_message->importance = importance;
1170 pending_message->timeout = timeout; 1202 pending_message->timeout = timeout;
1171 memcpy(&pending_message->recipient, &target->referrer->identity, sizeof(struct GNUNET_PeerIdentity)); 1203 memcpy (&pending_message->recipient, &target->referrer->identity,
1204 sizeof (struct GNUNET_PeerIdentity));
1172 pending_message->msg_size = msg_size; 1205 pending_message->msg_size = msg_size;
1173 toSend = (p2p_dv_MESSAGE_Data *)pending_message->msg; 1206 toSend = (p2p_dv_MESSAGE_Data *) pending_message->msg;
1174 toSend->header.size = htons (msg_size); 1207 toSend->header.size = htons (msg_size);
1175 toSend->header.type = htons (GNUNET_MESSAGE_TYPE_DV_DATA); 1208 toSend->header.type = htons (GNUNET_MESSAGE_TYPE_DV_DATA);
1176 toSend->sender = htonl (sender_id); 1209 toSend->sender = htonl (sender_id);
1177 toSend->recipient = htonl (recipient_id); 1210 toSend->recipient = htonl (recipient_id);
1178#if DEBUG_DV_MESSAGES 1211#if DEBUG_DV_MESSAGES
1179 toSend->uid = htonl(uid); 1212 toSend->uid = htonl (uid);
1180#else 1213#else
1181 toSend->uid = htonl(0); 1214 toSend->uid = htonl (0);
1182#endif 1215#endif
1183 1216
1184#if DEBUG_DV_PEER_NUMBERS 1217#if DEBUG_DV_PEER_NUMBERS
1185 GNUNET_CRYPTO_hash_to_enc (&target->identity.hashPubKey, &encPeerTo); 1218 GNUNET_CRYPTO_hash_to_enc (&target->identity.hashPubKey, &encPeerTo);
1186 encPeerTo.encoding[4] = '\0'; 1219 encPeerTo.encoding[4] = '\0';
1187 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Sending DATA message. Sender id %u, source %s, destination %s, via %s\n", GNUNET_i2s(&my_identity), sender_id, &encPeerFrom, &encPeerTo, &encPeerVia); 1220 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1221 "%s: Sending DATA message. Sender id %u, source %s, destination %s, via %s\n",
1222 GNUNET_i2s (&my_identity), sender_id, &encPeerFrom, &encPeerTo,
1223 &encPeerVia);
1188#endif 1224#endif
1189 memcpy (&toSend[1], message, message_size); 1225 memcpy (&toSend[1], message, message_size);
1190 if ((source != NULL) && (source->pkey == NULL)) /* Test our hypothesis about message failures! */ 1226 if ((source != NULL) && (source->pkey == NULL)) /* Test our hypothesis about message failures! */
1191 { 1227 {
1192 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: Sending message, but anticipate recipient will not know sender!!!\n\n\n", my_short_id); 1228 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1193 } 1229 "%s: Sending message, but anticipate recipient will not know sender!!!\n\n\n",
1230 my_short_id);
1231 }
1194 GNUNET_CONTAINER_DLL_insert_after (core_pending_head, 1232 GNUNET_CONTAINER_DLL_insert_after (core_pending_head,
1195 core_pending_tail, 1233 core_pending_tail,
1196 core_pending_tail, 1234 core_pending_tail, pending_message);
1197 pending_message);
1198#if DEBUG_DV 1235#if DEBUG_DV
1199 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Notifying core of send size %d to destination `%s'\n", "DV SEND MESSAGE", msg_size, GNUNET_i2s(recipient)); 1236 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1237 "%s: Notifying core of send size %d to destination `%s'\n",
1238 "DV SEND MESSAGE", msg_size, GNUNET_i2s (recipient));
1200#endif 1239#endif
1201 1240
1202 GNUNET_SCHEDULER_add_now(try_core_send, NULL); 1241 GNUNET_SCHEDULER_add_now (try_core_send, NULL);
1203 return (int) cost; 1242 return (int) cost;
1204} 1243}
1205 1244
@@ -1227,14 +1266,13 @@ struct CheckPeerContext
1227 * iterate, 1266 * iterate,
1228 * GNUNET_NO if not. 1267 * GNUNET_NO if not.
1229 */ 1268 */
1230int checkPeerID (void *cls, 1269int
1231 const GNUNET_HashCode * key, 1270checkPeerID (void *cls, const GNUNET_HashCode * key, void *value)
1232 void *value)
1233{ 1271{
1234 struct CheckPeerContext *ctx = cls; 1272 struct CheckPeerContext *ctx = cls;
1235 struct DistantNeighbor *distant = value; 1273 struct DistantNeighbor *distant = value;
1236 1274
1237 if (memcmp(key, &ctx->sender_id, sizeof(unsigned int)) == 0) 1275 if (memcmp (key, &ctx->sender_id, sizeof (unsigned int)) == 0)
1238 { 1276 {
1239 ctx->peer = distant; 1277 ctx->peer = distant;
1240 return GNUNET_NO; 1278 return GNUNET_NO;
@@ -1253,22 +1291,30 @@ int checkPeerID (void *cls,
1253 * @param client the TokenizedMessageContext which contains message information 1291 * @param client the TokenizedMessageContext which contains message information
1254 * @param message the actual message 1292 * @param message the actual message
1255 */ 1293 */
1256void tokenized_message_handler (void *cls, 1294void
1257 void *client, 1295tokenized_message_handler (void *cls,
1258 const struct GNUNET_MessageHeader *message) 1296 void *client,
1297 const struct GNUNET_MessageHeader *message)
1259{ 1298{
1260 struct TokenizedMessageContext *ctx = client; 1299 struct TokenizedMessageContext *ctx = client;
1300
1261 GNUNET_break_op (ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP); 1301 GNUNET_break_op (ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP);
1262 GNUNET_break_op (ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_DATA); 1302 GNUNET_break_op (ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_DATA);
1263 if ( (ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP) && 1303 if ((ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_GOSSIP) &&
1264 (ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_DATA) ) 1304 (ntohs (message->type) != GNUNET_MESSAGE_TYPE_DV_DATA))
1265 { 1305 {
1266#if DEBUG_DV_MESSAGES 1306#if DEBUG_DV_MESSAGES
1267 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1268 "%s: Receives %s message for me, uid %u, size %d, type %d cost %u from %s!\n", my_short_id, "DV DATA", ctx->uid, ntohs(message->size), ntohs(message->type), ctx->distant->cost, GNUNET_i2s(&ctx->distant->identity)); 1308 "%s: Receives %s message for me, uid %u, size %d, type %d cost %u from %s!\n",
1269#endif 1309 my_short_id, "DV DATA", ctx->uid, ntohs (message->size),
1270 GNUNET_assert(memcmp(ctx->peer, &ctx->distant->identity, sizeof(struct GNUNET_PeerIdentity)) != 0); 1310 ntohs (message->type), ctx->distant->cost,
1271 send_to_plugin(ctx->peer, message, ntohs(message->size), &ctx->distant->identity, ctx->distant->cost); 1311 GNUNET_i2s (&ctx->distant->identity));
1312#endif
1313 GNUNET_assert (memcmp
1314 (ctx->peer, &ctx->distant->identity,
1315 sizeof (struct GNUNET_PeerIdentity)) != 0);
1316 send_to_plugin (ctx->peer, message, ntohs (message->size),
1317 &ctx->distant->identity, ctx->distant->cost);
1272 } 1318 }
1273} 1319}
1274 1320
@@ -1282,23 +1328,23 @@ struct DelayedMessageContext
1282 uint32_t uid; 1328 uint32_t uid;
1283}; 1329};
1284 1330
1285void send_message_delayed (void *cls, 1331void
1286 const struct GNUNET_SCHEDULER_TaskContext *tc) 1332send_message_delayed (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1287{ 1333{
1288 struct DelayedMessageContext *msg_ctx = cls; 1334 struct DelayedMessageContext *msg_ctx = cls;
1335
1289 if (msg_ctx != NULL) 1336 if (msg_ctx != NULL)
1290 { 1337 {
1291 send_message(&msg_ctx->dest, 1338 send_message (&msg_ctx->dest,
1292 &msg_ctx->sender, 1339 &msg_ctx->sender,
1293 NULL, 1340 NULL,
1294 msg_ctx->message, 1341 msg_ctx->message,
1295 msg_ctx->message_size, 1342 msg_ctx->message_size,
1296 default_dv_priority, 1343 default_dv_priority,
1297 msg_ctx->uid, 1344 msg_ctx->uid, GNUNET_TIME_relative_get_forever ());
1298 GNUNET_TIME_relative_get_forever()); 1345 GNUNET_free (msg_ctx->message);
1299 GNUNET_free(msg_ctx->message); 1346 GNUNET_free (msg_ctx);
1300 GNUNET_free(msg_ctx); 1347 }
1301 }
1302} 1348}
1303#endif 1349#endif
1304 1350
@@ -1311,15 +1357,15 @@ void send_message_delayed (void *cls,
1311static uint32_t 1357static uint32_t
1312get_atsi_distance (const struct GNUNET_TRANSPORT_ATS_Information *atsi) 1358get_atsi_distance (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
1313{ 1359{
1314 while ( (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) && 1360 while ((ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) &&
1315 (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE) ) 1361 (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE))
1316 atsi++; 1362 atsi++;
1317 if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) 1363 if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR)
1318 { 1364 {
1319 GNUNET_break (0); 1365 GNUNET_break (0);
1320 /* FIXME: we do not have distance data? Assume direct neighbor. */ 1366 /* FIXME: we do not have distance data? Assume direct neighbor. */
1321 return DIRECT_NEIGHBOR_COST; 1367 return DIRECT_NEIGHBOR_COST;
1322 } 1368 }
1323 return ntohl (atsi->value); 1369 return ntohl (atsi->value);
1324} 1370}
1325 1371
@@ -1332,17 +1378,18 @@ get_atsi_distance (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
1332static struct GNUNET_TIME_Relative 1378static struct GNUNET_TIME_Relative
1333get_atsi_latency (const struct GNUNET_TRANSPORT_ATS_Information *atsi) 1379get_atsi_latency (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
1334{ 1380{
1335 while ( (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) && 1381 while ((ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) &&
1336 (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY) ) 1382 (ntohl (atsi->type) != GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY))
1337 atsi++; 1383 atsi++;
1338 if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR) 1384 if (ntohl (atsi->type) == GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR)
1339 { 1385 {
1340 GNUNET_break (0); 1386 GNUNET_break (0);
1341 /* how can we not have latency data? */ 1387 /* how can we not have latency data? */
1342 return GNUNET_TIME_UNIT_SECONDS; 1388 return GNUNET_TIME_UNIT_SECONDS;
1343 } 1389 }
1344 /* FIXME: Multiply by GNUNET_TIME_UNIT_MILLISECONDS (1) to get as a GNUNET_TIME_Relative */ 1390 /* FIXME: Multiply by GNUNET_TIME_UNIT_MILLISECONDS (1) to get as a GNUNET_TIME_Relative */
1345 return GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, ntohl (atsi->value)); 1391 return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
1392 ntohl (atsi->value));
1346} 1393}
1347 1394
1348/** 1395/**
@@ -1356,11 +1403,11 @@ get_atsi_latency (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
1356 * @param message the message 1403 * @param message the message
1357 * @param atsi transport ATS information (latency, distance, etc.) 1404 * @param atsi transport ATS information (latency, distance, etc.)
1358 */ 1405 */
1359static int 1406static int
1360handle_dv_data_message (void *cls, 1407handle_dv_data_message (void *cls,
1361 const struct GNUNET_PeerIdentity * peer, 1408 const struct GNUNET_PeerIdentity *peer,
1362 const struct GNUNET_MessageHeader * message, 1409 const struct GNUNET_MessageHeader *message,
1363 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 1410 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
1364{ 1411{
1365 const p2p_dv_MESSAGE_Data *incoming = (const p2p_dv_MESSAGE_Data *) message; 1412 const p2p_dv_MESSAGE_Data *incoming = (const p2p_dv_MESSAGE_Data *) message;
1366 const struct GNUNET_MessageHeader *packed_message; 1413 const struct GNUNET_MessageHeader *packed_message;
@@ -1374,6 +1421,7 @@ handle_dv_data_message (void *cls,
1374 struct TokenizedMessageContext tkm_ctx; 1421 struct TokenizedMessageContext tkm_ctx;
1375 int i; 1422 int i;
1376 int found_pos; 1423 int found_pos;
1424
1377#if DELAY_FORWARDS 1425#if DELAY_FORWARDS
1378 struct DelayedMessageContext *delayed_context; 1426 struct DelayedMessageContext *delayed_context;
1379#endif 1427#endif
@@ -1386,29 +1434,35 @@ handle_dv_data_message (void *cls,
1386 int ret; 1434 int ret;
1387 size_t packed_message_size; 1435 size_t packed_message_size;
1388 char *cbuf; 1436 char *cbuf;
1389 uint32_t distance; /* Distance information */ 1437 uint32_t distance; /* Distance information */
1390 struct GNUNET_TIME_Relative latency; /* Latency information */ 1438 struct GNUNET_TIME_Relative latency; /* Latency information */
1391 1439
1392 packed_message_size = ntohs(incoming->header.size) - sizeof(p2p_dv_MESSAGE_Data); 1440 packed_message_size =
1441 ntohs (incoming->header.size) - sizeof (p2p_dv_MESSAGE_Data);
1393#if DEBUG_DV 1442#if DEBUG_DV
1394 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1443 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1395 "%s: Receives DATA message from %s size %d, packed size %d!\n", my_short_id, GNUNET_i2s(peer) , ntohs(incoming->header.size), packed_message_size); 1444 "%s: Receives DATA message from %s size %d, packed size %d!\n",
1445 my_short_id, GNUNET_i2s (peer), ntohs (incoming->header.size),
1446 packed_message_size);
1396#endif 1447#endif
1397 1448
1398 if (ntohs (incoming->header.size) < sizeof (p2p_dv_MESSAGE_Data) + sizeof (struct GNUNET_MessageHeader)) 1449 if (ntohs (incoming->header.size) <
1399 { 1450 sizeof (p2p_dv_MESSAGE_Data) + sizeof (struct GNUNET_MessageHeader))
1451 {
1400#if DEBUG_DV 1452#if DEBUG_DV
1401 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1453 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1402 "`%s': Message sizes don't add up, total size %u, expected at least %u!\n", "dv service", ntohs(incoming->header.size), sizeof (p2p_dv_MESSAGE_Data) + sizeof (struct GNUNET_MessageHeader)); 1454 "`%s': Message sizes don't add up, total size %u, expected at least %u!\n",
1455 "dv service", ntohs (incoming->header.size),
1456 sizeof (p2p_dv_MESSAGE_Data) +
1457 sizeof (struct GNUNET_MessageHeader));
1403#endif 1458#endif
1404 return GNUNET_SYSERR; 1459 return GNUNET_SYSERR;
1405 } 1460 }
1406 1461
1407 /* Iterate over ATS_Information to get distance and latency */ 1462 /* Iterate over ATS_Information to get distance and latency */
1408 latency = get_atsi_latency(atsi); 1463 latency = get_atsi_latency (atsi);
1409 distance = get_atsi_distance(atsi); 1464 distance = get_atsi_distance (atsi);
1410 dn = GNUNET_CONTAINER_multihashmap_get (direct_neighbors, 1465 dn = GNUNET_CONTAINER_multihashmap_get (direct_neighbors, &peer->hashPubKey);
1411 &peer->hashPubKey);
1412 if (dn == NULL) 1466 if (dn == NULL)
1413 return GNUNET_OK; 1467 return GNUNET_OK;
1414 1468
@@ -1418,7 +1472,8 @@ handle_dv_data_message (void *cls,
1418 { 1472 {
1419 checkPeerCtx.sender_id = sid; 1473 checkPeerCtx.sender_id = sid;
1420 checkPeerCtx.peer = NULL; 1474 checkPeerCtx.peer = NULL;
1421 GNUNET_CONTAINER_multihashmap_iterate(extended_neighbors, &checkPeerID, &checkPeerCtx); 1475 GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors, &checkPeerID,
1476 &checkPeerCtx);
1422 pos = checkPeerCtx.peer; 1477 pos = checkPeerCtx.peer;
1423 } 1478 }
1424 else 1479 else
@@ -1433,154 +1488,177 @@ handle_dv_data_message (void *cls,
1433#endif 1488#endif
1434 1489
1435 if (pos == NULL) 1490 if (pos == NULL)
1436 { 1491 {
1437#if DEBUG_DV_MESSAGES 1492#if DEBUG_DV_MESSAGES
1438 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1493 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1439 "%s: unknown sender (%u), Message uid %u from %s!\n", my_short_id, ntohl(incoming->sender), ntohl(incoming->uid), GNUNET_i2s(&dn->identity)); 1494 "%s: unknown sender (%u), Message uid %u from %s!\n",
1440 pos = dn->referee_head; 1495 my_short_id, ntohl (incoming->sender), ntohl (incoming->uid),
1441 while ((NULL != pos) && (pos->referrer_id != sid)) 1496 GNUNET_i2s (&dn->identity));
1442 { 1497 pos = dn->referee_head;
1443 sender_id = strdup(GNUNET_i2s(&pos->identity)); 1498 while ((NULL != pos) && (pos->referrer_id != sid))
1444 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "I know sender %u %s\n", pos->referrer_id, sender_id); 1499 {
1445 GNUNET_free(sender_id); 1500 sender_id = strdup (GNUNET_i2s (&pos->identity));
1446 pos = pos->next; 1501 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "I know sender %u %s\n",
1447 } 1502 pos->referrer_id, sender_id);
1503 GNUNET_free (sender_id);
1504 pos = pos->next;
1505 }
1448#endif 1506#endif
1449 1507
1450 found_pos = -1; 1508 found_pos = -1;
1451 for (i = 0; i< MAX_OUTSTANDING_MESSAGES; i++) 1509 for (i = 0; i < MAX_OUTSTANDING_MESSAGES; i++)
1452 { 1510 {
1453 if (dn->pending_messages[i].sender_id == 0) 1511 if (dn->pending_messages[i].sender_id == 0)
1454 { 1512 {
1455 found_pos = i; 1513 found_pos = i;
1456 break; 1514 break;
1457 } 1515 }
1458 } 1516 }
1459 1517
1460 if (found_pos == -1) 1518 if (found_pos == -1)
1461 { 1519 {
1462 GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 1520 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1463 "%s: Too many unknown senders (%u), ignoring message! Message uid %llu from %s!\n", my_short_id, ntohl(incoming->sender), ntohl(incoming->uid), GNUNET_i2s(&dn->identity)); 1521 "%s: Too many unknown senders (%u), ignoring message! Message uid %llu from %s!\n",
1464 } 1522 my_short_id, ntohl (incoming->sender), ntohl (incoming->uid),
1465 else 1523 GNUNET_i2s (&dn->identity));
1466 {
1467 dn->pending_messages[found_pos].message = GNUNET_malloc(ntohs (message->size));
1468 memcpy(dn->pending_messages[found_pos].message, message, ntohs(message->size));
1469 dn->pending_messages[found_pos].distance = distance;
1470 dn->pending_messages[found_pos].latency = latency;
1471 memcpy(&dn->pending_messages[found_pos].sender, peer, sizeof(struct GNUNET_PeerIdentity));
1472 dn->pending_messages[found_pos].sender_id = sid;
1473 }
1474 /* unknown sender */
1475 return GNUNET_OK;
1476 } 1524 }
1525 else
1526 {
1527 dn->pending_messages[found_pos].message =
1528 GNUNET_malloc (ntohs (message->size));
1529 memcpy (dn->pending_messages[found_pos].message, message,
1530 ntohs (message->size));
1531 dn->pending_messages[found_pos].distance = distance;
1532 dn->pending_messages[found_pos].latency = latency;
1533 memcpy (&dn->pending_messages[found_pos].sender, peer,
1534 sizeof (struct GNUNET_PeerIdentity));
1535 dn->pending_messages[found_pos].sender_id = sid;
1536 }
1537 /* unknown sender */
1538 return GNUNET_OK;
1539 }
1477 original_sender = &pos->identity; 1540 original_sender = &pos->identity;
1478 tid = ntohl (incoming->recipient); 1541 tid = ntohl (incoming->recipient);
1479 if (tid == 0) 1542 if (tid == 0)
1543 {
1544 /* 0 == us */
1545 cbuf = (char *) &incoming[1];
1546
1547 tkm_ctx.peer = peer;
1548 tkm_ctx.distant = pos;
1549 tkm_ctx.uid = ntohl (incoming->uid);
1550 if (GNUNET_OK != GNUNET_SERVER_mst_receive (coreMST,
1551 &tkm_ctx,
1552 cbuf,
1553 packed_message_size,
1554 GNUNET_NO, GNUNET_NO))
1480 { 1555 {
1481 /* 0 == us */ 1556 GNUNET_break_op (0);
1482 cbuf = (char *)&incoming[1]; 1557 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1483 1558 "%s: %s Received corrupt data, discarding!", my_short_id,
1484 tkm_ctx.peer = peer; 1559 "DV SERVICE");
1485 tkm_ctx.distant = pos;
1486 tkm_ctx.uid = ntohl(incoming->uid);
1487 if (GNUNET_OK != GNUNET_SERVER_mst_receive (coreMST,
1488 &tkm_ctx,
1489 cbuf,
1490 packed_message_size,
1491 GNUNET_NO,
1492 GNUNET_NO))
1493 {
1494 GNUNET_break_op(0);
1495 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: %s Received corrupt data, discarding!", my_short_id, "DV SERVICE");
1496 }
1497 return GNUNET_OK;
1498 } 1560 }
1561 return GNUNET_OK;
1562 }
1499 else 1563 else
1500 { 1564 {
1501 packed_message = (struct GNUNET_MessageHeader *)&incoming[1]; 1565 packed_message = (struct GNUNET_MessageHeader *) &incoming[1];
1502 } 1566 }
1503 1567
1504 /* FIXME: this is the *only* per-request operation we have in DV 1568 /* FIXME: this is the *only* per-request operation we have in DV
1505 that is O(n) in relation to the number of connected peers; a 1569 * that is O(n) in relation to the number of connected peers; a
1506 hash-table lookup could easily solve this (minor performance 1570 * hash-table lookup could easily solve this (minor performance
1507 issue) */ 1571 * issue) */
1508 fdc.tid = tid; 1572 fdc.tid = tid;
1509 fdc.dest = NULL; 1573 fdc.dest = NULL;
1510 GNUNET_CONTAINER_heap_iterate (neighbor_max_heap, 1574 GNUNET_CONTAINER_heap_iterate (neighbor_max_heap, &find_destination, &fdc);
1511 &find_destination, &fdc);
1512 1575
1513#if DEBUG_DV 1576#if DEBUG_DV
1514 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1577 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1515 "%s: Receives %s message for someone else!\n", "dv", "DV DATA"); 1578 "%s: Receives %s message for someone else!\n", "dv", "DV DATA");
1516#endif 1579#endif
1517 1580
1518 if (fdc.dest == NULL) 1581 if (fdc.dest == NULL)
1519 { 1582 {
1520#if DEBUG_DV_MESSAGES 1583#if DEBUG_DV_MESSAGES
1521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1584 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1522 "%s: Receives %s message uid %u for someone we don't know (id %u)!\n", my_short_id, "DV DATA", ntohl(incoming->uid), tid); 1585 "%s: Receives %s message uid %u for someone we don't know (id %u)!\n",
1586 my_short_id, "DV DATA", ntohl (incoming->uid), tid);
1523#endif 1587#endif
1524 return GNUNET_OK; 1588 return GNUNET_OK;
1525 } 1589 }
1526 destination = &fdc.dest->identity; 1590 destination = &fdc.dest->identity;
1527 1591
1528 if (0 == memcmp (destination, peer, sizeof (struct GNUNET_PeerIdentity))) 1592 if (0 == memcmp (destination, peer, sizeof (struct GNUNET_PeerIdentity)))
1529 { 1593 {
1530 /* FIXME: create stat: routing loop-discard! */ 1594 /* FIXME: create stat: routing loop-discard! */
1531 1595
1532#if DEBUG_DV_MESSAGES 1596#if DEBUG_DV_MESSAGES
1533 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1597 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1534 "%s: DROPPING MESSAGE uid %u type %d, routing loop! Message immediately from %s!\n", my_short_id, ntohl(incoming->uid), ntohs(packed_message->type), GNUNET_i2s(&dn->identity)); 1598 "%s: DROPPING MESSAGE uid %u type %d, routing loop! Message immediately from %s!\n",
1599 my_short_id, ntohl (incoming->uid),
1600 ntohs (packed_message->type), GNUNET_i2s (&dn->identity));
1535#endif 1601#endif
1536 return GNUNET_OK; 1602 return GNUNET_OK;
1537 } 1603 }
1538 1604
1539 /* At this point we have a message, and we need to forward it on to the 1605 /* At this point we have a message, and we need to forward it on to the
1540 * next DV hop. 1606 * next DV hop.
1541 */ 1607 */
1542#if DEBUG_DV_MESSAGES 1608#if DEBUG_DV_MESSAGES
1543 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1609 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1544 "%s: FORWARD %s message for %s, uid %u, size %d type %d, cost %u!\n", my_short_id, "DV DATA", GNUNET_i2s(destination), ntohl(incoming->uid), ntohs(packed_message->size), ntohs(packed_message->type), pos->cost); 1610 "%s: FORWARD %s message for %s, uid %u, size %d type %d, cost %u!\n",
1611 my_short_id, "DV DATA", GNUNET_i2s (destination),
1612 ntohl (incoming->uid), ntohs (packed_message->size),
1613 ntohs (packed_message->type), pos->cost);
1545#endif 1614#endif
1546 1615
1547#if DELAY_FORWARDS 1616#if DELAY_FORWARDS
1548 if (GNUNET_TIME_absolute_get_duration(pos->last_gossip).abs_value < GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2).abs_value) 1617 if (GNUNET_TIME_absolute_get_duration (pos->last_gossip).abs_value <
1549 { 1618 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2).abs_value)
1550 delayed_context = GNUNET_malloc(sizeof(struct DelayedMessageContext)); 1619 {
1551 memcpy(&delayed_context->dest, destination, sizeof(struct GNUNET_PeerIdentity)); 1620 delayed_context = GNUNET_malloc (sizeof (struct DelayedMessageContext));
1552 memcpy(&delayed_context->sender, original_sender, sizeof(struct GNUNET_PeerIdentity)); 1621 memcpy (&delayed_context->dest, destination,
1553 delayed_context->message = GNUNET_malloc(packed_message_size); 1622 sizeof (struct GNUNET_PeerIdentity));
1554 memcpy(delayed_context->message, packed_message, packed_message_size); 1623 memcpy (&delayed_context->sender, original_sender,
1555 delayed_context->message_size = packed_message_size; 1624 sizeof (struct GNUNET_PeerIdentity));
1556 delayed_context->uid = ntohl(incoming->uid); 1625 delayed_context->message = GNUNET_malloc (packed_message_size);
1557 GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 2500), &send_message_delayed, delayed_context); 1626 memcpy (delayed_context->message, packed_message, packed_message_size);
1558 return GNUNET_OK; 1627 delayed_context->message_size = packed_message_size;
1559 } 1628 delayed_context->uid = ntohl (incoming->uid);
1629 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
1630 (GNUNET_TIME_UNIT_MILLISECONDS, 2500),
1631 &send_message_delayed, delayed_context);
1632 return GNUNET_OK;
1633 }
1560 else 1634 else
1561#endif 1635#endif
1562 { 1636 {
1563 ret = send_message(destination, 1637 ret = send_message (destination,
1564 original_sender, 1638 original_sender,
1565 NULL, 1639 NULL,
1566 packed_message, 1640 packed_message,
1567 packed_message_size, 1641 packed_message_size,
1568 default_dv_priority, 1642 default_dv_priority,
1569 ntohl(incoming->uid), 1643 ntohl (incoming->uid),
1570 GNUNET_TIME_relative_get_forever()); 1644 GNUNET_TIME_relative_get_forever ());
1571 } 1645 }
1572 if (ret != GNUNET_SYSERR) 1646 if (ret != GNUNET_SYSERR)
1573 return GNUNET_OK; 1647 return GNUNET_OK;
1574 else 1648 else
1575 { 1649 {
1576#if DEBUG_MESSAGE_DROP 1650#if DEBUG_MESSAGE_DROP
1577 char *direct_id = GNUNET_strdup(GNUNET_i2s(&dn->identity)); 1651 char *direct_id = GNUNET_strdup (GNUNET_i2s (&dn->identity));
1578 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1652
1579 "%s: DROPPING MESSAGE type %d, forwarding failed! Message immediately from %s!\n", GNUNET_i2s(&my_identity), ntohs(((struct GNUNET_MessageHeader *)&incoming[1])->type), direct_id); 1653 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1580 GNUNET_free (direct_id); 1654 "%s: DROPPING MESSAGE type %d, forwarding failed! Message immediately from %s!\n",
1655 GNUNET_i2s (&my_identity),
1656 ntohs (((struct GNUNET_MessageHeader *) &incoming[1])->type),
1657 direct_id);
1658 GNUNET_free (direct_id);
1581#endif 1659#endif
1582 return GNUNET_SYSERR; 1660 return GNUNET_SYSERR;
1583 } 1661 }
1584} 1662}
1585 1663
1586#if DEBUG_DV 1664#if DEBUG_DV
@@ -1594,19 +1672,24 @@ handle_dv_data_message (void *cls,
1594 * iterate, 1672 * iterate,
1595 * GNUNET_NO if not. 1673 * GNUNET_NO if not.
1596 */ 1674 */
1597int print_neighbors (void *cls, 1675int
1598 const GNUNET_HashCode * key, 1676print_neighbors (void *cls, const GNUNET_HashCode * key, void *abs_value)
1599 void *abs_value)
1600{ 1677{
1601 struct DistantNeighbor *distant_neighbor = abs_value; 1678 struct DistantNeighbor *distant_neighbor = abs_value;
1602 char my_shortname[5]; 1679 char my_shortname[5];
1603 char referrer_shortname[5]; 1680 char referrer_shortname[5];
1604 memcpy(&my_shortname, GNUNET_i2s(&my_identity), 4); 1681
1682 memcpy (&my_shortname, GNUNET_i2s (&my_identity), 4);
1605 my_shortname[4] = '\0'; 1683 my_shortname[4] = '\0';
1606 memcpy(&referrer_shortname, GNUNET_i2s(&distant_neighbor->referrer->identity), 4); 1684 memcpy (&referrer_shortname,
1685 GNUNET_i2s (&distant_neighbor->referrer->identity), 4);
1607 referrer_shortname[4] = '\0'; 1686 referrer_shortname[4] = '\0';
1608 1687
1609 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "`%s' %s: Peer `%s', distance %d, referrer `%s' pkey: %s\n", &my_shortname, "DV", GNUNET_i2s(&distant_neighbor->identity), distant_neighbor->cost, &referrer_shortname, distant_neighbor->pkey == NULL ? "no" : "yes"); 1688 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1689 "`%s' %s: Peer `%s', distance %d, referrer `%s' pkey: %s\n",
1690 &my_shortname, "DV", GNUNET_i2s (&distant_neighbor->identity),
1691 distant_neighbor->cost, &referrer_shortname,
1692 distant_neighbor->pkey == NULL ? "no" : "yes");
1610 return GNUNET_YES; 1693 return GNUNET_YES;
1611} 1694}
1612#endif 1695#endif
@@ -1616,13 +1699,13 @@ int print_neighbors (void *cls,
1616 * peers. Will run until called with reason shutdown. 1699 * peers. Will run until called with reason shutdown.
1617 */ 1700 */
1618static void 1701static void
1619neighbor_send_task (void *cls, 1702neighbor_send_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1620 const struct GNUNET_SCHEDULER_TaskContext *tc)
1621{ 1703{
1622 struct NeighborSendContext *send_context = cls; 1704 struct NeighborSendContext *send_context = cls;
1705
1623#if DEBUG_DV_GOSSIP_SEND 1706#if DEBUG_DV_GOSSIP_SEND
1624 char * encPeerAbout; 1707 char *encPeerAbout;
1625 char * encPeerTo; 1708 char *encPeerTo;
1626#endif 1709#endif
1627 struct DistantNeighbor *about; 1710 struct DistantNeighbor *about;
1628 struct DirectNeighbor *to; 1711 struct DirectNeighbor *to;
@@ -1631,41 +1714,41 @@ neighbor_send_task (void *cls,
1631 p2p_dv_MESSAGE_NeighborInfo *message; 1714 p2p_dv_MESSAGE_NeighborInfo *message;
1632 struct PendingMessage *pending_message; 1715 struct PendingMessage *pending_message;
1633 1716
1634 if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0) 1717 if ((tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
1635 { 1718 {
1636#if DEBUG_DV_GOSSIP 1719#if DEBUG_DV_GOSSIP
1637 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1720 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1638 "%s: Called with reason shutdown, shutting down!\n", 1721 "%s: Called with reason shutdown, shutting down!\n",
1639 GNUNET_i2s(&my_identity)); 1722 GNUNET_i2s (&my_identity));
1640#endif 1723#endif
1641 return; 1724 return;
1642 } 1725 }
1643 1726
1644 if (send_context->fast_gossip_list_head != NULL) 1727 if (send_context->fast_gossip_list_head != NULL)
1645 { 1728 {
1646 about_list = send_context->fast_gossip_list_head; 1729 about_list = send_context->fast_gossip_list_head;
1647 about = about_list->about; 1730 about = about_list->about;
1648 GNUNET_CONTAINER_DLL_remove(send_context->fast_gossip_list_head, 1731 GNUNET_CONTAINER_DLL_remove (send_context->fast_gossip_list_head,
1649 send_context->fast_gossip_list_tail, 1732 send_context->fast_gossip_list_tail,
1650 about_list); 1733 about_list);
1651 GNUNET_free(about_list); 1734 GNUNET_free (about_list);
1652 } 1735 }
1653 else 1736 else
1654 { 1737 {
1655 /* FIXME: this may become a problem, because the heap walk has only one internal "walker". This means 1738 /* FIXME: this may become a problem, because the heap walk has only one internal "walker". This means
1656 * that if two neighbor_send_tasks are operating in lockstep (which is quite possible, given default 1739 * that if two neighbor_send_tasks are operating in lockstep (which is quite possible, given default
1657 * values for all connected peers) there may be a serious bias as to which peers get gossiped about! 1740 * values for all connected peers) there may be a serious bias as to which peers get gossiped about!
1658 * Probably the *best* way to fix would be to have an opaque pointer to the walk position passed as 1741 * Probably the *best* way to fix would be to have an opaque pointer to the walk position passed as
1659 * part of the walk_get_next call. Then the heap would have to keep a list of walks, or reset the walk 1742 * part of the walk_get_next call. Then the heap would have to keep a list of walks, or reset the walk
1660 * whenever a modification has been detected. Yuck either way. Perhaps we could iterate over the heap 1743 * whenever a modification has been detected. Yuck either way. Perhaps we could iterate over the heap
1661 * once to get a list of peers to gossip about and gossip them over time... But then if one goes away 1744 * once to get a list of peers to gossip about and gossip them over time... But then if one goes away
1662 * in the mean time that becomes nasty. For now we'll just assume that the walking is done 1745 * in the mean time that becomes nasty. For now we'll just assume that the walking is done
1663 * asynchronously enough to avoid major problems (-; 1746 * asynchronously enough to avoid major problems (-;
1664 * 1747 *
1665 * NOTE: probably fixed once we decided send rate based on allowed bandwidth. 1748 * NOTE: probably fixed once we decided send rate based on allowed bandwidth.
1666 */ 1749 */
1667 about = GNUNET_CONTAINER_heap_walk_get_next (neighbor_min_heap); 1750 about = GNUNET_CONTAINER_heap_walk_get_next (neighbor_min_heap);
1668 } 1751 }
1669 to = send_context->toNeighbor; 1752 to = send_context->toNeighbor;
1670 1753
1671 if ((about != NULL) && (to != about->referrer /* split horizon */ ) && 1754 if ((about != NULL) && (to != about->referrer /* split horizon */ ) &&
@@ -1674,61 +1757,69 @@ neighbor_send_task (void *cls,
1674#endif 1757#endif
1675 (to != NULL) && 1758 (to != NULL) &&
1676 (0 != memcmp (&about->identity, 1759 (0 != memcmp (&about->identity,
1677 &to->identity, sizeof (struct GNUNET_PeerIdentity))) && 1760 &to->identity, sizeof (struct GNUNET_PeerIdentity))) &&
1678 (about->pkey != NULL)) 1761 (about->pkey != NULL))
1679 { 1762 {
1680#if DEBUG_DV_GOSSIP_SEND 1763#if DEBUG_DV_GOSSIP_SEND
1681 encPeerAbout = GNUNET_strdup(GNUNET_i2s(&about->identity)); 1764 encPeerAbout = GNUNET_strdup (GNUNET_i2s (&about->identity));
1682 encPeerTo = GNUNET_strdup(GNUNET_i2s(&to->identity)); 1765 encPeerTo = GNUNET_strdup (GNUNET_i2s (&to->identity));
1683 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1766 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1684 "%s: Sending info about peer %s id %u to directly connected peer %s\n", 1767 "%s: Sending info about peer %s id %u to directly connected peer %s\n",
1685 GNUNET_i2s(&my_identity), 1768 GNUNET_i2s (&my_identity),
1686 encPeerAbout, about->our_id, encPeerTo); 1769 encPeerAbout, about->our_id, encPeerTo);
1687 GNUNET_free(encPeerAbout); 1770 GNUNET_free (encPeerAbout);
1688 GNUNET_free(encPeerTo); 1771 GNUNET_free (encPeerTo);
1689#endif 1772#endif
1690 about->last_gossip = GNUNET_TIME_absolute_get(); 1773 about->last_gossip = GNUNET_TIME_absolute_get ();
1691 pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + sizeof(p2p_dv_MESSAGE_NeighborInfo)); 1774 pending_message =
1692 pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1]; 1775 GNUNET_malloc (sizeof (struct PendingMessage) +
1693 pending_message->importance = default_dv_priority; 1776 sizeof (p2p_dv_MESSAGE_NeighborInfo));
1694 pending_message->timeout = GNUNET_TIME_relative_get_forever(); 1777 pending_message->msg = (struct GNUNET_MessageHeader *) &pending_message[1];
1695 memcpy(&pending_message->recipient, &to->identity, sizeof(struct GNUNET_PeerIdentity)); 1778 pending_message->importance = default_dv_priority;
1696 pending_message->msg_size = sizeof(p2p_dv_MESSAGE_NeighborInfo); 1779 pending_message->timeout = GNUNET_TIME_relative_get_forever ();
1697 message = (p2p_dv_MESSAGE_NeighborInfo *)pending_message->msg; 1780 memcpy (&pending_message->recipient, &to->identity,
1698 message->header.size = htons (sizeof (p2p_dv_MESSAGE_NeighborInfo)); 1781 sizeof (struct GNUNET_PeerIdentity));
1699 message->header.type = htons (GNUNET_MESSAGE_TYPE_DV_GOSSIP); 1782 pending_message->msg_size = sizeof (p2p_dv_MESSAGE_NeighborInfo);
1700 message->cost = htonl (about->cost); 1783 message = (p2p_dv_MESSAGE_NeighborInfo *) pending_message->msg;
1701 message->neighbor_id = htonl (about->our_id); 1784 message->header.size = htons (sizeof (p2p_dv_MESSAGE_NeighborInfo));
1702 1785 message->header.type = htons (GNUNET_MESSAGE_TYPE_DV_GOSSIP);
1703 memcpy (&message->pkey, about->pkey, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 1786 message->cost = htonl (about->cost);
1704 memcpy (&message->neighbor, 1787 message->neighbor_id = htonl (about->our_id);
1705 &about->identity, sizeof (struct GNUNET_PeerIdentity)); 1788
1706 1789 memcpy (&message->pkey, about->pkey,
1707 GNUNET_CONTAINER_DLL_insert_after (core_pending_head, 1790 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
1708 core_pending_tail, 1791 memcpy (&message->neighbor, &about->identity,
1709 core_pending_tail, 1792 sizeof (struct GNUNET_PeerIdentity));
1710 pending_message); 1793
1711 1794 GNUNET_CONTAINER_DLL_insert_after (core_pending_head,
1712 GNUNET_SCHEDULER_add_now(try_core_send, NULL); 1795 core_pending_tail,
1713 /*if (core_transmit_handle == NULL) 1796 core_pending_tail, pending_message);
1714 core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, GNUNET_YES, default_dv_priority, GNUNET_TIME_relative_get_forever(), &to->identity, sizeof(p2p_dv_MESSAGE_NeighborInfo), &core_transmit_notify, NULL);*/ 1797
1798 GNUNET_SCHEDULER_add_now (try_core_send, NULL);
1799 /*if (core_transmit_handle == NULL)
1800 * core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, GNUNET_YES, default_dv_priority, GNUNET_TIME_relative_get_forever(), &to->identity, sizeof(p2p_dv_MESSAGE_NeighborInfo), &core_transmit_notify, NULL); */
1715 1801
1716 } 1802 }
1717 1803
1718 if (send_context->fast_gossip_list_head != NULL) /* If there are other peers in the fast list, schedule right away */ 1804 if (send_context->fast_gossip_list_head != NULL) /* If there are other peers in the fast list, schedule right away */
1719 { 1805 {
1720#if DEBUG_DV_PEER_NUMBERS 1806#if DEBUG_DV_PEER_NUMBERS
1721 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "DV SERVICE: still in fast send mode\n"); 1807 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1808 "DV SERVICE: still in fast send mode\n");
1722#endif 1809#endif
1723 send_context->task = GNUNET_SCHEDULER_add_now(&neighbor_send_task, send_context); 1810 send_context->task =
1724 } 1811 GNUNET_SCHEDULER_add_now (&neighbor_send_task, send_context);
1812 }
1725 else 1813 else
1726 { 1814 {
1727#if DEBUG_DV_PEER_NUMBERS 1815#if DEBUG_DV_PEER_NUMBERS
1728 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "DV SERVICE: entering slow send mode\n"); 1816 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1817 "DV SERVICE: entering slow send mode\n");
1729#endif 1818#endif
1730 send_context->task = GNUNET_SCHEDULER_add_delayed(GNUNET_DV_DEFAULT_SEND_INTERVAL, &neighbor_send_task, send_context); 1819 send_context->task =
1731 } 1820 GNUNET_SCHEDULER_add_delayed (GNUNET_DV_DEFAULT_SEND_INTERVAL,
1821 &neighbor_send_task, send_context);
1822 }
1732 1823
1733 return; 1824 return;
1734} 1825}
@@ -1755,7 +1846,7 @@ handle_start (void *cls,
1755 1846
1756 client_handle = client; 1847 client_handle = client;
1757 1848
1758 GNUNET_SERVER_client_keep(client_handle); 1849 GNUNET_SERVER_client_keep (client_handle);
1759 GNUNET_SERVER_receive_done (client, GNUNET_OK); 1850 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1760} 1851}
1761 1852
@@ -1771,18 +1862,17 @@ handle_start (void *cls,
1771 * iterate, 1862 * iterate,
1772 * GNUNET_NO if not. 1863 * GNUNET_NO if not.
1773 */ 1864 */
1774int send_iterator (void *cls, 1865int
1775 const GNUNET_HashCode * key, 1866send_iterator (void *cls, const GNUNET_HashCode * key, void *abs_value)
1776 void *abs_value)
1777{ 1867{
1778 struct DV_SendContext *send_context = cls; 1868 struct DV_SendContext *send_context = cls;
1779 struct DistantNeighbor *distant_neighbor = abs_value; 1869 struct DistantNeighbor *distant_neighbor = abs_value;
1780 1870
1781 if (memcmp(distant_neighbor->referrer, send_context->direct_peer, sizeof(struct GNUNET_PeerIdentity)) == 0) /* They match, send and free */ 1871 if (memcmp (distant_neighbor->referrer, send_context->direct_peer, sizeof (struct GNUNET_PeerIdentity)) == 0) /* They match, send and free */
1782 { 1872 {
1783 send_message_via(&my_identity, distant_neighbor, send_context); 1873 send_message_via (&my_identity, distant_neighbor, send_context);
1784 return GNUNET_NO; 1874 return GNUNET_NO;
1785 } 1875 }
1786 return GNUNET_YES; 1876 return GNUNET_YES;
1787} 1877}
1788#endif 1878#endif
@@ -1795,9 +1885,10 @@ int send_iterator (void *cls,
1795 * @param client identification of the client 1885 * @param client identification of the client
1796 * @param message the actual message 1886 * @param message the actual message
1797 */ 1887 */
1798void handle_dv_send_message (void *cls, 1888void
1799 struct GNUNET_SERVER_Client * client, 1889handle_dv_send_message (void *cls,
1800 const struct GNUNET_MessageHeader * message) 1890 struct GNUNET_SERVER_Client *client,
1891 const struct GNUNET_MessageHeader *message)
1801{ 1892{
1802 struct GNUNET_DV_SendMessage *send_msg; 1893 struct GNUNET_DV_SendMessage *send_msg;
1803 struct GNUNET_DV_SendResultMessage *send_result_msg; 1894 struct GNUNET_DV_SendResultMessage *send_result_msg;
@@ -1811,6 +1902,7 @@ void handle_dv_send_message (void *cls,
1811 int offset; 1902 int offset;
1812 static struct GNUNET_CRYPTO_HashAsciiEncoded dest_hash; 1903 static struct GNUNET_CRYPTO_HashAsciiEncoded dest_hash;
1813 struct DV_SendContext *send_context; 1904 struct DV_SendContext *send_context;
1905
1814#if DEBUG_DV_MESSAGES 1906#if DEBUG_DV_MESSAGES
1815 char *cbuf; 1907 char *cbuf;
1816 struct GNUNET_MessageHeader *packed_message; 1908 struct GNUNET_MessageHeader *packed_message;
@@ -1820,7 +1912,8 @@ void handle_dv_send_message (void *cls,
1820 { 1912 {
1821 client_handle = client; 1913 client_handle = client;
1822 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1914 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1823 "%s: Setting initial client handle, never received `%s' message?\n", "dv", "START"); 1915 "%s: Setting initial client handle, never received `%s' message?\n",
1916 "dv", "START");
1824 } 1917 }
1825 else if (client_handle != client) 1918 else if (client_handle != client)
1826 { 1919 {
@@ -1832,55 +1925,67 @@ void handle_dv_send_message (void *cls,
1832#endif 1925#endif
1833 } 1926 }
1834 1927
1835 GNUNET_assert(ntohs(message->size) > sizeof(struct GNUNET_DV_SendMessage)); 1928 GNUNET_assert (ntohs (message->size) > sizeof (struct GNUNET_DV_SendMessage));
1836 send_msg = (struct GNUNET_DV_SendMessage *)message; 1929 send_msg = (struct GNUNET_DV_SendMessage *) message;
1837 1930
1838 address_len = ntohl(send_msg->addrlen); 1931 address_len = ntohl (send_msg->addrlen);
1839 GNUNET_assert(address_len == sizeof(struct GNUNET_PeerIdentity) * 2); 1932 GNUNET_assert (address_len == sizeof (struct GNUNET_PeerIdentity) * 2);
1840 message_size = ntohs(message->size) - sizeof(struct GNUNET_DV_SendMessage) - address_len; 1933 message_size =
1841 destination = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); 1934 ntohs (message->size) - sizeof (struct GNUNET_DV_SendMessage) -
1842 direct = GNUNET_malloc(sizeof(struct GNUNET_PeerIdentity)); 1935 address_len;
1843 message_buf = GNUNET_malloc(message_size); 1936 destination = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
1937 direct = GNUNET_malloc (sizeof (struct GNUNET_PeerIdentity));
1938 message_buf = GNUNET_malloc (message_size);
1844 1939
1845 temp_pos = (char *)&send_msg[1]; /* Set pointer to end of message */ 1940 temp_pos = (char *) &send_msg[1]; /* Set pointer to end of message */
1846 offset = 0; /* Offset starts at zero */ 1941 offset = 0; /* Offset starts at zero */
1847 1942
1848 memcpy(destination, &temp_pos[offset], sizeof(struct GNUNET_PeerIdentity)); 1943 memcpy (destination, &temp_pos[offset], sizeof (struct GNUNET_PeerIdentity));
1849 offset += sizeof(struct GNUNET_PeerIdentity); 1944 offset += sizeof (struct GNUNET_PeerIdentity);
1850 1945
1851 memcpy(direct, &temp_pos[offset], sizeof(struct GNUNET_PeerIdentity)); 1946 memcpy (direct, &temp_pos[offset], sizeof (struct GNUNET_PeerIdentity));
1852 offset += sizeof(struct GNUNET_PeerIdentity); 1947 offset += sizeof (struct GNUNET_PeerIdentity);
1853 1948
1854 1949
1855 memcpy(message_buf, &temp_pos[offset], message_size); 1950 memcpy (message_buf, &temp_pos[offset], message_size);
1856 if (memcmp(&send_msg->target, destination, sizeof(struct GNUNET_PeerIdentity)) != 0) 1951 if (memcmp
1857 { 1952 (&send_msg->target, destination,
1858 GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /* GNUNET_i2s won't properly work, need to hash one ourselves */ 1953 sizeof (struct GNUNET_PeerIdentity)) != 0)
1859 dest_hash.encoding[4] = '\0'; 1954 {
1860 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: asked to send message to `%s', but address is for `%s'!", "DV SERVICE", GNUNET_i2s(&send_msg->target), (const char *)&dest_hash.encoding); 1955 GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /* GNUNET_i2s won't properly work, need to hash one ourselves */
1861 } 1956 dest_hash.encoding[4] = '\0';
1957 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1958 "%s: asked to send message to `%s', but address is for `%s'!",
1959 "DV SERVICE", GNUNET_i2s (&send_msg->target),
1960 (const char *) &dest_hash.encoding);
1961 }
1862 1962
1863#if DEBUG_DV_MESSAGES 1963#if DEBUG_DV_MESSAGES
1864 cbuf = (char *)message_buf; 1964 cbuf = (char *) message_buf;
1865 offset = 0; 1965 offset = 0;
1866 while(offset < message_size) 1966 while (offset < message_size)
1867 { 1967 {
1868 packed_message = (struct GNUNET_MessageHeader *)&cbuf[offset]; 1968 packed_message = (struct GNUNET_MessageHeader *) &cbuf[offset];
1869 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: DV PLUGIN SEND uid %u type %d to %s\n", my_short_id, ntohl(send_msg->uid), ntohs(packed_message->type), GNUNET_i2s(destination)); 1969 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1870 offset += ntohs(packed_message->size); 1970 "%s: DV PLUGIN SEND uid %u type %d to %s\n", my_short_id,
1871 } 1971 ntohl (send_msg->uid), ntohs (packed_message->type),
1872 /*GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: DV PLUGIN SEND uid %u type %d to %s\n", my_short_id, ntohl(send_msg->uid), ntohs(message_buf->type), GNUNET_i2s(destination));*/ 1972 GNUNET_i2s (destination));
1973 offset += ntohs (packed_message->size);
1974 }
1975 /*GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: DV PLUGIN SEND uid %u type %d to %s\n", my_short_id, ntohl(send_msg->uid), ntohs(message_buf->type), GNUNET_i2s(destination)); */
1873#endif 1976#endif
1874 GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /* GNUNET_i2s won't properly work, need to hash one ourselves */ 1977 GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /* GNUNET_i2s won't properly work, need to hash one ourselves */
1875 dest_hash.encoding[4] = '\0'; 1978 dest_hash.encoding[4] = '\0';
1876 send_context = GNUNET_malloc(sizeof(struct DV_SendContext)); 1979 send_context = GNUNET_malloc (sizeof (struct DV_SendContext));
1877 1980
1878 send_result_msg = GNUNET_malloc(sizeof(struct GNUNET_DV_SendResultMessage)); 1981 send_result_msg = GNUNET_malloc (sizeof (struct GNUNET_DV_SendResultMessage));
1879 send_result_msg->header.size = htons(sizeof(struct GNUNET_DV_SendResultMessage)); 1982 send_result_msg->header.size =
1880 send_result_msg->header.type = htons(GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND_RESULT); 1983 htons (sizeof (struct GNUNET_DV_SendResultMessage));
1984 send_result_msg->header.type =
1985 htons (GNUNET_MESSAGE_TYPE_TRANSPORT_DV_SEND_RESULT);
1881 send_result_msg->uid = send_msg->uid; /* No need to ntohl->htonl this */ 1986 send_result_msg->uid = send_msg->uid; /* No need to ntohl->htonl this */
1882 1987
1883 send_context->importance = ntohl(send_msg->priority); 1988 send_context->importance = ntohl (send_msg->priority);
1884 send_context->timeout = send_msg->timeout; 1989 send_context->timeout = send_msg->timeout;
1885 send_context->direct_peer = direct; 1990 send_context->direct_peer = direct;
1886 send_context->distant_peer = destination; 1991 send_context->distant_peer = destination;
@@ -1891,84 +1996,111 @@ void handle_dv_send_message (void *cls,
1891 send_context->uid = send_msg->uid; 1996 send_context->uid = send_msg->uid;
1892#endif 1997#endif
1893 1998
1894 if (send_message_via(&my_identity, direct, send_context) != GNUNET_YES) 1999 if (send_message_via (&my_identity, direct, send_context) != GNUNET_YES)
2000 {
2001 send_result_msg->result = htons (1);
2002 pending_message =
2003 GNUNET_malloc (sizeof (struct PendingMessage) +
2004 sizeof (struct GNUNET_DV_SendResultMessage));
2005 pending_message->msg = (struct GNUNET_MessageHeader *) &pending_message[1];
2006 memcpy (&pending_message[1], send_result_msg,
2007 sizeof (struct GNUNET_DV_SendResultMessage));
2008 GNUNET_free (send_result_msg);
2009
2010 GNUNET_CONTAINER_DLL_insert_after (plugin_pending_head, plugin_pending_tail,
2011 plugin_pending_tail, pending_message);
2012
2013 if (client_handle != NULL)
1895 { 2014 {
1896 send_result_msg->result = htons(1); 2015 if (plugin_transmit_handle == NULL)
1897 pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + sizeof(struct GNUNET_DV_SendResultMessage)); 2016 {
1898 pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1]; 2017 plugin_transmit_handle =
1899 memcpy(&pending_message[1], send_result_msg, sizeof(struct GNUNET_DV_SendResultMessage)); 2018 GNUNET_SERVER_notify_transmit_ready (client_handle,
1900 GNUNET_free(send_result_msg); 2019 sizeof (struct
1901 2020 GNUNET_DV_SendResultMessage),
1902 GNUNET_CONTAINER_DLL_insert_after(plugin_pending_head, plugin_pending_tail, plugin_pending_tail, pending_message); 2021 GNUNET_TIME_UNIT_FOREVER_REL,
1903 2022 &transmit_to_plugin, NULL);
1904 if (client_handle != NULL) 2023 }
1905 { 2024 else
1906 if (plugin_transmit_handle == NULL) 2025 {
1907 { 2026 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1908 plugin_transmit_handle = GNUNET_SERVER_notify_transmit_ready (client_handle, 2027 "Failed to queue message for plugin, must be one in progress already!!\n");
1909 sizeof(struct GNUNET_DV_SendResultMessage), 2028 }
1910 GNUNET_TIME_UNIT_FOREVER_REL,
1911 &transmit_to_plugin, NULL);
1912 }
1913 else
1914 {
1915 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to queue message for plugin, must be one in progress already!!\n");
1916 }
1917 }
1918 GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /* GNUNET_i2s won't properly work, need to hash one ourselves */
1919 dest_hash.encoding[4] = '\0';
1920 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s DV SEND failed to send message to destination `%s' via `%s'\n", my_short_id, (const char *)&dest_hash.encoding, GNUNET_i2s(direct));
1921 } 2029 }
2030 GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /* GNUNET_i2s won't properly work, need to hash one ourselves */
2031 dest_hash.encoding[4] = '\0';
2032 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2033 "%s DV SEND failed to send message to destination `%s' via `%s'\n",
2034 my_short_id, (const char *) &dest_hash.encoding,
2035 GNUNET_i2s (direct));
2036 }
1922 2037
1923 /* In bizarro world GNUNET_SYSERR indicates that we succeeded */ 2038 /* In bizarro world GNUNET_SYSERR indicates that we succeeded */
1924#if UNSIMPLER 2039#if UNSIMPLER
1925 if (GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_get_multiple(extended_neighbors, &destination->hashPubKey, &send_iterator, send_context)) 2040 if (GNUNET_SYSERR !=
2041 GNUNET_CONTAINER_multihashmap_get_multiple (extended_neighbors,
2042 &destination->hashPubKey,
2043 &send_iterator, send_context))
2044 {
2045 send_result_msg->result = htons (1);
2046 pending_message =
2047 GNUNET_malloc (sizeof (struct PendingMessage) +
2048 sizeof (struct GNUNET_DV_SendResultMessage));
2049 pending_message->msg = (struct GNUNET_MessageHeader *) &pending_message[1];
2050 memcpy (&pending_message[1], send_result_msg,
2051 sizeof (struct GNUNET_DV_SendResultMessage));
2052 GNUNET_free (send_result_msg);
2053
2054 GNUNET_CONTAINER_DLL_insert_after (plugin_pending_head, plugin_pending_tail,
2055 plugin_pending_tail, pending_message);
2056
2057 if (client_handle != NULL)
1926 { 2058 {
1927 send_result_msg->result = htons(1); 2059 if (plugin_transmit_handle == NULL)
1928 pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + sizeof(struct GNUNET_DV_SendResultMessage)); 2060 {
1929 pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1]; 2061 plugin_transmit_handle =
1930 memcpy(&pending_message[1], send_result_msg, sizeof(struct GNUNET_DV_SendResultMessage)); 2062 GNUNET_SERVER_notify_transmit_ready (client_handle,
1931 GNUNET_free(send_result_msg); 2063 sizeof (struct
1932 2064 GNUNET_DV_SendResultMessage),
1933 GNUNET_CONTAINER_DLL_insert_after(plugin_pending_head, plugin_pending_tail, plugin_pending_tail, pending_message); 2065 GNUNET_TIME_UNIT_FOREVER_REL,
1934 2066 &transmit_to_plugin, NULL);
1935 if (client_handle != NULL) 2067 }
1936 { 2068 else
1937 if (plugin_transmit_handle == NULL) 2069 {
1938 { 2070 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1939 plugin_transmit_handle = GNUNET_SERVER_notify_transmit_ready (client_handle, 2071 "Failed to queue message for plugin, must be one in progress already!!\n");
1940 sizeof(struct GNUNET_DV_SendResultMessage), 2072 }
1941 GNUNET_TIME_UNIT_FOREVER_REL,
1942 &transmit_to_plugin, NULL);
1943 }
1944 else
1945 {
1946 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Failed to queue message for plugin, must be one in progress already!!\n");
1947 }
1948 }
1949 GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /* GNUNET_i2s won't properly work, need to hash one ourselves */
1950 dest_hash.encoding[4] = '\0';
1951 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s DV SEND failed to send message to destination `%s' via `%s'\n", my_short_id, (const char *)&dest_hash.encoding, GNUNET_i2s(direct));
1952 } 2073 }
2074 GNUNET_CRYPTO_hash_to_enc (&destination->hashPubKey, &dest_hash); /* GNUNET_i2s won't properly work, need to hash one ourselves */
2075 dest_hash.encoding[4] = '\0';
2076 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2077 "%s DV SEND failed to send message to destination `%s' via `%s'\n",
2078 my_short_id, (const char *) &dest_hash.encoding,
2079 GNUNET_i2s (direct));
2080 }
1953#endif 2081#endif
1954 GNUNET_free(message_buf); 2082 GNUNET_free (message_buf);
1955 GNUNET_free(send_context); 2083 GNUNET_free (send_context);
1956 GNUNET_free(direct); 2084 GNUNET_free (direct);
1957 GNUNET_free(destination); 2085 GNUNET_free (destination);
1958 2086
1959 GNUNET_SERVER_receive_done(client, GNUNET_OK); 2087 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1960} 2088}
1961 2089
1962/** Forward declarations **/ 2090/** Forward declarations **/
1963static int handle_dv_gossip_message (void *cls, 2091static int handle_dv_gossip_message (void *cls,
1964 const struct GNUNET_PeerIdentity *peer, 2092 const struct GNUNET_PeerIdentity *peer,
1965 const struct GNUNET_MessageHeader *message, 2093 const struct GNUNET_MessageHeader *message,
1966 const struct GNUNET_TRANSPORT_ATS_Information *atsi); 2094 const struct
2095 GNUNET_TRANSPORT_ATS_Information *atsi);
1967 2096
1968static int handle_dv_disconnect_message (void *cls, 2097static int handle_dv_disconnect_message (void *cls,
1969 const struct GNUNET_PeerIdentity *peer, 2098 const struct GNUNET_PeerIdentity *peer,
1970 const struct GNUNET_MessageHeader *message, 2099 const struct GNUNET_MessageHeader
1971 const struct GNUNET_TRANSPORT_ATS_Information *atsi); 2100 *message,
2101 const struct
2102 GNUNET_TRANSPORT_ATS_Information
2103 *atsi);
1972/** End forward declarations **/ 2104/** End forward declarations **/
1973 2105
1974 2106
@@ -2006,14 +2138,14 @@ distant_neighbor_free (struct DistantNeighbor *referee)
2006 2138
2007 referrer = referee->referrer; 2139 referrer = referee->referrer;
2008 if (referrer != NULL) 2140 if (referrer != NULL)
2009 { 2141 {
2010 GNUNET_CONTAINER_DLL_remove (referrer->referee_head, 2142 GNUNET_CONTAINER_DLL_remove (referrer->referee_head,
2011 referrer->referee_tail, referee); 2143 referrer->referee_tail, referee);
2012 } 2144 }
2013 GNUNET_CONTAINER_heap_remove_node (referee->max_loc); 2145 GNUNET_CONTAINER_heap_remove_node (referee->max_loc);
2014 GNUNET_CONTAINER_heap_remove_node (referee->min_loc); 2146 GNUNET_CONTAINER_heap_remove_node (referee->min_loc);
2015 GNUNET_CONTAINER_multihashmap_remove_all (extended_neighbors, 2147 GNUNET_CONTAINER_multihashmap_remove_all (extended_neighbors,
2016 &referee->identity.hashPubKey); 2148 &referee->identity.hashPubKey);
2017 GNUNET_free_non_null (referee->pkey); 2149 GNUNET_free_non_null (referee->pkey);
2018 GNUNET_free (referee); 2150 GNUNET_free (referee);
2019} 2151}
@@ -2032,18 +2164,20 @@ direct_neighbor_free (struct DirectNeighbor *direct)
2032 send_context = direct->send_context; 2164 send_context = direct->send_context;
2033 2165
2034 if (send_context->task != GNUNET_SCHEDULER_NO_TASK) 2166 if (send_context->task != GNUNET_SCHEDULER_NO_TASK)
2035 GNUNET_SCHEDULER_cancel(send_context->task); 2167 GNUNET_SCHEDULER_cancel (send_context->task);
2036 2168
2037 about_list = send_context->fast_gossip_list_head; 2169 about_list = send_context->fast_gossip_list_head;
2038 while (about_list != NULL) 2170 while (about_list != NULL)
2039 { 2171 {
2040 GNUNET_CONTAINER_DLL_remove(send_context->fast_gossip_list_head, send_context->fast_gossip_list_tail, about_list); 2172 GNUNET_CONTAINER_DLL_remove (send_context->fast_gossip_list_head,
2041 prev_about = about_list; 2173 send_context->fast_gossip_list_tail,
2042 about_list = about_list->next; 2174 about_list);
2043 GNUNET_free(prev_about); 2175 prev_about = about_list;
2044 } 2176 about_list = about_list->next;
2045 GNUNET_free(send_context); 2177 GNUNET_free (prev_about);
2046 GNUNET_free(direct); 2178 }
2179 GNUNET_free (send_context);
2180 GNUNET_free (direct);
2047} 2181}
2048 2182
2049/** 2183/**
@@ -2056,9 +2190,9 @@ direct_neighbor_free (struct DirectNeighbor *direct)
2056 * 2190 *
2057 * @return GNUNET_YES to continue iteration, GNUNET_NO to stop 2191 * @return GNUNET_YES to continue iteration, GNUNET_NO to stop
2058 */ 2192 */
2059static int schedule_disconnect_messages (void *cls, 2193static int
2060 const GNUNET_HashCode * key, 2194schedule_disconnect_messages (void *cls,
2061 void *value) 2195 const GNUNET_HashCode * key, void *value)
2062{ 2196{
2063 struct DisconnectContext *disconnect_context = cls; 2197 struct DisconnectContext *disconnect_context = cls;
2064 struct DirectNeighbor *disconnected = disconnect_context->direct; 2198 struct DirectNeighbor *disconnected = disconnect_context->direct;
@@ -2066,28 +2200,32 @@ static int schedule_disconnect_messages (void *cls,
2066 struct PendingMessage *pending_message; 2200 struct PendingMessage *pending_message;
2067 p2p_dv_MESSAGE_Disconnect *disconnect_message; 2201 p2p_dv_MESSAGE_Disconnect *disconnect_message;
2068 2202
2069 if (memcmp(&notify->identity, &disconnected->identity, sizeof(struct GNUNET_PeerIdentity)) == 0) 2203 if (memcmp
2070 return GNUNET_YES; /* Don't send disconnect message to peer that disconnected! */ 2204 (&notify->identity, &disconnected->identity,
2205 sizeof (struct GNUNET_PeerIdentity)) == 0)
2206 return GNUNET_YES; /* Don't send disconnect message to peer that disconnected! */
2071 2207
2072 pending_message = GNUNET_malloc(sizeof(struct PendingMessage) + sizeof(p2p_dv_MESSAGE_Disconnect)); 2208 pending_message =
2073 pending_message->msg = (struct GNUNET_MessageHeader *)&pending_message[1]; 2209 GNUNET_malloc (sizeof (struct PendingMessage) +
2210 sizeof (p2p_dv_MESSAGE_Disconnect));
2211 pending_message->msg = (struct GNUNET_MessageHeader *) &pending_message[1];
2074 pending_message->importance = default_dv_priority; 2212 pending_message->importance = default_dv_priority;
2075 pending_message->timeout = GNUNET_TIME_relative_get_forever(); 2213 pending_message->timeout = GNUNET_TIME_relative_get_forever ();
2076 memcpy(&pending_message->recipient, &notify->identity, sizeof(struct GNUNET_PeerIdentity)); 2214 memcpy (&pending_message->recipient, &notify->identity,
2077 pending_message->msg_size = sizeof(p2p_dv_MESSAGE_Disconnect); 2215 sizeof (struct GNUNET_PeerIdentity));
2078 disconnect_message = (p2p_dv_MESSAGE_Disconnect *)pending_message->msg; 2216 pending_message->msg_size = sizeof (p2p_dv_MESSAGE_Disconnect);
2217 disconnect_message = (p2p_dv_MESSAGE_Disconnect *) pending_message->msg;
2079 disconnect_message->header.size = htons (sizeof (p2p_dv_MESSAGE_Disconnect)); 2218 disconnect_message->header.size = htons (sizeof (p2p_dv_MESSAGE_Disconnect));
2080 disconnect_message->header.type = htons (GNUNET_MESSAGE_TYPE_DV_DISCONNECT); 2219 disconnect_message->header.type = htons (GNUNET_MESSAGE_TYPE_DV_DISCONNECT);
2081 disconnect_message->peer_id = htonl(disconnect_context->distant->our_id); 2220 disconnect_message->peer_id = htonl (disconnect_context->distant->our_id);
2082 2221
2083 GNUNET_CONTAINER_DLL_insert_after (core_pending_head, 2222 GNUNET_CONTAINER_DLL_insert_after (core_pending_head,
2084 core_pending_tail, 2223 core_pending_tail,
2085 core_pending_tail, 2224 core_pending_tail, pending_message);
2086 pending_message);
2087 2225
2088 GNUNET_SCHEDULER_add_now(try_core_send, NULL); 2226 GNUNET_SCHEDULER_add_now (try_core_send, NULL);
2089 /*if (core_transmit_handle == NULL) 2227 /*if (core_transmit_handle == NULL)
2090 core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, GNUNET_YES, default_dv_priority, GNUNET_TIME_relative_get_forever(), &notify->identity, sizeof(p2p_dv_MESSAGE_Disconnect), &core_transmit_notify, NULL);*/ 2228 * core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, GNUNET_YES, default_dv_priority, GNUNET_TIME_relative_get_forever(), &notify->identity, sizeof(p2p_dv_MESSAGE_Disconnect), &core_transmit_notify, NULL); */
2091 2229
2092 return GNUNET_YES; 2230 return GNUNET_YES;
2093} 2231}
@@ -2101,12 +2239,12 @@ static int schedule_disconnect_messages (void *cls,
2101 * 2239 *
2102 * @return GNUNET_YES to continue iteration, GNUNET_NO to stop 2240 * @return GNUNET_YES to continue iteration, GNUNET_NO to stop
2103 */ 2241 */
2104static int free_extended_neighbors (void *cls, 2242static int
2105 const GNUNET_HashCode * key, 2243free_extended_neighbors (void *cls, const GNUNET_HashCode * key, void *value)
2106 void *value)
2107{ 2244{
2108 struct DistantNeighbor *distant = value; 2245 struct DistantNeighbor *distant = value;
2109 distant_neighbor_free(distant); 2246
2247 distant_neighbor_free (distant);
2110 return GNUNET_YES; 2248 return GNUNET_YES;
2111} 2249}
2112 2250
@@ -2119,12 +2257,12 @@ static int free_extended_neighbors (void *cls,
2119 * 2257 *
2120 * @return GNUNET_YES to continue iteration, GNUNET_NO to stop 2258 * @return GNUNET_YES to continue iteration, GNUNET_NO to stop
2121 */ 2259 */
2122static int free_direct_neighbors (void *cls, 2260static int
2123 const GNUNET_HashCode * key, 2261free_direct_neighbors (void *cls, const GNUNET_HashCode * key, void *value)
2124 void *value)
2125{ 2262{
2126 struct DirectNeighbor *direct = value; 2263 struct DirectNeighbor *direct = value;
2127 direct_neighbor_free(direct); 2264
2265 direct_neighbor_free (direct);
2128 return GNUNET_YES; 2266 return GNUNET_YES;
2129} 2267}
2130 2268
@@ -2136,52 +2274,56 @@ static int free_direct_neighbors (void *cls,
2136 * @param tc unused 2274 * @param tc unused
2137 */ 2275 */
2138static void 2276static void
2139shutdown_task (void *cls, 2277shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2140 const struct GNUNET_SCHEDULER_TaskContext *tc)
2141{ 2278{
2142#if DEBUG_DV 2279#if DEBUG_DV
2143 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "calling CORE_DISCONNECT\n"); 2280 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "calling CORE_DISCONNECT\n");
2144 GNUNET_CONTAINER_multihashmap_iterate(extended_neighbors, &print_neighbors, NULL); 2281 GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors, &print_neighbors,
2282 NULL);
2145#endif 2283#endif
2146 GNUNET_CONTAINER_multihashmap_iterate(extended_neighbors, &free_extended_neighbors, NULL); 2284 GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors,
2147 GNUNET_CONTAINER_multihashmap_destroy(extended_neighbors); 2285 &free_extended_neighbors, NULL);
2148 GNUNET_CONTAINER_multihashmap_iterate(direct_neighbors, &free_direct_neighbors, NULL); 2286 GNUNET_CONTAINER_multihashmap_destroy (extended_neighbors);
2149 GNUNET_CONTAINER_multihashmap_destroy(direct_neighbors); 2287 GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors,
2288 &free_direct_neighbors, NULL);
2289 GNUNET_CONTAINER_multihashmap_destroy (direct_neighbors);
2150 2290
2151 GNUNET_CONTAINER_heap_destroy(neighbor_max_heap); 2291 GNUNET_CONTAINER_heap_destroy (neighbor_max_heap);
2152 GNUNET_CONTAINER_heap_destroy(neighbor_min_heap); 2292 GNUNET_CONTAINER_heap_destroy (neighbor_min_heap);
2153 2293
2154 GNUNET_CORE_disconnect (coreAPI); 2294 GNUNET_CORE_disconnect (coreAPI);
2155 coreAPI = NULL; 2295 coreAPI = NULL;
2156 GNUNET_PEERINFO_disconnect(peerinfo_handle); 2296 GNUNET_PEERINFO_disconnect (peerinfo_handle);
2157 GNUNET_SERVER_mst_destroy(coreMST); 2297 GNUNET_SERVER_mst_destroy (coreMST);
2158 GNUNET_free_non_null(my_short_id); 2298 GNUNET_free_non_null (my_short_id);
2159#if DEBUG_DV 2299#if DEBUG_DV
2160 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "CORE_DISCONNECT completed\n"); 2300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "CORE_DISCONNECT completed\n");
2161#endif 2301#endif
2162} 2302}
2163 2303
2164/** 2304/**
2165 * To be called on core init/fail. 2305 * To be called on core init/fail.
2166 */ 2306 */
2167void core_init (void *cls, 2307void
2168 struct GNUNET_CORE_Handle * server, 2308core_init (void *cls,
2169 const struct GNUNET_PeerIdentity *identity, 2309 struct GNUNET_CORE_Handle *server,
2170 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded * publicKey) 2310 const struct GNUNET_PeerIdentity *identity,
2311 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *publicKey)
2171{ 2312{
2172 2313
2173 if (server == NULL) 2314 if (server == NULL)
2174 { 2315 {
2175 GNUNET_SCHEDULER_cancel(cleanup_task); 2316 GNUNET_SCHEDULER_cancel (cleanup_task);
2176 GNUNET_SCHEDULER_add_now(&shutdown_task, NULL); 2317 GNUNET_SCHEDULER_add_now (&shutdown_task, NULL);
2177 return; 2318 return;
2178 } 2319 }
2179#if DEBUG_DV 2320#if DEBUG_DV
2180 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2321 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2181 "%s: Core connection initialized, I am peer: %s\n", "dv", GNUNET_i2s(identity)); 2322 "%s: Core connection initialized, I am peer: %s\n", "dv",
2323 GNUNET_i2s (identity));
2182#endif 2324#endif
2183 memcpy(&my_identity, identity, sizeof(struct GNUNET_PeerIdentity)); 2325 memcpy (&my_identity, identity, sizeof (struct GNUNET_PeerIdentity));
2184 my_short_id = GNUNET_strdup(GNUNET_i2s(&my_identity)); 2326 my_short_id = GNUNET_strdup (GNUNET_i2s (&my_identity));
2185 coreAPI = server; 2327 coreAPI = server;
2186} 2328}
2187 2329
@@ -2197,17 +2339,18 @@ void core_init (void *cls,
2197 * iterate, 2339 * iterate,
2198 * GNUNET_NO if not. 2340 * GNUNET_NO if not.
2199 */ 2341 */
2200static int add_pkey_to_extended (void *cls, 2342static int
2201 const GNUNET_HashCode * key, 2343add_pkey_to_extended (void *cls, const GNUNET_HashCode * key, void *abs_value)
2202 void *abs_value)
2203{ 2344{
2204 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey = cls; 2345 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey = cls;
2205 struct DistantNeighbor *distant_neighbor = abs_value; 2346 struct DistantNeighbor *distant_neighbor = abs_value;
2206 2347
2207 if (distant_neighbor->pkey == NULL) 2348 if (distant_neighbor->pkey == NULL)
2208 { 2349 {
2209 distant_neighbor->pkey = GNUNET_malloc(sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 2350 distant_neighbor->pkey =
2210 memcpy(distant_neighbor->pkey, pkey, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 2351 GNUNET_malloc (sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
2352 memcpy (distant_neighbor->pkey, pkey,
2353 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
2211 } 2354 }
2212 2355
2213 return GNUNET_YES; 2356 return GNUNET_YES;
@@ -2224,20 +2367,21 @@ static int add_pkey_to_extended (void *cls,
2224 * iterate, 2367 * iterate,
2225 * GNUNET_NO if not. 2368 * GNUNET_NO if not.
2226 */ 2369 */
2227static int update_matching_neighbors (void *cls, 2370static int
2228 const GNUNET_HashCode * key, 2371update_matching_neighbors (void *cls, const GNUNET_HashCode * key, void *value)
2229 void *value)
2230{ 2372{
2231 struct NeighborUpdateInfo * update_info = cls; 2373 struct NeighborUpdateInfo *update_info = cls;
2232 struct DistantNeighbor *distant_neighbor = value; 2374 struct DistantNeighbor *distant_neighbor = value;
2233 2375
2234 if (update_info->referrer == distant_neighbor->referrer) /* Direct neighbor matches, update it's info and return GNUNET_NO */ 2376 if (update_info->referrer == distant_neighbor->referrer) /* Direct neighbor matches, update it's info and return GNUNET_NO */
2235 { 2377 {
2236 /* same referrer, cost change! */ 2378 /* same referrer, cost change! */
2237 GNUNET_CONTAINER_heap_update_cost (neighbor_max_heap, 2379 GNUNET_CONTAINER_heap_update_cost (neighbor_max_heap,
2238 update_info->neighbor->max_loc, update_info->cost); 2380 update_info->neighbor->max_loc,
2381 update_info->cost);
2239 GNUNET_CONTAINER_heap_update_cost (neighbor_min_heap, 2382 GNUNET_CONTAINER_heap_update_cost (neighbor_min_heap,
2240 update_info->neighbor->min_loc, update_info->cost); 2383 update_info->neighbor->min_loc,
2384 update_info->cost);
2241 update_info->neighbor->last_activity = update_info->now; 2385 update_info->neighbor->last_activity = update_info->now;
2242 update_info->neighbor->cost = update_info->cost; 2386 update_info->neighbor->cost = update_info->cost;
2243 update_info->neighbor->referrer_id = update_info->referrer_peer_id; 2387 update_info->neighbor->referrer_id = update_info->referrer_peer_id;
@@ -2259,54 +2403,59 @@ static int update_matching_neighbors (void *cls,
2259 * 2403 *
2260 * @return GNUNET_YES to continue iteration, GNUNET_NO otherwise 2404 * @return GNUNET_YES to continue iteration, GNUNET_NO otherwise
2261 */ 2405 */
2262static int add_distant_all_direct_neighbors (void *cls, 2406static int
2263 const GNUNET_HashCode * key, 2407add_distant_all_direct_neighbors (void *cls,
2264 void *value) 2408 const GNUNET_HashCode * key, void *value)
2265{ 2409{
2266 struct DirectNeighbor *direct = (struct DirectNeighbor *)value; 2410 struct DirectNeighbor *direct = (struct DirectNeighbor *) value;
2267 struct DistantNeighbor *distant = (struct DistantNeighbor *)cls; 2411 struct DistantNeighbor *distant = (struct DistantNeighbor *) cls;
2268 struct NeighborSendContext *send_context = direct->send_context; 2412 struct NeighborSendContext *send_context = direct->send_context;
2269 struct FastGossipNeighborList *gossip_entry; 2413 struct FastGossipNeighborList *gossip_entry;
2414
2270#if DEBUG_DV 2415#if DEBUG_DV
2271 char *encPeerAbout; 2416 char *encPeerAbout;
2272 char *encPeerTo; 2417 char *encPeerTo;
2273#endif 2418#endif
2274 2419
2275 if (distant == NULL) 2420 if (distant == NULL)
2276 { 2421 {
2277 return GNUNET_YES; 2422 return GNUNET_YES;
2278 } 2423 }
2279 2424
2280 if (memcmp(&direct->identity, &distant->identity, sizeof(struct GNUNET_PeerIdentity)) == 0) 2425 if (memcmp
2281 { 2426 (&direct->identity, &distant->identity,
2282 return GNUNET_YES; /* Don't gossip to a peer about itself! */ 2427 sizeof (struct GNUNET_PeerIdentity)) == 0)
2283 } 2428 {
2429 return GNUNET_YES; /* Don't gossip to a peer about itself! */
2430 }
2284 2431
2285#if SUPPORT_HIDING 2432#if SUPPORT_HIDING
2286 if (distant->hidden == GNUNET_YES) 2433 if (distant->hidden == GNUNET_YES)
2287 return GNUNET_YES; /* This peer should not be gossipped about (hidden) */ 2434 return GNUNET_YES; /* This peer should not be gossipped about (hidden) */
2288#endif 2435#endif
2289 gossip_entry = GNUNET_malloc(sizeof(struct FastGossipNeighborList)); 2436 gossip_entry = GNUNET_malloc (sizeof (struct FastGossipNeighborList));
2290 gossip_entry->about = distant; 2437 gossip_entry->about = distant;
2291 2438
2292 GNUNET_CONTAINER_DLL_insert_after(send_context->fast_gossip_list_head, 2439 GNUNET_CONTAINER_DLL_insert_after (send_context->fast_gossip_list_head,
2293 send_context->fast_gossip_list_tail, 2440 send_context->fast_gossip_list_tail,
2294 send_context->fast_gossip_list_tail, 2441 send_context->fast_gossip_list_tail,
2295 gossip_entry); 2442 gossip_entry);
2296#if DEBUG_DV 2443#if DEBUG_DV
2297 encPeerAbout = GNUNET_strdup(GNUNET_i2s(&distant->identity)); 2444 encPeerAbout = GNUNET_strdup (GNUNET_i2s (&distant->identity));
2298 encPeerTo = GNUNET_strdup(GNUNET_i2s(&direct->identity)); 2445 encPeerTo = GNUNET_strdup (GNUNET_i2s (&direct->identity));
2299 2446
2300 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Fast send info about peer %s id %u for directly connected peer %s\n", 2447 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2301 GNUNET_i2s(&my_identity), 2448 "%s: Fast send info about peer %s id %u for directly connected peer %s\n",
2302 encPeerAbout, distant->our_id, encPeerTo); 2449 GNUNET_i2s (&my_identity), encPeerAbout, distant->our_id,
2303 GNUNET_free(encPeerAbout); 2450 encPeerTo);
2304 GNUNET_free(encPeerTo); 2451 GNUNET_free (encPeerAbout);
2452 GNUNET_free (encPeerTo);
2305#endif 2453#endif
2306 /*if (send_context->task != GNUNET_SCHEDULER_NO_TASK) 2454 /*if (send_context->task != GNUNET_SCHEDULER_NO_TASK)
2307 GNUNET_SCHEDULER_cancel(send_context->task);*/ 2455 * GNUNET_SCHEDULER_cancel(send_context->task); */
2308 2456
2309 send_context->task = GNUNET_SCHEDULER_add_now(&neighbor_send_task, send_context); 2457 send_context->task =
2458 GNUNET_SCHEDULER_add_now (&neighbor_send_task, send_context);
2310 return GNUNET_YES; 2459 return GNUNET_YES;
2311} 2460}
2312 2461
@@ -2333,24 +2482,27 @@ generate_hello_address (void *cls, size_t max, void *buf)
2333 return 0; 2482 return 0;
2334 2483
2335 /* Hello "address" will be concatenation of distant peer and direct peer identities */ 2484 /* Hello "address" will be concatenation of distant peer and direct peer identities */
2336 size = 2 * sizeof(struct GNUNET_PeerIdentity); 2485 size = 2 * sizeof (struct GNUNET_PeerIdentity);
2337 GNUNET_assert(max >= size); 2486 GNUNET_assert (max >= size);
2338 2487
2339 addr_buffer = GNUNET_malloc(size); 2488 addr_buffer = GNUNET_malloc (size);
2340 offset = 0; 2489 offset = 0;
2341 /* Copy the distant peer identity to buffer */ 2490 /* Copy the distant peer identity to buffer */
2342 memcpy(addr_buffer, &hello_context->distant_peer, sizeof(struct GNUNET_PeerIdentity)); 2491 memcpy (addr_buffer, &hello_context->distant_peer,
2343 offset += sizeof(struct GNUNET_PeerIdentity); 2492 sizeof (struct GNUNET_PeerIdentity));
2493 offset += sizeof (struct GNUNET_PeerIdentity);
2344 /* Copy the direct peer identity to buffer */ 2494 /* Copy the direct peer identity to buffer */
2345 memcpy(&addr_buffer[offset], hello_context->direct_peer, sizeof(struct GNUNET_PeerIdentity)); 2495 memcpy (&addr_buffer[offset], hello_context->direct_peer,
2346 ret = GNUNET_HELLO_add_address ("dv", 2496 sizeof (struct GNUNET_PeerIdentity));
2347 GNUNET_TIME_relative_to_absolute 2497 ret =
2348 (GNUNET_TIME_UNIT_HOURS), addr_buffer, size, 2498 GNUNET_HELLO_add_address ("dv",
2349 buf, max); 2499 GNUNET_TIME_relative_to_absolute
2500 (GNUNET_TIME_UNIT_HOURS), addr_buffer, size,
2501 buf, max);
2350 2502
2351 hello_context->addresses_to_add--; 2503 hello_context->addresses_to_add--;
2352 2504
2353 GNUNET_free(addr_buffer); 2505 GNUNET_free (addr_buffer);
2354 return ret; 2506 return ret;
2355} 2507}
2356 2508
@@ -2370,8 +2522,8 @@ generate_hello_address (void *cls, size_t max, void *buf)
2370 * not added) 2522 * not added)
2371 */ 2523 */
2372static struct DistantNeighbor * 2524static struct DistantNeighbor *
2373addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer, 2525addUpdateNeighbor (const struct GNUNET_PeerIdentity *peer,
2374 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey, 2526 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pkey,
2375 unsigned int referrer_peer_id, 2527 unsigned int referrer_peer_id,
2376 struct DirectNeighbor *referrer, unsigned int cost) 2528 struct DirectNeighbor *referrer, unsigned int cost)
2377{ 2529{
@@ -2388,6 +2540,7 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer,
2388 2540
2389#if DEBUG_DV_PEER_NUMBERS 2541#if DEBUG_DV_PEER_NUMBERS
2390 char *encAbout; 2542 char *encAbout;
2543
2391 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2544 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2392 "%s Received sender id (%u)!\n", "DV SERVICE", referrer_peer_id); 2545 "%s Received sender id (%u)!\n", "DV SERVICE", referrer_peer_id);
2393#endif 2546#endif
@@ -2395,7 +2548,7 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer,
2395 now = GNUNET_TIME_absolute_get (); 2548 now = GNUNET_TIME_absolute_get ();
2396 neighbor = GNUNET_CONTAINER_multihashmap_get (extended_neighbors, 2549 neighbor = GNUNET_CONTAINER_multihashmap_get (extended_neighbors,
2397 &peer->hashPubKey); 2550 &peer->hashPubKey);
2398 neighbor_update = GNUNET_malloc(sizeof(struct NeighborUpdateInfo)); 2551 neighbor_update = GNUNET_malloc (sizeof (struct NeighborUpdateInfo));
2399 neighbor_update->neighbor = neighbor; 2552 neighbor_update->neighbor = neighbor;
2400 neighbor_update->cost = cost; 2553 neighbor_update->cost = cost;
2401 neighbor_update->now = now; 2554 neighbor_update->now = now;
@@ -2403,163 +2556,189 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer,
2403 neighbor_update->referrer_peer_id = referrer_peer_id; 2556 neighbor_update->referrer_peer_id = referrer_peer_id;
2404 2557
2405 if (neighbor != NULL) 2558 if (neighbor != NULL)
2406 { 2559 {
2407#if USE_PEER_ID 2560#if USE_PEER_ID
2408 memcpy(&our_id, &neighbor->identity, sizeof(unsigned int)); 2561 memcpy (&our_id, &neighbor->identity, sizeof (unsigned int));
2409#else 2562#else
2410 our_id = neighbor->our_id; 2563 our_id = neighbor->our_id;
2411#endif 2564#endif
2412 } 2565 }
2413 else 2566 else
2414 { 2567 {
2415#if USE_PEER_ID 2568#if USE_PEER_ID
2416 memcpy(&our_id, peer, sizeof(unsigned int)); 2569 memcpy (&our_id, peer, sizeof (unsigned int));
2417#else 2570#else
2418 our_id = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG, RAND_MAX - 1) + 1; 2571 our_id =
2572 GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_STRONG,
2573 RAND_MAX - 1) + 1;
2419#endif 2574#endif
2420 } 2575 }
2421 2576
2422 /* Either we do not know this peer, or we already do but via a different immediate peer */ 2577 /* Either we do not know this peer, or we already do but via a different immediate peer */
2423 if ((neighbor == NULL) || 2578 if ((neighbor == NULL) ||
2424 (GNUNET_CONTAINER_multihashmap_get_multiple(extended_neighbors, 2579 (GNUNET_CONTAINER_multihashmap_get_multiple (extended_neighbors,
2425 &peer->hashPubKey, 2580 &peer->hashPubKey,
2426 &update_matching_neighbors, 2581 &update_matching_neighbors,
2427 neighbor_update) != GNUNET_SYSERR)) 2582 neighbor_update) !=
2428 { 2583 GNUNET_SYSERR))
2584 {
2429#if AT_MOST_ONE 2585#if AT_MOST_ONE
2430 if ((neighbor != NULL) && (cost < neighbor->cost)) /* New cost is less than old, remove old */ 2586 if ((neighbor != NULL) && (cost < neighbor->cost)) /* New cost is less than old, remove old */
2431 { 2587 {
2432 distant_neighbor_free(neighbor); 2588 distant_neighbor_free (neighbor);
2433 } 2589 }
2434 else if (neighbor != NULL) /* Only allow one DV connection to each peer */ 2590 else if (neighbor != NULL) /* Only allow one DV connection to each peer */
2435 { 2591 {
2436 return NULL; 2592 return NULL;
2437 } 2593 }
2438#endif 2594#endif
2439 /* new neighbor! */ 2595 /* new neighbor! */
2440 if (cost > fisheye_depth) 2596 if (cost > fisheye_depth)
2441 { 2597 {
2442 /* too costly */ 2598 /* too costly */
2443 GNUNET_free(neighbor_update); 2599 GNUNET_free (neighbor_update);
2444 return NULL; 2600 return NULL;
2445 } 2601 }
2446 2602
2447#if DEBUG_DV_PEER_NUMBERS 2603#if DEBUG_DV_PEER_NUMBERS
2448 encAbout = GNUNET_strdup(GNUNET_i2s(peer)); 2604 encAbout = GNUNET_strdup (GNUNET_i2s (peer));
2449 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2605 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2450 "%s: %s Chose NEW id (%u) for peer %s!\n", GNUNET_i2s(&my_identity), "DV SERVICE", our_id, encAbout); 2606 "%s: %s Chose NEW id (%u) for peer %s!\n",
2451 GNUNET_free(encAbout); 2607 GNUNET_i2s (&my_identity), "DV SERVICE", our_id, encAbout);
2608 GNUNET_free (encAbout);
2452#endif 2609#endif
2453 2610
2454 if (max_table_size <= 2611 if (max_table_size <=
2455 GNUNET_CONTAINER_multihashmap_size (extended_neighbors)) 2612 GNUNET_CONTAINER_multihashmap_size (extended_neighbors))
2456 { 2613 {
2457 /* remove most expensive entry */ 2614 /* remove most expensive entry */
2458 max = GNUNET_CONTAINER_heap_peek (neighbor_max_heap); 2615 max = GNUNET_CONTAINER_heap_peek (neighbor_max_heap);
2459 GNUNET_assert(max != NULL); 2616 GNUNET_assert (max != NULL);
2460 if (cost > max->cost) 2617 if (cost > max->cost)
2461 {
2462 /* new entry most expensive, don't create */
2463 GNUNET_free(neighbor_update);
2464 return NULL;
2465 }
2466 if (max->cost > 1)
2467 {
2468 /* only free if this is not a direct connection;
2469 we could theoretically have more direct
2470 connections than DV entries allowed total! */
2471 distant_neighbor_free (max);
2472 }
2473 }
2474
2475 neighbor = GNUNET_malloc (sizeof (struct DistantNeighbor));
2476 GNUNET_CONTAINER_DLL_insert (referrer->referee_head,
2477 referrer->referee_tail, neighbor);
2478 neighbor->max_loc = GNUNET_CONTAINER_heap_insert (neighbor_max_heap,
2479 neighbor, cost);
2480 neighbor->min_loc = GNUNET_CONTAINER_heap_insert (neighbor_min_heap,
2481 neighbor, cost);
2482 neighbor->referrer = referrer;
2483 memcpy (&neighbor->identity, peer, sizeof (struct GNUNET_PeerIdentity));
2484 if (pkey != NULL) /* pkey will be null on direct neighbor addition */
2485 { 2618 {
2486 neighbor->pkey = GNUNET_malloc(sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 2619 /* new entry most expensive, don't create */
2487 memcpy (neighbor->pkey, pkey, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 2620 GNUNET_free (neighbor_update);
2621 return NULL;
2488 } 2622 }
2489 else 2623 if (max->cost > 1)
2490 neighbor->pkey = pkey; 2624 {
2491 2625 /* only free if this is not a direct connection;
2492 neighbor->last_activity = now; 2626 * we could theoretically have more direct
2493 neighbor->cost = cost; 2627 * connections than DV entries allowed total! */
2494 neighbor->referrer_id = referrer_peer_id; 2628 distant_neighbor_free (max);
2495 neighbor->our_id = our_id; 2629 }
2496 neighbor->hidden = 2630 }
2497 (cost == DIRECT_NEIGHBOR_COST) ? (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 4) == 2631
2498 0) : GNUNET_NO; 2632 neighbor = GNUNET_malloc (sizeof (struct DistantNeighbor));
2499 2633 GNUNET_CONTAINER_DLL_insert (referrer->referee_head,
2500 GNUNET_CONTAINER_multihashmap_put (extended_neighbors, &peer->hashPubKey, 2634 referrer->referee_tail, neighbor);
2501 neighbor, 2635 neighbor->max_loc = GNUNET_CONTAINER_heap_insert (neighbor_max_heap,
2502 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); 2636 neighbor, cost);
2503 if (referrer_peer_id != 0) 2637 neighbor->min_loc = GNUNET_CONTAINER_heap_insert (neighbor_min_heap,
2638 neighbor, cost);
2639 neighbor->referrer = referrer;
2640 memcpy (&neighbor->identity, peer, sizeof (struct GNUNET_PeerIdentity));
2641 if (pkey != NULL) /* pkey will be null on direct neighbor addition */
2642 {
2643 neighbor->pkey =
2644 GNUNET_malloc (sizeof
2645 (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
2646 memcpy (neighbor->pkey, pkey,
2647 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
2648 }
2649 else
2650 neighbor->pkey = pkey;
2651
2652 neighbor->last_activity = now;
2653 neighbor->cost = cost;
2654 neighbor->referrer_id = referrer_peer_id;
2655 neighbor->our_id = our_id;
2656 neighbor->hidden =
2657 (cost ==
2658 DIRECT_NEIGHBOR_COST)
2659 ? (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 4) ==
2660 0) : GNUNET_NO;
2661
2662 GNUNET_CONTAINER_multihashmap_put (extended_neighbors, &peer->hashPubKey,
2663 neighbor,
2664 GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
2665 if (referrer_peer_id != 0)
2666 {
2667 for (i = 0; i < MAX_OUTSTANDING_MESSAGES; i++)
2668 {
2669 if (referrer->pending_messages[i].sender_id == referrer_peer_id) /* We have a queued message from just learned about peer! */
2504 { 2670 {
2505 for (i = 0; i< MAX_OUTSTANDING_MESSAGES; i++)
2506 {
2507 if (referrer->pending_messages[i].sender_id == referrer_peer_id) /* We have a queued message from just learned about peer! */
2508 {
2509#if DEBUG_DV_MESSAGES 2671#if DEBUG_DV_MESSAGES
2510 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: learned about peer %llu from which we have a previous unknown message, processing!\n", my_short_id, referrer_peer_id); 2672 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2511#endif 2673 "%s: learned about peer %llu from which we have a previous unknown message, processing!\n",
2512 struct GNUNET_TRANSPORT_ATS_Information atsi[3]; 2674 my_short_id, referrer_peer_id);
2513 atsi[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE); 2675#endif
2514 atsi[0].value = htonl (referrer->pending_messages[i].distance); 2676 struct GNUNET_TRANSPORT_ATS_Information atsi[3];
2515 atsi[1].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY); 2677
2516 atsi[1].value = htonl ((uint32_t)referrer->pending_messages[i].latency.rel_value); 2678 atsi[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
2517 atsi[2].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); 2679 atsi[0].value = htonl (referrer->pending_messages[i].distance);
2518 atsi[2].value = htonl (0); 2680 atsi[1].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DELAY);
2519 handle_dv_data_message(NULL, 2681 atsi[1].value =
2520 &referrer->pending_messages[i].sender, 2682 htonl ((uint32_t) referrer->pending_messages[i].
2521 referrer->pending_messages[i].message, 2683 latency.rel_value);
2522 (const struct GNUNET_TRANSPORT_ATS_Information *)&atsi); 2684 atsi[2].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
2523 GNUNET_free(referrer->pending_messages[i].message); 2685 atsi[2].value = htonl (0);
2524 referrer->pending_messages[i].sender_id = 0; 2686 handle_dv_data_message (NULL,
2525 } 2687 &referrer->pending_messages[i].sender,
2526 } 2688 referrer->pending_messages[i].message,
2689 (const struct GNUNET_TRANSPORT_ATS_Information
2690 *) &atsi);
2691 GNUNET_free (referrer->pending_messages[i].message);
2692 referrer->pending_messages[i].sender_id = 0;
2527 } 2693 }
2528 if ((cost != DIRECT_NEIGHBOR_COST) && (neighbor->pkey != NULL)) 2694 }
2529 { 2695 }
2530 /* Added neighbor, now send HELLO to transport */ 2696 if ((cost != DIRECT_NEIGHBOR_COST) && (neighbor->pkey != NULL))
2531 hello_context = GNUNET_malloc(sizeof(struct HelloContext)); 2697 {
2532 hello_context->direct_peer = &referrer->identity; 2698 /* Added neighbor, now send HELLO to transport */
2533 memcpy(&hello_context->distant_peer, peer, sizeof(struct GNUNET_PeerIdentity)); 2699 hello_context = GNUNET_malloc (sizeof (struct HelloContext));
2534 hello_context->addresses_to_add = 1; 2700 hello_context->direct_peer = &referrer->identity;
2535 hello_msg = GNUNET_HELLO_create(pkey, &generate_hello_address, hello_context); 2701 memcpy (&hello_context->distant_peer, peer,
2536 GNUNET_assert(memcmp(hello_context->direct_peer, &hello_context->distant_peer, sizeof(struct GNUNET_PeerIdentity)) != 0); 2702 sizeof (struct GNUNET_PeerIdentity));
2537 addr1 = GNUNET_strdup(GNUNET_i2s(hello_context->direct_peer)); 2703 hello_context->addresses_to_add = 1;
2538 addr2 = GNUNET_strdup(GNUNET_i2s(&hello_context->distant_peer)); 2704 hello_msg =
2705 GNUNET_HELLO_create (pkey, &generate_hello_address, hello_context);
2706 GNUNET_assert (memcmp
2707 (hello_context->direct_peer, &hello_context->distant_peer,
2708 sizeof (struct GNUNET_PeerIdentity)) != 0);
2709 addr1 = GNUNET_strdup (GNUNET_i2s (hello_context->direct_peer));
2710 addr2 = GNUNET_strdup (GNUNET_i2s (&hello_context->distant_peer));
2539#if DEBUG_DV 2711#if DEBUG_DV
2540 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: GIVING HELLO size %d for %s via %s to TRANSPORT\n", my_short_id, GNUNET_HELLO_size(hello_msg), addr2, addr1); 2712 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2541#endif 2713 "%s: GIVING HELLO size %d for %s via %s to TRANSPORT\n",
2542 GNUNET_free(addr1); 2714 my_short_id, GNUNET_HELLO_size (hello_msg), addr2, addr1);
2543 GNUNET_free(addr2); 2715#endif
2544 send_to_plugin(hello_context->direct_peer, GNUNET_HELLO_get_header(hello_msg), GNUNET_HELLO_size(hello_msg), &hello_context->distant_peer, cost); 2716 GNUNET_free (addr1);
2545 GNUNET_free(hello_context); 2717 GNUNET_free (addr2);
2546 GNUNET_free(hello_msg); 2718 send_to_plugin (hello_context->direct_peer,
2547 } 2719 GNUNET_HELLO_get_header (hello_msg),
2548 2720 GNUNET_HELLO_size (hello_msg),
2721 &hello_context->distant_peer, cost);
2722 GNUNET_free (hello_context);
2723 GNUNET_free (hello_msg);
2549 } 2724 }
2725
2726 }
2550 else 2727 else
2551 { 2728 {
2552#if DEBUG_DV_GOSSIP 2729#if DEBUG_DV_GOSSIP
2553 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2730 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2554 "%s: Already know peer %s distance %d, referrer id %d!\n", "dv", GNUNET_i2s(peer), cost, referrer_peer_id); 2731 "%s: Already know peer %s distance %d, referrer id %d!\n", "dv",
2732 GNUNET_i2s (peer), cost, referrer_peer_id);
2555#endif 2733#endif
2556 } 2734 }
2557#if DEBUG_DV 2735#if DEBUG_DV
2558 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2736 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2559 "%s: Size of extended_neighbors is %d\n", "dv", GNUNET_CONTAINER_multihashmap_size(extended_neighbors)); 2737 "%s: Size of extended_neighbors is %d\n", "dv",
2738 GNUNET_CONTAINER_multihashmap_size (extended_neighbors));
2560#endif 2739#endif
2561 2740
2562 GNUNET_free(neighbor_update); 2741 GNUNET_free (neighbor_update);
2563 return neighbor; 2742 return neighbor;
2564} 2743}
2565 2744
@@ -2576,19 +2755,22 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer,
2576 * @param message the message 2755 * @param message the message
2577 * @param atsi performance data 2756 * @param atsi performance data
2578 */ 2757 */
2579static int handle_dv_disconnect_message (void *cls, 2758static int
2580 const struct GNUNET_PeerIdentity *peer, 2759handle_dv_disconnect_message (void *cls,
2581 const struct GNUNET_MessageHeader *message, 2760 const struct GNUNET_PeerIdentity *peer,
2582 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 2761 const struct GNUNET_MessageHeader *message,
2762 const struct GNUNET_TRANSPORT_ATS_Information
2763 *atsi)
2583{ 2764{
2584 struct DirectNeighbor *referrer; 2765 struct DirectNeighbor *referrer;
2585 struct DistantNeighbor *distant; 2766 struct DistantNeighbor *distant;
2586 p2p_dv_MESSAGE_Disconnect *enc_message = (p2p_dv_MESSAGE_Disconnect *)message; 2767 p2p_dv_MESSAGE_Disconnect *enc_message =
2768 (p2p_dv_MESSAGE_Disconnect *) message;
2587 2769
2588 if (ntohs (message->size) < sizeof (p2p_dv_MESSAGE_Disconnect)) 2770 if (ntohs (message->size) < sizeof (p2p_dv_MESSAGE_Disconnect))
2589 { 2771 {
2590 return GNUNET_SYSERR; /* invalid message */ 2772 return GNUNET_SYSERR; /* invalid message */
2591 } 2773 }
2592 2774
2593 referrer = GNUNET_CONTAINER_multihashmap_get (direct_neighbors, 2775 referrer = GNUNET_CONTAINER_multihashmap_get (direct_neighbors,
2594 &peer->hashPubKey); 2776 &peer->hashPubKey);
@@ -2597,15 +2779,15 @@ static int handle_dv_disconnect_message (void *cls,
2597 2779
2598 distant = referrer->referee_head; 2780 distant = referrer->referee_head;
2599 while (distant != NULL) 2781 while (distant != NULL)
2782 {
2783 if (distant->referrer_id == ntohl (enc_message->peer_id))
2600 { 2784 {
2601 if (distant->referrer_id == ntohl(enc_message->peer_id)) 2785 distant_neighbor_free (distant);
2602 { 2786 distant = referrer->referee_head;
2603 distant_neighbor_free(distant);
2604 distant = referrer->referee_head;
2605 }
2606 else
2607 distant = distant->next;
2608 } 2787 }
2788 else
2789 distant = distant->next;
2790 }
2609 2791
2610 return GNUNET_OK; 2792 return GNUNET_OK;
2611} 2793}
@@ -2623,30 +2805,33 @@ static int handle_dv_disconnect_message (void *cls,
2623 * @param message the message 2805 * @param message the message
2624 * @param atsi performance data 2806 * @param atsi performance data
2625 */ 2807 */
2626static int 2808static int
2627handle_dv_gossip_message (void *cls, 2809handle_dv_gossip_message (void *cls,
2628 const struct GNUNET_PeerIdentity *peer, 2810 const struct GNUNET_PeerIdentity *peer,
2629 const struct GNUNET_MessageHeader *message, 2811 const struct GNUNET_MessageHeader *message,
2630 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 2812 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
2631{ 2813{
2632 struct DirectNeighbor *referrer; 2814 struct DirectNeighbor *referrer;
2633 p2p_dv_MESSAGE_NeighborInfo *enc_message = (p2p_dv_MESSAGE_NeighborInfo *)message; 2815 p2p_dv_MESSAGE_NeighborInfo *enc_message =
2816 (p2p_dv_MESSAGE_NeighborInfo *) message;
2634 2817
2635 if (ntohs (message->size) < sizeof (p2p_dv_MESSAGE_NeighborInfo)) 2818 if (ntohs (message->size) < sizeof (p2p_dv_MESSAGE_NeighborInfo))
2636 { 2819 {
2637 return GNUNET_SYSERR; /* invalid message */ 2820 return GNUNET_SYSERR; /* invalid message */
2638 } 2821 }
2639 2822
2640#if DEBUG_DV_GOSSIP_RECEIPT 2823#if DEBUG_DV_GOSSIP_RECEIPT
2641 char * encPeerAbout; 2824 char *encPeerAbout;
2642 char * encPeerFrom; 2825 char *encPeerFrom;
2643 2826
2644 encPeerAbout = GNUNET_strdup(GNUNET_i2s(&enc_message->neighbor)); 2827 encPeerAbout = GNUNET_strdup (GNUNET_i2s (&enc_message->neighbor));
2645 encPeerFrom = GNUNET_strdup(GNUNET_i2s(peer)); 2828 encPeerFrom = GNUNET_strdup (GNUNET_i2s (peer));
2646 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2829 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2647 "%s: Received %s message from peer %s about peer %s id %u distance %d!\n", GNUNET_i2s(&my_identity), "DV GOSSIP", encPeerFrom, encPeerAbout, ntohl(enc_message->neighbor_id), ntohl (enc_message->cost) + 1); 2830 "%s: Received %s message from peer %s about peer %s id %u distance %d!\n",
2648 GNUNET_free(encPeerAbout); 2831 GNUNET_i2s (&my_identity), "DV GOSSIP", encPeerFrom, encPeerAbout,
2649 GNUNET_free(encPeerFrom); 2832 ntohl (enc_message->neighbor_id), ntohl (enc_message->cost) + 1);
2833 GNUNET_free (encPeerAbout);
2834 GNUNET_free (encPeerFrom);
2650#endif 2835#endif
2651 2836
2652 referrer = GNUNET_CONTAINER_multihashmap_get (direct_neighbors, 2837 referrer = GNUNET_CONTAINER_multihashmap_get (direct_neighbors,
@@ -2673,29 +2858,29 @@ handle_dv_gossip_message (void *cls,
2673 * 2858 *
2674 * @return GNUNET_YES to continue iteration, GNUNET_NO otherwise 2859 * @return GNUNET_YES to continue iteration, GNUNET_NO otherwise
2675 */ 2860 */
2676static int 2861static int
2677add_all_extended_peers (void *cls, 2862add_all_extended_peers (void *cls, const GNUNET_HashCode * key, void *value)
2678 const GNUNET_HashCode * key,
2679 void *value)
2680{ 2863{
2681 struct NeighborSendContext *send_context = (struct NeighborSendContext *)cls; 2864 struct NeighborSendContext *send_context = (struct NeighborSendContext *) cls;
2682 struct DistantNeighbor *distant = (struct DistantNeighbor *)value; 2865 struct DistantNeighbor *distant = (struct DistantNeighbor *) value;
2683 struct FastGossipNeighborList *gossip_entry; 2866 struct FastGossipNeighborList *gossip_entry;
2684 2867
2685 if (memcmp(&send_context->toNeighbor->identity, &distant->identity, sizeof(struct GNUNET_PeerIdentity)) == 0) 2868 if (memcmp
2686 return GNUNET_YES; /* Don't gossip to a peer about itself! */ 2869 (&send_context->toNeighbor->identity, &distant->identity,
2870 sizeof (struct GNUNET_PeerIdentity)) == 0)
2871 return GNUNET_YES; /* Don't gossip to a peer about itself! */
2687 2872
2688#if SUPPORT_HIDING 2873#if SUPPORT_HIDING
2689 if (distant->hidden == GNUNET_YES) 2874 if (distant->hidden == GNUNET_YES)
2690 return GNUNET_YES; /* This peer should not be gossipped about (hidden) */ 2875 return GNUNET_YES; /* This peer should not be gossipped about (hidden) */
2691#endif 2876#endif
2692 gossip_entry = GNUNET_malloc(sizeof(struct FastGossipNeighborList)); 2877 gossip_entry = GNUNET_malloc (sizeof (struct FastGossipNeighborList));
2693 gossip_entry->about = distant; 2878 gossip_entry->about = distant;
2694 2879
2695 GNUNET_CONTAINER_DLL_insert_after(send_context->fast_gossip_list_head, 2880 GNUNET_CONTAINER_DLL_insert_after (send_context->fast_gossip_list_head,
2696 send_context->fast_gossip_list_tail, 2881 send_context->fast_gossip_list_tail,
2697 send_context->fast_gossip_list_tail, 2882 send_context->fast_gossip_list_tail,
2698 gossip_entry); 2883 gossip_entry);
2699 2884
2700 return GNUNET_YES; 2885 return GNUNET_YES;
2701} 2886}
@@ -2711,19 +2896,21 @@ add_all_extended_peers (void *cls,
2711 * iterate, 2896 * iterate,
2712 * GNUNET_NO if not. 2897 * GNUNET_NO if not.
2713 */ 2898 */
2714static int 2899static int
2715gossip_all_to_all_iterator (void *cls, 2900gossip_all_to_all_iterator (void *cls,
2716 const GNUNET_HashCode * key, 2901 const GNUNET_HashCode * key, void *abs_value)
2717 void *abs_value)
2718{ 2902{
2719 struct DirectNeighbor *direct = abs_value; 2903 struct DirectNeighbor *direct = abs_value;
2720 2904
2721 GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors, &add_all_extended_peers, direct->send_context); 2905 GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors,
2906 &add_all_extended_peers,
2907 direct->send_context);
2722 2908
2723 if (direct->send_context->task != GNUNET_SCHEDULER_NO_TASK) 2909 if (direct->send_context->task != GNUNET_SCHEDULER_NO_TASK)
2724 GNUNET_SCHEDULER_cancel(direct->send_context->task); 2910 GNUNET_SCHEDULER_cancel (direct->send_context->task);
2725 2911
2726 direct->send_context->task = GNUNET_SCHEDULER_add_now(&neighbor_send_task, direct->send_context); 2912 direct->send_context->task =
2913 GNUNET_SCHEDULER_add_now (&neighbor_send_task, direct->send_context);
2727 return GNUNET_YES; 2914 return GNUNET_YES;
2728} 2915}
2729 2916
@@ -2734,14 +2921,14 @@ gossip_all_to_all_iterator (void *cls,
2734 * @param tc unused 2921 * @param tc unused
2735 */ 2922 */
2736static void 2923static void
2737gossip_all_to_all (void *cls, 2924gossip_all_to_all (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
2738 const struct GNUNET_SCHEDULER_TaskContext *tc)
2739{ 2925{
2740 GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors, &gossip_all_to_all_iterator, NULL); 2926 GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors,
2927 &gossip_all_to_all_iterator, NULL);
2741 2928
2742 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5), 2929 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
2743 &gossip_all_to_all, 2930 (GNUNET_TIME_UNIT_SECONDS, 5),
2744 NULL); 2931 &gossip_all_to_all, NULL);
2745 2932
2746} 2933}
2747#endif 2934#endif
@@ -2756,50 +2943,55 @@ gossip_all_to_all (void *cls,
2756 * 2943 *
2757 * @return GNUNET_YES to continue iteration, GNUNET_NO otherwise 2944 * @return GNUNET_YES to continue iteration, GNUNET_NO otherwise
2758 */ 2945 */
2759static int 2946static int
2760add_all_direct_neighbors (void *cls, 2947add_all_direct_neighbors (void *cls, const GNUNET_HashCode * key, void *value)
2761 const GNUNET_HashCode * key,
2762 void *value)
2763{ 2948{
2764 struct DirectNeighbor *direct = (struct DirectNeighbor *)value; 2949 struct DirectNeighbor *direct = (struct DirectNeighbor *) value;
2765 struct DirectNeighbor *to = (struct DirectNeighbor *)cls; 2950 struct DirectNeighbor *to = (struct DirectNeighbor *) cls;
2766 struct DistantNeighbor *distant; 2951 struct DistantNeighbor *distant;
2767 struct NeighborSendContext *send_context = direct->send_context; 2952 struct NeighborSendContext *send_context = direct->send_context;
2768 struct FastGossipNeighborList *gossip_entry; 2953 struct FastGossipNeighborList *gossip_entry;
2769 char *direct_id; 2954 char *direct_id;
2770 2955
2771 2956
2772 distant = GNUNET_CONTAINER_multihashmap_get(extended_neighbors, &to->identity.hashPubKey); 2957 distant =
2958 GNUNET_CONTAINER_multihashmap_get (extended_neighbors,
2959 &to->identity.hashPubKey);
2773 if (distant == NULL) 2960 if (distant == NULL)
2774 { 2961 {
2775 return GNUNET_YES; 2962 return GNUNET_YES;
2776 } 2963 }
2777 2964
2778 if (memcmp(&direct->identity, &to->identity, sizeof(struct GNUNET_PeerIdentity)) == 0) 2965 if (memcmp
2779 { 2966 (&direct->identity, &to->identity,
2780 return GNUNET_YES; /* Don't gossip to a peer about itself! */ 2967 sizeof (struct GNUNET_PeerIdentity)) == 0)
2781 } 2968 {
2969 return GNUNET_YES; /* Don't gossip to a peer about itself! */
2970 }
2782 2971
2783#if SUPPORT_HIDING 2972#if SUPPORT_HIDING
2784 if (distant->hidden == GNUNET_YES) 2973 if (distant->hidden == GNUNET_YES)
2785 return GNUNET_YES; /* This peer should not be gossipped about (hidden) */ 2974 return GNUNET_YES; /* This peer should not be gossipped about (hidden) */
2786#endif 2975#endif
2787 direct_id = GNUNET_strdup(GNUNET_i2s(&direct->identity)); 2976 direct_id = GNUNET_strdup (GNUNET_i2s (&direct->identity));
2788#if DEBUG_DV_GOSSIP 2977#if DEBUG_DV_GOSSIP
2789 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "%s: adding peer %s to fast send list for %s\n", my_short_id, GNUNET_i2s(&distant->identity), direct_id); 2978 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2979 "%s: adding peer %s to fast send list for %s\n", my_short_id,
2980 GNUNET_i2s (&distant->identity), direct_id);
2790#endif 2981#endif
2791 GNUNET_free(direct_id); 2982 GNUNET_free (direct_id);
2792 gossip_entry = GNUNET_malloc(sizeof(struct FastGossipNeighborList)); 2983 gossip_entry = GNUNET_malloc (sizeof (struct FastGossipNeighborList));
2793 gossip_entry->about = distant; 2984 gossip_entry->about = distant;
2794 2985
2795 GNUNET_CONTAINER_DLL_insert_after(send_context->fast_gossip_list_head, 2986 GNUNET_CONTAINER_DLL_insert_after (send_context->fast_gossip_list_head,
2796 send_context->fast_gossip_list_tail, 2987 send_context->fast_gossip_list_tail,
2797 send_context->fast_gossip_list_tail, 2988 send_context->fast_gossip_list_tail,
2798 gossip_entry); 2989 gossip_entry);
2799 if (send_context->task != GNUNET_SCHEDULER_NO_TASK) 2990 if (send_context->task != GNUNET_SCHEDULER_NO_TASK)
2800 GNUNET_SCHEDULER_cancel(send_context->task); 2991 GNUNET_SCHEDULER_cancel (send_context->task);
2801 2992
2802 send_context->task = GNUNET_SCHEDULER_add_now(&neighbor_send_task, send_context); 2993 send_context->task =
2994 GNUNET_SCHEDULER_add_now (&neighbor_send_task, send_context);
2803 //tc.reason = GNUNET_SCHEDULER_REASON_TIMEOUT; 2995 //tc.reason = GNUNET_SCHEDULER_REASON_TIMEOUT;
2804 //neighbor_send_task(send_context, &tc); 2996 //neighbor_send_task(send_context, &tc);
2805 return GNUNET_YES; 2997 return GNUNET_YES;
@@ -2817,73 +3009,97 @@ add_all_direct_neighbors (void *cls,
2817static void 3009static void
2818process_peerinfo (void *cls, 3010process_peerinfo (void *cls,
2819 const struct GNUNET_PeerIdentity *peer, 3011 const struct GNUNET_PeerIdentity *peer,
2820 const struct GNUNET_HELLO_Message *hello, 3012 const struct GNUNET_HELLO_Message *hello, const char *err_msg)
2821 const char *err_msg)
2822{ 3013{
2823 struct PeerIteratorContext *peerinfo_iterator = cls; 3014 struct PeerIteratorContext *peerinfo_iterator = cls;
2824 struct DirectNeighbor *neighbor = peerinfo_iterator->neighbor; 3015 struct DirectNeighbor *neighbor = peerinfo_iterator->neighbor;
2825 struct DistantNeighbor *distant = peerinfo_iterator->distant; 3016 struct DistantNeighbor *distant = peerinfo_iterator->distant;
3017
2826#if DEBUG_DV_PEER_NUMBERS 3018#if DEBUG_DV_PEER_NUMBERS
2827 char *neighbor_pid; 3019 char *neighbor_pid;
2828#endif 3020#endif
2829 int sent; 3021 int sent;
3022
2830 if (err_msg != NULL) 3023 if (err_msg != NULL)
2831 { 3024 {
2832 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3025 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2833 _("Error in communication with PEERINFO service\n")); 3026 _("Error in communication with PEERINFO service\n"));
2834 /* return; */ 3027 /* return; */
2835 } 3028 }
2836 if (peer == NULL) 3029 if (peer == NULL)
3030 {
3031 if (distant->pkey == NULL)
2837 { 3032 {
2838 if (distant->pkey == NULL)
2839 {
2840#if DEBUG_DV 3033#if DEBUG_DV
2841 GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Failed to get peerinfo information for this peer, retrying!\n"); 3034 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
2842#endif 3035 "Failed to get peerinfo information for this peer, retrying!\n");
2843 peerinfo_iterator->ic = GNUNET_PEERINFO_iterate(peerinfo_handle, 3036#endif
2844 &peerinfo_iterator->neighbor->identity, 3037 peerinfo_iterator->ic = GNUNET_PEERINFO_iterate (peerinfo_handle,
2845 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3), 3038 &peerinfo_iterator->neighbor->
2846 &process_peerinfo, 3039 identity,
2847 peerinfo_iterator); 3040 GNUNET_TIME_relative_multiply
2848 } 3041 (GNUNET_TIME_UNIT_SECONDS,
2849 else 3042 3), &process_peerinfo,
2850 { 3043 peerinfo_iterator);
2851 GNUNET_free(peerinfo_iterator);
2852 }
2853 return;
2854 } 3044 }
3045 else
3046 {
3047 GNUNET_free (peerinfo_iterator);
3048 }
3049 return;
3050 }
2855 3051
2856 if (memcmp(&neighbor->identity, peer, sizeof(struct GNUNET_PeerIdentity) != 0)) 3052 if (memcmp
3053 (&neighbor->identity, peer, sizeof (struct GNUNET_PeerIdentity) != 0))
2857 return; 3054 return;
2858 3055
2859 if ((hello != NULL) && (GNUNET_HELLO_get_key (hello, &neighbor->pkey) == GNUNET_OK)) 3056 if ((hello != NULL) &&
3057 (GNUNET_HELLO_get_key (hello, &neighbor->pkey) == GNUNET_OK))
3058 {
3059 if (distant->pkey == NULL)
2860 { 3060 {
2861 if (distant->pkey == NULL) 3061 distant->pkey =
2862 { 3062 GNUNET_malloc (sizeof
2863 distant->pkey = GNUNET_malloc(sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 3063 (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
2864 memcpy(distant->pkey, &neighbor->pkey, sizeof(struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded)); 3064 memcpy (distant->pkey, &neighbor->pkey,
2865 } 3065 sizeof (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded));
3066 }
2866 3067
2867 sent = GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors, &add_all_extended_peers, neighbor->send_context); 3068 sent =
2868 if (stats != NULL) 3069 GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors,
2869 { 3070 &add_all_extended_peers,
2870 GNUNET_STATISTICS_update (stats, "# distant peers gossiped to direct neighbors", sent, GNUNET_NO); 3071 neighbor->send_context);
2871 } 3072 if (stats != NULL)
3073 {
3074 GNUNET_STATISTICS_update (stats,
3075 "# distant peers gossiped to direct neighbors",
3076 sent, GNUNET_NO);
3077 }
2872#if DEBUG_DV_PEER_NUMBERS 3078#if DEBUG_DV_PEER_NUMBERS
2873 neighbor_pid = GNUNET_strdup(GNUNET_i2s(&neighbor->identity)); 3079 neighbor_pid = GNUNET_strdup (GNUNET_i2s (&neighbor->identity));
2874 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Gossipped %d extended peers to %s\n", GNUNET_i2s(&my_identity), sent, neighbor_pid); 3080 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2875#endif 3081 "%s: Gossipped %d extended peers to %s\n",
2876 sent = GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors, &add_all_direct_neighbors, neighbor); 3082 GNUNET_i2s (&my_identity), sent, neighbor_pid);
2877 if (stats != NULL) 3083#endif
2878 { 3084 sent =
2879 GNUNET_STATISTICS_update (stats, "# direct peers gossiped to direct neighbors", sent, GNUNET_NO); 3085 GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors,
2880 } 3086 &add_all_direct_neighbors,
3087 neighbor);
3088 if (stats != NULL)
3089 {
3090 GNUNET_STATISTICS_update (stats,
3091 "# direct peers gossiped to direct neighbors",
3092 sent, GNUNET_NO);
3093 }
2881#if DEBUG_DV_PEER_NUMBERS 3094#if DEBUG_DV_PEER_NUMBERS
2882 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "%s: Gossipped about %s to %d direct peers\n", GNUNET_i2s(&my_identity), neighbor_pid, sent); 3095 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2883 GNUNET_free(neighbor_pid); 3096 "%s: Gossipped about %s to %d direct peers\n",
3097 GNUNET_i2s (&my_identity), neighbor_pid, sent);
3098 GNUNET_free (neighbor_pid);
2884#endif 3099#endif
2885 neighbor->send_context->task = GNUNET_SCHEDULER_add_now(&neighbor_send_task, neighbor->send_context); 3100 neighbor->send_context->task =
2886 } 3101 GNUNET_SCHEDULER_add_now (&neighbor_send_task, neighbor->send_context);
3102 }
2887} 3103}
2888 3104
2889 3105
@@ -2894,10 +3110,10 @@ process_peerinfo (void *cls,
2894 * @param peer peer identity this notification is about 3110 * @param peer peer identity this notification is about
2895 * @param atsi performance data 3111 * @param atsi performance data
2896 */ 3112 */
2897static void 3113static void
2898handle_core_connect (void *cls, 3114handle_core_connect (void *cls,
2899 const struct GNUNET_PeerIdentity * peer, 3115 const struct GNUNET_PeerIdentity *peer,
2900 const struct GNUNET_TRANSPORT_ATS_Information *atsi) 3116 const struct GNUNET_TRANSPORT_ATS_Information *atsi)
2901{ 3117{
2902 struct DirectNeighbor *neighbor; 3118 struct DirectNeighbor *neighbor;
2903 struct DistantNeighbor *about; 3119 struct DistantNeighbor *about;
@@ -2907,54 +3123,69 @@ handle_core_connect (void *cls,
2907 uint32_t distance; 3123 uint32_t distance;
2908 3124
2909 /* Check for connect to self message */ 3125 /* Check for connect to self message */
2910 if (0 == memcmp(&my_identity, peer, sizeof(struct GNUNET_PeerIdentity))) 3126 if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
2911 return; 3127 return;
2912 3128
2913 distance = get_atsi_distance (atsi); 3129 distance = get_atsi_distance (atsi);
2914 if ((distance == DIRECT_NEIGHBOR_COST) && 3130 if ((distance == DIRECT_NEIGHBOR_COST) &&
2915 (GNUNET_CONTAINER_multihashmap_get(direct_neighbors, &peer->hashPubKey) == NULL)) 3131 (GNUNET_CONTAINER_multihashmap_get (direct_neighbors, &peer->hashPubKey)
3132 == NULL))
2916 { 3133 {
2917 peerinfo_iterator = GNUNET_malloc(sizeof(struct PeerIteratorContext)); 3134 peerinfo_iterator = GNUNET_malloc (sizeof (struct PeerIteratorContext));
2918 neighbor = GNUNET_malloc (sizeof (struct DirectNeighbor)); 3135 neighbor = GNUNET_malloc (sizeof (struct DirectNeighbor));
2919 neighbor->send_context = GNUNET_malloc(sizeof(struct NeighborSendContext)); 3136 neighbor->send_context =
3137 GNUNET_malloc (sizeof (struct NeighborSendContext));
2920 neighbor->send_context->toNeighbor = neighbor; 3138 neighbor->send_context->toNeighbor = neighbor;
2921 memcpy (&neighbor->identity, peer, sizeof (struct GNUNET_PeerIdentity)); 3139 memcpy (&neighbor->identity, peer, sizeof (struct GNUNET_PeerIdentity));
2922 3140
2923 GNUNET_assert(GNUNET_SYSERR != GNUNET_CONTAINER_multihashmap_put (direct_neighbors, 3141 GNUNET_assert (GNUNET_SYSERR !=
2924 &peer->hashPubKey, 3142 GNUNET_CONTAINER_multihashmap_put (direct_neighbors,
2925 neighbor, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 3143 &peer->hashPubKey,
3144 neighbor,
3145 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
2926 about = addUpdateNeighbor (peer, NULL, 0, neighbor, DIRECT_NEIGHBOR_COST); 3146 about = addUpdateNeighbor (peer, NULL, 0, neighbor, DIRECT_NEIGHBOR_COST);
2927 peerinfo_iterator->distant = about; 3147 peerinfo_iterator->distant = about;
2928 peerinfo_iterator->neighbor = neighbor; 3148 peerinfo_iterator->neighbor = neighbor;
2929 peerinfo_iterator->ic = GNUNET_PEERINFO_iterate (peerinfo_handle, 3149 peerinfo_iterator->ic = GNUNET_PEERINFO_iterate (peerinfo_handle,
2930 peer, 3150 peer,
2931 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 3), 3151 GNUNET_TIME_relative_multiply
2932 &process_peerinfo, 3152 (GNUNET_TIME_UNIT_SECONDS,
3153 3), &process_peerinfo,
2933 peerinfo_iterator); 3154 peerinfo_iterator);
2934 3155
2935 if ((about != NULL) && (about->pkey == NULL)) 3156 if ((about != NULL) && (about->pkey == NULL))
2936 { 3157 {
2937#if DEBUG_DV 3158#if DEBUG_DV
2938 GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Newly added peer %s has NULL pkey!\n", GNUNET_i2s(peer)); 3159 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
3160 "Newly added peer %s has NULL pkey!\n", GNUNET_i2s (peer));
2939#endif 3161#endif
2940 } 3162 }
2941 else if (about != NULL) 3163 else if (about != NULL)
2942 { 3164 {
2943 GNUNET_free(peerinfo_iterator); 3165 GNUNET_free (peerinfo_iterator);
2944 } 3166 }
2945 } 3167 }
2946 else 3168 else
2947 { 3169 {
2948 about = GNUNET_CONTAINER_multihashmap_get(extended_neighbors, &peer->hashPubKey); 3170 about =
2949 if ((GNUNET_CONTAINER_multihashmap_get(direct_neighbors, &peer->hashPubKey) == NULL) && (about != NULL)) 3171 GNUNET_CONTAINER_multihashmap_get (extended_neighbors,
2950 { 3172 &peer->hashPubKey);
2951 sent = GNUNET_CONTAINER_multihashmap_iterate(direct_neighbors, &add_distant_all_direct_neighbors, about); 3173 if ((GNUNET_CONTAINER_multihashmap_get (direct_neighbors, &peer->hashPubKey)
2952 if (stats != NULL) 3174 == NULL) && (about != NULL))
2953 GNUNET_STATISTICS_update (stats, "# direct peers gossiped to new direct neighbors", sent, GNUNET_NO); 3175 {
2954 } 3176 sent =
3177 GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors,
3178 &add_distant_all_direct_neighbors,
3179 about);
3180 if (stats != NULL)
3181 GNUNET_STATISTICS_update (stats,
3182 "# direct peers gossiped to new direct neighbors",
3183 sent, GNUNET_NO);
3184 }
2955#if DEBUG_DV 3185#if DEBUG_DV
2956 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2957 "%s: Distance (%d) greater than %d or already know about peer (%s), not re-adding!\n", "dv", distance, DIRECT_NEIGHBOR_COST, GNUNET_i2s(peer)); 3187 "%s: Distance (%d) greater than %d or already know about peer (%s), not re-adding!\n",
3188 "dv", distance, DIRECT_NEIGHBOR_COST, GNUNET_i2s (peer));
2958#endif 3189#endif
2959 return; 3190 return;
2960 } 3191 }
@@ -2966,8 +3197,8 @@ handle_core_connect (void *cls,
2966 * @param cls closure 3197 * @param cls closure
2967 * @param peer peer identity this notification is about 3198 * @param peer peer identity this notification is about
2968 */ 3199 */
2969void handle_core_disconnect (void *cls, 3200void
2970 const struct GNUNET_PeerIdentity * peer) 3201handle_core_disconnect (void *cls, const struct GNUNET_PeerIdentity *peer)
2971{ 3202{
2972 struct DirectNeighbor *neighbor; 3203 struct DirectNeighbor *neighbor;
2973 struct DistantNeighbor *referee; 3204 struct DistantNeighbor *referee;
@@ -2981,28 +3212,31 @@ void handle_core_disconnect (void *cls,
2981#endif 3212#endif
2982 3213
2983 /* Check for disconnect from self message */ 3214 /* Check for disconnect from self message */
2984 if (0 == memcmp(&my_identity, peer, sizeof(struct GNUNET_PeerIdentity))) 3215 if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity)))
2985 return; 3216 return;
2986 3217
2987 neighbor = 3218 neighbor =
2988 GNUNET_CONTAINER_multihashmap_get (direct_neighbors, &peer->hashPubKey); 3219 GNUNET_CONTAINER_multihashmap_get (direct_neighbors, &peer->hashPubKey);
2989 3220
2990 if (neighbor == NULL) 3221 if (neighbor == NULL)
2991 { 3222 {
2992 return; 3223 return;
2993 } 3224 }
2994 3225
2995 pending_pos = core_pending_head; 3226 pending_pos = core_pending_head;
2996 while (NULL != pending_pos) 3227 while (NULL != pending_pos)
3228 {
3229 if (0 ==
3230 memcmp (&pending_pos->recipient, &neighbor->identity,
3231 sizeof (struct GNUNET_PeerIdentity)))
2997 { 3232 {
2998 if (0 == memcmp(&pending_pos->recipient, &neighbor->identity, sizeof(struct GNUNET_PeerIdentity))) 3233 GNUNET_CONTAINER_DLL_remove (core_pending_head, core_pending_tail,
2999 { 3234 pending_pos);
3000 GNUNET_CONTAINER_DLL_remove(core_pending_head, core_pending_tail, pending_pos); 3235 pending_pos = core_pending_head;
3001 pending_pos = core_pending_head;
3002 }
3003 else
3004 pending_pos = pending_pos->next;
3005 } 3236 }
3237 else
3238 pending_pos = pending_pos->next;
3239 }
3006 3240
3007 while (NULL != (referee = neighbor->referee_head)) 3241 while (NULL != (referee = neighbor->referee_head))
3008 distant_neighbor_free (referee); 3242 distant_neighbor_free (referee);
@@ -3010,24 +3244,28 @@ void handle_core_disconnect (void *cls,
3010 fdc.dest = NULL; 3244 fdc.dest = NULL;
3011 fdc.tid = 0; 3245 fdc.tid = 0;
3012 3246
3013 GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors, &find_distant_peer, &fdc); 3247 GNUNET_CONTAINER_multihashmap_iterate (extended_neighbors, &find_distant_peer,
3248 &fdc);
3014 3249
3015 if (fdc.dest != NULL) 3250 if (fdc.dest != NULL)
3016 { 3251 {
3017 disconnect_context.direct = neighbor; 3252 disconnect_context.direct = neighbor;
3018 disconnect_context.distant = fdc.dest; 3253 disconnect_context.distant = fdc.dest;
3019 GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors, &schedule_disconnect_messages, &disconnect_context); 3254 GNUNET_CONTAINER_multihashmap_iterate (direct_neighbors,
3020 } 3255 &schedule_disconnect_messages,
3256 &disconnect_context);
3257 }
3021 3258
3022 GNUNET_assert (neighbor->referee_tail == NULL); 3259 GNUNET_assert (neighbor->referee_tail == NULL);
3023 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_remove (direct_neighbors, 3260 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_remove (direct_neighbors,
3024 &peer->hashPubKey, neighbor)) 3261 &peer->hashPubKey,
3025 { 3262 neighbor))
3026 GNUNET_break(0); 3263 {
3027 } 3264 GNUNET_break (0);
3265 }
3028 if ((neighbor->send_context != NULL) && 3266 if ((neighbor->send_context != NULL) &&
3029 (neighbor->send_context->task != GNUNET_SCHEDULER_NO_TASK)) 3267 (neighbor->send_context->task != GNUNET_SCHEDULER_NO_TASK))
3030 GNUNET_SCHEDULER_cancel(neighbor->send_context->task); 3268 GNUNET_SCHEDULER_cancel (neighbor->send_context->task);
3031 GNUNET_free (neighbor); 3269 GNUNET_free (neighbor);
3032} 3270}
3033 3271
@@ -3045,6 +3283,7 @@ run (void *cls,
3045 const struct GNUNET_CONFIGURATION_Handle *c) 3283 const struct GNUNET_CONFIGURATION_Handle *c)
3046{ 3284{
3047 unsigned long long max_hosts; 3285 unsigned long long max_hosts;
3286
3048 cfg = c; 3287 cfg = c;
3049 3288
3050 /* FIXME: Read from config, or calculate, or something other than this! */ 3289 /* FIXME: Read from config, or calculate, or something other than this! */
@@ -3052,58 +3291,59 @@ run (void *cls,
3052 max_table_size = DEFAULT_DV_SIZE; 3291 max_table_size = DEFAULT_DV_SIZE;
3053 fisheye_depth = DEFAULT_FISHEYE_DEPTH; 3292 fisheye_depth = DEFAULT_FISHEYE_DEPTH;
3054 3293
3055 if (GNUNET_CONFIGURATION_have_value(cfg, "dv", "max_direct_connections")) 3294 if (GNUNET_CONFIGURATION_have_value (cfg, "dv", "max_direct_connections"))
3056 GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "dv", "max_direct_connections", &max_hosts)); 3295 GNUNET_assert (GNUNET_OK ==
3296 GNUNET_CONFIGURATION_get_value_number (cfg, "dv",
3297 "max_direct_connections",
3298 &max_hosts));
3057 3299
3058 if (GNUNET_CONFIGURATION_have_value(cfg, "dv", "max_total_connections")) 3300 if (GNUNET_CONFIGURATION_have_value (cfg, "dv", "max_total_connections"))
3059 GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "dv", "max_total_connections", &max_table_size)); 3301 GNUNET_assert (GNUNET_OK ==
3302 GNUNET_CONFIGURATION_get_value_number (cfg, "dv",
3303 "max_total_connections",
3304 &max_table_size));
3060 3305
3061 3306
3062 if (GNUNET_CONFIGURATION_have_value(cfg, "dv", "fisheye_depth")) 3307 if (GNUNET_CONFIGURATION_have_value (cfg, "dv", "fisheye_depth"))
3063 GNUNET_assert(GNUNET_OK == GNUNET_CONFIGURATION_get_value_number(cfg, "dv", "fisheye_depth", &fisheye_depth)); 3308 GNUNET_assert (GNUNET_OK ==
3309 GNUNET_CONFIGURATION_get_value_number (cfg, "dv",
3310 "fisheye_depth",
3311 &fisheye_depth));
3064 3312
3065 neighbor_min_heap = 3313 neighbor_min_heap =
3066 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN); 3314 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MIN);
3067 neighbor_max_heap = 3315 neighbor_max_heap =
3068 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX); 3316 GNUNET_CONTAINER_heap_create (GNUNET_CONTAINER_HEAP_ORDER_MAX);
3069 3317
3070 direct_neighbors = GNUNET_CONTAINER_multihashmap_create (max_hosts); 3318 direct_neighbors = GNUNET_CONTAINER_multihashmap_create (max_hosts);
3071 extended_neighbors = 3319 extended_neighbors =
3072 GNUNET_CONTAINER_multihashmap_create (max_table_size * 3); 3320 GNUNET_CONTAINER_multihashmap_create (max_table_size * 3);
3073 3321
3074 GNUNET_SERVER_add_handlers (server, plugin_handlers); 3322 GNUNET_SERVER_add_handlers (server, plugin_handlers);
3075 coreAPI = 3323 coreAPI = GNUNET_CORE_connect (cfg, 1, NULL, /* FIXME: anything we want to pass around? */
3076 GNUNET_CORE_connect (cfg, 3324 &core_init,
3077 1, 3325 &handle_core_connect,
3078 NULL, /* FIXME: anything we want to pass around? */ 3326 &handle_core_disconnect,
3079 &core_init, 3327 NULL,
3080 &handle_core_connect, 3328 NULL,
3081 &handle_core_disconnect, 3329 GNUNET_NO, NULL, GNUNET_NO, core_handlers);
3082 NULL,
3083 NULL,
3084 GNUNET_NO,
3085 NULL,
3086 GNUNET_NO,
3087 core_handlers);
3088 3330
3089 if (coreAPI == NULL) 3331 if (coreAPI == NULL)
3090 return; 3332 return;
3091 3333
3092 coreMST = GNUNET_SERVER_mst_create (&tokenized_message_handler, 3334 coreMST = GNUNET_SERVER_mst_create (&tokenized_message_handler, NULL);
3093 NULL);
3094 3335
3095 peerinfo_handle = GNUNET_PEERINFO_connect(cfg); 3336 peerinfo_handle = GNUNET_PEERINFO_connect (cfg);
3096 3337
3097 if (peerinfo_handle == NULL) 3338 if (peerinfo_handle == NULL)
3098 { 3339 {
3099 GNUNET_CORE_disconnect(coreAPI); 3340 GNUNET_CORE_disconnect (coreAPI);
3100 return; 3341 return;
3101 } 3342 }
3102 3343
3103 /* Scheduled the task to clean up when shutdown is called */ 3344 /* Scheduled the task to clean up when shutdown is called */
3104 cleanup_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, 3345 cleanup_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
3105 &shutdown_task, 3346 &shutdown_task, NULL);
3106 NULL);
3107} 3347}
3108 3348
3109 3349
@@ -3121,6 +3361,5 @@ main (int argc, char *const *argv)
3121 GNUNET_SERVICE_run (argc, 3361 GNUNET_SERVICE_run (argc,
3122 argv, 3362 argv,
3123 "dv", 3363 "dv",
3124 GNUNET_SERVICE_OPTION_NONE, 3364 GNUNET_SERVICE_OPTION_NONE, &run, NULL)) ? 0 : 1;
3125 &run, NULL)) ? 0 : 1;
3126} 3365}