aboutsummaryrefslogtreecommitdiff
path: root/src/dht/gnunet-service-xdht_neighbours.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/dht/gnunet-service-xdht_neighbours.c')
-rw-r--r--src/dht/gnunet-service-xdht_neighbours.c108
1 files changed, 96 insertions, 12 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c
index a06dfd87b..3d6d6f85e 100644
--- a/src/dht/gnunet-service-xdht_neighbours.c
+++ b/src/dht/gnunet-service-xdht_neighbours.c
@@ -876,7 +876,7 @@ static struct GNUNET_CORE_Handle *core_api;
876/** 876/**
877 * Handle for the statistics service. 877 * Handle for the statistics service.
878 */ 878 */
879extern struct GNUNET_STATISTICS_Handle *GDS_stats; 879//extern struct GNUNET_STATISTICS_Handle *GDS_stats;
880 880
881/** 881/**
882 * The current finger index that we have want to find trail to. We start the 882 * The current finger index that we have want to find trail to. We start the
@@ -892,6 +892,12 @@ static unsigned int current_search_finger_index;
892unsigned int track_topology; 892unsigned int track_topology;
893 893
894/** 894/**
895 * Should I be a malicious peer and drop the PUT/GET packets?
896 * if 0 then NOT malicious.
897 */
898unsigned int act_malicious;
899
900/**
895 * Called when core is ready to send a message we asked for 901 * Called when core is ready to send a message we asked for
896 * out to the destination. 902 * out to the destination.
897 * 903 *
@@ -992,6 +998,18 @@ process_friend_queue (struct FriendInfo *peer)
992} 998}
993 999
994 1000
1001#if ENABLE_MALICIOUS
1002/**
1003 * Set the ENABLE_MALICIOUS value to malicious.
1004 * @param malicious
1005 */
1006void
1007GDS_NEIGHBOURS_act_malicious (unsigned int malicious)
1008{
1009 act_malicious = malicious;
1010}
1011#endif
1012
995/** 1013/**
996 * Construct a trail setup message and forward it to target_friend 1014 * Construct a trail setup message and forward it to target_friend
997 * @param source_peer Peer which wants to setup the trail 1015 * @param source_peer Peer which wants to setup the trail
@@ -2093,6 +2111,8 @@ find_successor (uint64_t destination_finger_value,
2093 2111
2094 2112
2095/** 2113/**
2114 * FIXME; Send put message across all the trail to reach to next hop to handle
2115 * malicious peers.
2096 * Construct a Put message and send it to target_peer. 2116 * Construct a Put message and send it to target_peer.
2097 * @param key Key for the content 2117 * @param key Key for the content
2098 * @param block_type Type of the block 2118 * @param block_type Type of the block
@@ -2134,6 +2154,18 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key,
2134 msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size + 2154 msize = put_path_length * sizeof (struct GNUNET_PeerIdentity) + data_size +
2135 sizeof (struct PeerPutMessage); 2155 sizeof (struct PeerPutMessage);
2136 2156
2157#if ENABLE_MALICIOUS
2158 /*Call is made to this function from
2159 1. First peer.
2160 2. Every peer to construct a pending message and send it to next peer.
2161 In case of 2nd, this case should have been handled in handle_dht_p2p_put/get
2162 No need to check here. First peer can never be malicious. IDEALLY we DONOT
2163 need the condition here. REMOVE IT AFTERWARDS once verified.*/
2164 if(1 == act_malicious)
2165 {
2166 return;
2167 }
2168#endif
2137 if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) 2169 if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE)
2138 { 2170 {
2139 put_path_length = 0; 2171 put_path_length = 0;
@@ -2212,6 +2244,8 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key,
2212 2244
2213 2245
2214/** 2246/**
2247 * FIXME; Send get message across all the trail to reach to next hop to handle
2248 * malicious peers.
2215 * Construct a Get message and send it to target_peer. 2249 * Construct a Get message and send it to target_peer.
2216 * @param key Key for the content 2250 * @param key Key for the content
2217 * @param block_type Type of the block 2251 * @param block_type Type of the block
@@ -2249,6 +2283,12 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key,
2249 msize = sizeof (struct PeerGetMessage) + 2283 msize = sizeof (struct PeerGetMessage) +
2250 (get_path_length * sizeof (struct GNUNET_PeerIdentity)); 2284 (get_path_length * sizeof (struct GNUNET_PeerIdentity));
2251 2285
2286#if ENABLE_MALICIOUS
2287 if(1 == act_malicious)
2288 {
2289 return;
2290 }
2291#endif
2252 //GNUNET_SERVER_MAX_MESSAGE_SIZE 2292 //GNUNET_SERVER_MAX_MESSAGE_SIZE
2253 /* FIXME:TODO:URGENTHere you can try to optimize it a bit. In case the get path contains you 2293 /* FIXME:TODO:URGENTHere you can try to optimize it a bit. In case the get path contains you
2254 or your friend then shorten the path. */ 2294 or your friend then shorten the path. */
@@ -2298,7 +2338,7 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key,
2298 { 2338 {
2299 GNUNET_assert (NULL != 2339 GNUNET_assert (NULL !=
2300 (target_friend = 2340 (target_friend =
2301 GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer))); //FIXME: assertion fails. 2341 GNUNET_CONTAINER_multipeermap_get (friend_peermap, target_peer)));
2302 } 2342 }
2303 2343
2304 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize); 2344 pending = GNUNET_malloc (sizeof (struct P2PPendingMessage) + msize);
@@ -3404,7 +3444,6 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3404 finger_trail_length, 3444 finger_trail_length,
3405 finger_trail_id, 3445 finger_trail_id,
3406 &updated_finger_trail_length); 3446 &updated_finger_trail_length);
3407
3408 add_new_finger (finger_identity, updated_trail, 3447 add_new_finger (finger_identity, updated_trail,
3409 updated_finger_trail_length, 3448 updated_finger_trail_length,
3410 finger_trail_id, finger_table_index); 3449 finger_trail_id, finger_table_index);
@@ -3491,7 +3530,10 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3491 return; 3530 return;
3492} 3531}
3493 3532
3533
3494/** 3534/**
3535 * FIXME: Check for loop in the request. If you already are part of put path,
3536 * then you need to reset the put path length.
3495 * Core handler for P2P put messages. 3537 * Core handler for P2P put messages.
3496 * @param cls closure 3538 * @param cls closure
3497 * @param peer sender of the request 3539 * @param peer sender of the request
@@ -3516,6 +3558,14 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
3516 size_t payload_size; 3558 size_t payload_size;
3517 uint64_t key_value; 3559 uint64_t key_value;
3518 3560
3561#if ENABLE_MALICIOUS
3562 if(1 == act_malicious)
3563 {
3564 DEBUG("I am malicious,dropping put request. \n");
3565 return GNUNET_OK;
3566 }
3567#endif
3568
3519 msize = ntohs (message->size); 3569 msize = ntohs (message->size);
3520 if (msize < sizeof (struct PeerPutMessage)) 3570 if (msize < sizeof (struct PeerPutMessage))
3521 { 3571 {
@@ -3668,6 +3718,8 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
3668 3718
3669 3719
3670/** 3720/**
3721 * FIXME: Check for loop in the request. If you already are part of get path,
3722 * then you need to reset the get path length.
3671 * Core handler for p2p get requests. 3723 * Core handler for p2p get requests.
3672 * 3724 *
3673 * @param cls closure 3725 * @param cls closure
@@ -3689,6 +3741,14 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
3689 uint64_t key_value; 3741 uint64_t key_value;
3690 size_t msize; 3742 size_t msize;
3691 3743
3744#if ENABLE_MALICIOUS
3745 if(1 == act_malicious)
3746 {
3747 DEBUG("I am malicious,dropping get request. \n");
3748 return GNUNET_OK;
3749 }
3750#endif
3751
3692 msize = ntohs (message->size); 3752 msize = ntohs (message->size);
3693 if (msize < sizeof (struct PeerGetMessage)) 3753 if (msize < sizeof (struct PeerGetMessage))
3694 { 3754 {
@@ -4237,8 +4297,6 @@ handle_dht_p2p_trail_setup_result(void *cls, const struct GNUNET_PeerIdentity *p
4237 ulitmate_destination_finger_value = 4297 ulitmate_destination_finger_value =
4238 GNUNET_ntohll (trail_result->ulitmate_destination_finger_value); 4298 GNUNET_ntohll (trail_result->ulitmate_destination_finger_value);
4239 4299
4240 /* FIXME: here we are calculating my_index and comparing also in this function.
4241 And we are doing it again here in this function. Re factor the code. */
4242 /* Ensure that sender peer is the peer from which we were expecting the message. */ 4300 /* Ensure that sender peer is the peer from which we were expecting the message. */
4243#if 0 4301#if 0
4244 if (GNUNET_NO == is_sender_peer_correct (trail_peer_list, 4302 if (GNUNET_NO == is_sender_peer_correct (trail_peer_list,
@@ -4433,7 +4491,7 @@ check_for_duplicate_entries (const struct GNUNET_PeerIdentity *trail_1,
4433 4491
4434 4492
4435 /* Copy all the elements from 0 to i into joined_trail. */ 4493 /* Copy all the elements from 0 to i into joined_trail. */
4436 for(k = 0; k < (i+1); k++) 4494 for(k = 0; k < ( i+1); k++)
4437 { 4495 {
4438 joined_trail[k] = trail_1[k]; 4496 joined_trail[k] = trail_1[k];
4439 } 4497 }
@@ -4442,7 +4500,7 @@ check_for_duplicate_entries (const struct GNUNET_PeerIdentity *trail_1,
4442 j = j+1; 4500 j = j+1;
4443 4501
4444 /* Copy all the elements from j to trail_2_len-1 to joined trail.*/ 4502 /* Copy all the elements from j to trail_2_len-1 to joined trail.*/
4445 while((k < *joined_trail_len) && (j < trail_2_len)); 4503 while(k <= (*joined_trail_len - 1))
4446 { 4504 {
4447 joined_trail[k] = trail_2[j]; 4505 joined_trail[k] = trail_2[j];
4448 j++; 4506 j++;
@@ -4911,8 +4969,8 @@ compare_and_update_successor (struct GNUNET_PeerIdentity curr_succ,
4911 if (closest_peer == &current_successor->finger_identity) 4969 if (closest_peer == &current_successor->finger_identity)
4912 { 4970 {
4913 /* Code for testing ONLY: Store the successor for path tracking */ 4971 /* Code for testing ONLY: Store the successor for path tracking */
4914 track_topology = 1; 4972// track_topology = 1;
4915 if (track_topology && (NULL != GDS_stats)) 4973 if ((NULL != GDS_stats))
4916 { 4974 {
4917 char *my_id_str; 4975 char *my_id_str;
4918 uint64_t succ; 4976 uint64_t succ;
@@ -5571,7 +5629,7 @@ remove_matching_trails (const struct GNUNET_PeerIdentity *disconnected_friend,
5571 matching_trails_count = 0; 5629 matching_trails_count = 0;
5572 5630
5573 /* Iterate over all the trails of finger. */ 5631 /* Iterate over all the trails of finger. */
5574 for (i = 0; i < MAXIMUM_TRAILS_PER_FINGER; i++) 5632 for (i = 0; i < remove_finger->trails_count; i++)
5575 { 5633 {
5576 struct Trail *trail; 5634 struct Trail *trail;
5577 trail = &remove_finger->trail_list[i]; 5635 trail = &remove_finger->trail_list[i];
@@ -5787,7 +5845,6 @@ handle_core_connect (void *cls, const struct GNUNET_PeerIdentity *peer_identity)
5787 peer_identity, friend, 5845 peer_identity, friend,
5788 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY)); 5846 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
5789 5847
5790
5791 /* got a first connection, good time to start with FIND FINGER TRAIL requests...*/ 5848 /* got a first connection, good time to start with FIND FINGER TRAIL requests...*/
5792 if (GNUNET_SCHEDULER_NO_TASK == find_finger_trail_task) 5849 if (GNUNET_SCHEDULER_NO_TASK == find_finger_trail_task)
5793 { 5850 {
@@ -5855,11 +5912,16 @@ GDS_NEIGHBOURS_init (void)
5855 {&handle_dht_p2p_add_trail, GNUNET_MESSAGE_TYPE_XDHT_P2P_ADD_TRAIL, 0}, 5912 {&handle_dht_p2p_add_trail, GNUNET_MESSAGE_TYPE_XDHT_P2P_ADD_TRAIL, 0},
5856 {NULL, 0, 0} 5913 {NULL, 0, 0}
5857 }; 5914 };
5858 5915
5916#if ENABLE_MALICIOUS
5917 act_malicious = 0;
5918#endif
5919
5859 core_api = 5920 core_api =
5860 GNUNET_CORE_connect (GDS_cfg, NULL, &core_init, &handle_core_connect, 5921 GNUNET_CORE_connect (GDS_cfg, NULL, &core_init, &handle_core_connect,
5861 &handle_core_disconnect, NULL, GNUNET_NO, NULL, 5922 &handle_core_disconnect, NULL, GNUNET_NO, NULL,
5862 GNUNET_NO, core_handlers); 5923 GNUNET_NO, core_handlers);
5924
5863 if (NULL == core_api) 5925 if (NULL == core_api)
5864 return GNUNET_SYSERR; 5926 return GNUNET_SYSERR;
5865 5927
@@ -5869,6 +5931,26 @@ GDS_NEIGHBOURS_init (void)
5869 return GNUNET_OK; 5931 return GNUNET_OK;
5870} 5932}
5871 5933
5934/**
5935 * Free the memory held up by trails of a finger.
5936 */
5937static void
5938delete_finger_table_entries()
5939{
5940 unsigned int i;
5941 unsigned int j;
5942
5943 for(i = 0; i < MAX_FINGERS; i++)
5944 {
5945 if(GNUNET_NO == finger_table[i].is_present)
5946 continue;
5947
5948 for(j = 0; j < finger_table[i].trails_count; j++)
5949 {
5950 free_trail(&finger_table[i].trail_list[i]);
5951 }
5952 }
5953}
5872 5954
5873/** 5955/**
5874 * Shutdown neighbours subsystem. 5956 * Shutdown neighbours subsystem.
@@ -5882,6 +5964,8 @@ GDS_NEIGHBOURS_done (void)
5882 GNUNET_CORE_disconnect (core_api); 5964 GNUNET_CORE_disconnect (core_api);
5883 core_api = NULL; 5965 core_api = NULL;
5884 5966
5967 delete_finger_table_entries();
5968
5885 GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (friend_peermap)); 5969 GNUNET_assert (0 == GNUNET_CONTAINER_multipeermap_size (friend_peermap));
5886 GNUNET_CONTAINER_multipeermap_destroy (friend_peermap); 5970 GNUNET_CONTAINER_multipeermap_destroy (friend_peermap);
5887 friend_peermap = NULL; 5971 friend_peermap = NULL;