diff options
-rw-r--r-- | src/dv/gnunet-service-dv.c | 110 |
1 files changed, 76 insertions, 34 deletions
diff --git a/src/dv/gnunet-service-dv.c b/src/dv/gnunet-service-dv.c index 21e2e6657..ebf8e82fe 100644 --- a/src/dv/gnunet-service-dv.c +++ b/src/dv/gnunet-service-dv.c | |||
@@ -390,15 +390,18 @@ size_t transmit_to_plugin (void *cls, | |||
390 | size_t size, void *buf) | 390 | size_t size, void *buf) |
391 | { | 391 | { |
392 | struct GNUNET_DV_MessageReceived *msg = cls; | 392 | struct GNUNET_DV_MessageReceived *msg = cls; |
393 | int msize; | ||
393 | 394 | ||
394 | if (buf == NULL) | 395 | if (buf == NULL) |
395 | return 0; | 396 | return 0; |
396 | 397 | ||
397 | GNUNET_assert(size >= ntohs(msg->header.size)); | 398 | msize = ntohs(msg->header.size); |
399 | GNUNET_assert(size >= msize); | ||
398 | 400 | ||
399 | memcpy(buf, msg, size); | 401 | |
402 | memcpy(buf, msg, msize); | ||
400 | GNUNET_free(msg); | 403 | GNUNET_free(msg); |
401 | return size; | 404 | return msize; |
402 | } | 405 | } |
403 | 406 | ||
404 | 407 | ||
@@ -730,6 +733,7 @@ neighbor_send_task (void *cls, | |||
730 | memcpy (&message->neighbor, | 733 | memcpy (&message->neighbor, |
731 | &about->identity, sizeof (struct GNUNET_PeerIdentity)); | 734 | &about->identity, sizeof (struct GNUNET_PeerIdentity)); |
732 | 735 | ||
736 | pending_message->msg_size = sizeof(p2p_dv_MESSAGE_NeighborInfo); | ||
733 | pending_message->transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, default_dv_priority, default_dv_delay, &to->identity, sizeof(p2p_dv_MESSAGE_NeighborInfo), &core_transmit_notify, pending_message); | 737 | pending_message->transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, default_dv_priority, default_dv_delay, &to->identity, sizeof(p2p_dv_MESSAGE_NeighborInfo), &core_transmit_notify, pending_message); |
734 | 738 | ||
735 | if (NULL == pending_message->transmit_handle) | 739 | if (NULL == pending_message->transmit_handle) |
@@ -747,33 +751,6 @@ neighbor_send_task (void *cls, | |||
747 | return; | 751 | return; |
748 | } | 752 | } |
749 | 753 | ||
750 | /** | ||
751 | * Core handler for dv gossip messages. These will be used | ||
752 | * by us to create a HELLO message for the newly peer containing | ||
753 | * which direct peer we can connect through, and what the cost | ||
754 | * is. This HELLO will then be scheduled for validation by the | ||
755 | * transport service so that it can be used by all others. | ||
756 | * | ||
757 | * @param cls closure | ||
758 | * @param peer peer which sent the message (immediate sender) | ||
759 | * @param message the message | ||
760 | * @param latency the latency of the connection we received the message from | ||
761 | * @param distance the distance to the immediate peer | ||
762 | */ | ||
763 | static int handle_dv_gossip_message (void *cls, | ||
764 | const struct GNUNET_PeerIdentity *peer, | ||
765 | const struct GNUNET_MessageHeader *message, | ||
766 | struct GNUNET_TIME_Relative latency, | ||
767 | uint32_t distance) | ||
768 | { | ||
769 | #if DEBUG_DV | ||
770 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
771 | "%s: Receives %s message!\n", "dv", "DV GOSSIP"); | ||
772 | #endif | ||
773 | |||
774 | return 0; | ||
775 | } | ||
776 | |||
777 | 754 | ||
778 | /** | 755 | /** |
779 | * Service server's handler for message send requests (which come | 756 | * Service server's handler for message send requests (which come |
@@ -810,6 +787,11 @@ void send_dv_message (void *cls, | |||
810 | GNUNET_SERVER_receive_done(client, GNUNET_OK); | 787 | GNUNET_SERVER_receive_done(client, GNUNET_OK); |
811 | } | 788 | } |
812 | 789 | ||
790 | static int handle_dv_gossip_message (void *cls, | ||
791 | const struct GNUNET_PeerIdentity *peer, | ||
792 | const struct GNUNET_MessageHeader *message, | ||
793 | struct GNUNET_TIME_Relative latency, | ||
794 | uint32_t distance); | ||
813 | 795 | ||
814 | /** | 796 | /** |
815 | * List of handlers for the messages understood by this | 797 | * List of handlers for the messages understood by this |
@@ -886,9 +868,9 @@ static int update_matching_neighbors (void *cls, | |||
886 | void *value) | 868 | void *value) |
887 | { | 869 | { |
888 | struct NeighborUpdateInfo * update_info = cls; | 870 | struct NeighborUpdateInfo * update_info = cls; |
889 | struct DirectNeighbor *direct_neighbor = value; | 871 | struct DistantNeighbor *distant_neighbor = value; |
890 | 872 | ||
891 | if (update_info->referrer == direct_neighbor) /* Direct neighbor matches, update it's info and return GNUNET_NO */ | 873 | if (update_info->referrer == distant_neighbor->referrer) /* Direct neighbor matches, update it's info and return GNUNET_NO */ |
892 | { | 874 | { |
893 | /* same referrer, cost change! */ | 875 | /* same referrer, cost change! */ |
894 | GNUNET_CONTAINER_heap_update_cost (ctx.neighbor_max_heap, | 876 | GNUNET_CONTAINER_heap_update_cost (ctx.neighbor_max_heap, |
@@ -929,7 +911,7 @@ distant_neighbor_free (struct DistantNeighbor *referee) | |||
929 | 911 | ||
930 | /** | 912 | /** |
931 | * Handles when a peer is either added due to being newly connected | 913 | * Handles when a peer is either added due to being newly connected |
932 | * or having been gossiped about, also called when a cost for a neighbor | 914 | * or having been gossiped about, also called when the cost for a neighbor |
933 | * needs to be updated. | 915 | * needs to be updated. |
934 | * | 916 | * |
935 | * @param peer identity of the peer whose info is being added/updated | 917 | * @param peer identity of the peer whose info is being added/updated |
@@ -1013,7 +995,17 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer, | |||
1013 | neighbor, | 995 | neighbor, |
1014 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); | 996 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE); |
1015 | } | 997 | } |
1016 | 998 | else | |
999 | { | ||
1000 | #if DEBUG_DV | ||
1001 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1002 | "%s: Already know peer %s distance %d, referrer id %d!\n", "dv", GNUNET_i2s(peer), cost, referrer_peer_id); | ||
1003 | #endif | ||
1004 | } | ||
1005 | #if DEBUG_DV | ||
1006 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1007 | "%s: Size of extended_neighbors is %d\n", "dv", GNUNET_CONTAINER_multihashmap_size(ctx.extended_neighbors)); | ||
1008 | #endif | ||
1017 | GNUNET_free(neighbor_update); | 1009 | GNUNET_free(neighbor_update); |
1018 | /* Old logic to remove entry and replace, not needed now as we only want to remove when full | 1010 | /* Old logic to remove entry and replace, not needed now as we only want to remove when full |
1019 | * or when the referring peer disconnects from us. | 1011 | * or when the referring peer disconnects from us. |
@@ -1034,6 +1026,56 @@ addUpdateNeighbor (const struct GNUNET_PeerIdentity * peer, | |||
1034 | */ | 1026 | */ |
1035 | } | 1027 | } |
1036 | 1028 | ||
1029 | /** | ||
1030 | * Core handler for dv gossip messages. These will be used | ||
1031 | * by us to create a HELLO message for the newly peer containing | ||
1032 | * which direct peer we can connect through, and what the cost | ||
1033 | * is. This HELLO will then be scheduled for validation by the | ||
1034 | * transport service so that it can be used by all others. | ||
1035 | * | ||
1036 | * @param cls closure | ||
1037 | * @param peer peer which sent the message (immediate sender) | ||
1038 | * @param message the message | ||
1039 | * @param latency the latency of the connection we received the message from | ||
1040 | * @param distance the distance to the immediate peer | ||
1041 | */ | ||
1042 | static int handle_dv_gossip_message (void *cls, | ||
1043 | const struct GNUNET_PeerIdentity *peer, | ||
1044 | const struct GNUNET_MessageHeader *message, | ||
1045 | struct GNUNET_TIME_Relative latency, | ||
1046 | uint32_t distance) | ||
1047 | { | ||
1048 | #if DEBUG_DV | ||
1049 | char * encPeerAbout; | ||
1050 | char * encPeerFrom; | ||
1051 | #endif | ||
1052 | struct DirectNeighbor *referrer; | ||
1053 | p2p_dv_MESSAGE_NeighborInfo *enc_message = (p2p_dv_MESSAGE_NeighborInfo *)message; | ||
1054 | #if DEBUG_DV | ||
1055 | encPeerAbout = GNUNET_strdup(GNUNET_i2s(&enc_message->neighbor)); | ||
1056 | encPeerFrom = GNUNET_strdup(GNUNET_i2s(peer)); | ||
1057 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1058 | "%s: Receives %s message from peer %s about peer %s!\n", "dv", "DV GOSSIP", encPeerFrom, encPeerAbout); | ||
1059 | GNUNET_free(encPeerAbout); | ||
1060 | GNUNET_free(encPeerFrom); | ||
1061 | #endif | ||
1062 | |||
1063 | if (ntohs (message->size) < sizeof (p2p_dv_MESSAGE_NeighborInfo)) | ||
1064 | { | ||
1065 | return GNUNET_SYSERR; /* invalid message */ | ||
1066 | } | ||
1067 | |||
1068 | referrer = GNUNET_CONTAINER_multihashmap_get (ctx.direct_neighbors, | ||
1069 | &peer->hashPubKey); | ||
1070 | if (referrer == NULL) | ||
1071 | return GNUNET_OK; | ||
1072 | |||
1073 | addUpdateNeighbor (&enc_message->neighbor, | ||
1074 | ntohl (enc_message->neighbor_id), | ||
1075 | referrer, ntohl (enc_message->cost) + 1); | ||
1076 | |||
1077 | return GNUNET_OK; | ||
1078 | } | ||
1037 | 1079 | ||
1038 | /** | 1080 | /** |
1039 | * Method called whenever a peer connects. | 1081 | * Method called whenever a peer connects. |