diff options
author | Supriti Singh <supritisingh08@gmail.com> | 2014-08-13 13:58:41 +0000 |
---|---|---|
committer | Supriti Singh <supritisingh08@gmail.com> | 2014-08-13 13:58:41 +0000 |
commit | c04d50e9c8c9375e2bba39c2de9fe864fdb17572 (patch) | |
tree | c6022596e8ac5e0969d5f937dc1ce96a733e341e | |
parent | 0f78836a920e83ff987d0a4f3490de892bfa0892 (diff) | |
download | gnunet-c04d50e9c8c9375e2bba39c2de9fe864fdb17572.tar.gz gnunet-c04d50e9c8c9375e2bba39c2de9fe864fdb17572.zip |
Act Malicious service code
-rw-r--r-- | src/dht/dht_api.c | 40 | ||||
-rw-r--r-- | src/dht/gnunet-service-xdht_clients.c | 1 | ||||
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 108 | ||||
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.h | 9 | ||||
-rw-r--r-- | src/dht/gnunet_dht_profiler.c | 59 |
5 files changed, 191 insertions, 26 deletions
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c index 0a35ba988..8aa7320f5 100644 --- a/src/dht/dht_api.c +++ b/src/dht/dht_api.c | |||
@@ -1496,4 +1496,44 @@ GNUNET_DHT_monitor_stop (struct GNUNET_DHT_MonitorHandle *handle) | |||
1496 | GNUNET_free (handle); | 1496 | GNUNET_free (handle); |
1497 | } | 1497 | } |
1498 | 1498 | ||
1499 | |||
1500 | #if ENABLE_MALICIOUS | ||
1501 | /** | ||
1502 | * Turn the DHT service to act malicious depending on @a flag | ||
1503 | * | ||
1504 | * @param handle the DHT handle | ||
1505 | * @param action 1 to make the service malicious; 0 to make it benign | ||
1506 | FIXME: perhaps make this an enum of known malicious behaviors? | ||
1507 | */ | ||
1508 | void | ||
1509 | GNUNET_DHT_malicious (struct GNUNET_DHT_Handle *handle, unsigned int action) | ||
1510 | { | ||
1511 | struct GNUNET_DHT_ActMaliciousMessage *amm; | ||
1512 | struct PendingMessage *pending; | ||
1513 | size_t msize; | ||
1514 | |||
1515 | msize = sizeof(struct GNUNET_DHT_ActMaliciousMessage); | ||
1516 | if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) | ||
1517 | { | ||
1518 | GNUNET_break(0); | ||
1519 | return; | ||
1520 | } | ||
1521 | |||
1522 | pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize); | ||
1523 | amm = (struct GNUNET_DHT_ActMaliciousMessage *)&pending[1]; | ||
1524 | pending->msg = &amm->header; | ||
1525 | pending->handle = handle; | ||
1526 | pending->free_on_send = GNUNET_YES; | ||
1527 | amm->header.size = htons (msize); | ||
1528 | amm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_ACT_MALICIOUS); | ||
1529 | amm->action = action; | ||
1530 | |||
1531 | GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail, | ||
1532 | pending); | ||
1533 | pending->in_pending_queue = GNUNET_YES; | ||
1534 | process_pending_messages (handle); | ||
1535 | } | ||
1536 | #endif | ||
1537 | |||
1538 | |||
1499 | /* end of dht_api.c */ | 1539 | /* end of dht_api.c */ |
diff --git a/src/dht/gnunet-service-xdht_clients.c b/src/dht/gnunet-service-xdht_clients.c index 901b9c321..c5f6c0d83 100644 --- a/src/dht/gnunet-service-xdht_clients.c +++ b/src/dht/gnunet-service-xdht_clients.c | |||
@@ -1355,7 +1355,6 @@ static void | |||
1355 | handle_dht_act_malicious (void *cls, struct GNUNET_SERVER_Client *client, | 1355 | handle_dht_act_malicious (void *cls, struct GNUNET_SERVER_Client *client, |
1356 | const struct GNUNET_MessageHeader *message) | 1356 | const struct GNUNET_MessageHeader *message) |
1357 | { | 1357 | { |
1358 | /* FIXME: parse message and set malicious */ | ||
1359 | const struct GNUNET_DHT_ActMaliciousMessage *msg; | 1358 | const struct GNUNET_DHT_ActMaliciousMessage *msg; |
1360 | unsigned int malicious; | 1359 | unsigned int malicious; |
1361 | 1360 | ||
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 | */ |
879 | extern 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; | |||
892 | unsigned int track_topology; | 892 | unsigned 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 | */ | ||
898 | unsigned 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 | */ | ||
1006 | void | ||
1007 | GDS_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 == ¤t_successor->finger_identity) | 4969 | if (closest_peer == ¤t_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 | */ | ||
5937 | static void | ||
5938 | delete_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; |
diff --git a/src/dht/gnunet-service-xdht_neighbours.h b/src/dht/gnunet-service-xdht_neighbours.h index 8955fadb0..6d5c881ec 100644 --- a/src/dht/gnunet-service-xdht_neighbours.h +++ b/src/dht/gnunet-service-xdht_neighbours.h | |||
@@ -32,6 +32,15 @@ | |||
32 | #include "gnunet_dht_service.h" | 32 | #include "gnunet_dht_service.h" |
33 | 33 | ||
34 | 34 | ||
35 | #if ENABLE_MALICIOUS | ||
36 | /** | ||
37 | * Set the ENABLE_MALICIOUS value to malicious. | ||
38 | * @param malicious | ||
39 | */ | ||
40 | void | ||
41 | GDS_NEIGHBOURS_act_malicious (unsigned int malicious); | ||
42 | #endif | ||
43 | |||
35 | /** | 44 | /** |
36 | * Construct a Put message and send it to target_peer. | 45 | * Construct a Put message and send it to target_peer. |
37 | * @param key Key for the content | 46 | * @param key Key for the content |
diff --git a/src/dht/gnunet_dht_profiler.c b/src/dht/gnunet_dht_profiler.c index 0fb7ab7df..00668c8fb 100644 --- a/src/dht/gnunet_dht_profiler.c +++ b/src/dht/gnunet_dht_profiler.c | |||
@@ -38,7 +38,14 @@ | |||
38 | /** | 38 | /** |
39 | * Number of peers which should perform a PUT out of 100 peers | 39 | * Number of peers which should perform a PUT out of 100 peers |
40 | */ | 40 | */ |
41 | #define PUT_PROBABILITY 50 | 41 | #define PUT_PROBABILITY 100 |
42 | |||
43 | /** | ||
44 | * Percentage of peers that should act maliciously. | ||
45 | * These peers will never start PUT/GET request. | ||
46 | * n_active and n_malicious should not intersect. | ||
47 | */ | ||
48 | #define MALICIOUS_PEERS 0 | ||
42 | 49 | ||
43 | /** | 50 | /** |
44 | * Configuration | 51 | * Configuration |
@@ -160,6 +167,13 @@ static struct GNUNET_TIME_Relative timeout; | |||
160 | */ | 167 | */ |
161 | static unsigned int num_peers; | 168 | static unsigned int num_peers; |
162 | 169 | ||
170 | #if ENABLE_MALICIOUS | ||
171 | /** | ||
172 | * Number or malicious peers. | ||
173 | */ | ||
174 | static unsigned int n_malicious; | ||
175 | #endif | ||
176 | |||
163 | /** | 177 | /** |
164 | * Number of active peers | 178 | * Number of active peers |
165 | */ | 179 | */ |
@@ -585,7 +599,7 @@ static void | |||
585 | delayed_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 599 | delayed_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
586 | { | 600 | { |
587 | struct ActiveContext *ac = cls; | 601 | struct ActiveContext *ac = cls; |
588 | DEBUG("PUT SUPU \n"); | 602 | |
589 | ac->delay_task = GNUNET_SCHEDULER_NO_TASK; | 603 | ac->delay_task = GNUNET_SCHEDULER_NO_TASK; |
590 | /* Generate and DHT PUT some random data */ | 604 | /* Generate and DHT PUT some random data */ |
591 | ac->put_data_size = 16; /* minimum */ | 605 | ac->put_data_size = 16; /* minimum */ |
@@ -638,7 +652,7 @@ dht_connected (void *cls, | |||
638 | ctx->op = NULL; | 652 | ctx->op = NULL; |
639 | return; | 653 | return; |
640 | } | 654 | } |
641 | 655 | ||
642 | ac->delay_task = GNUNET_SCHEDULER_add_delayed (delay, &delayed_put, ac); | 656 | ac->delay_task = GNUNET_SCHEDULER_add_delayed (delay, &delayed_put, ac); |
643 | } | 657 | } |
644 | 658 | ||
@@ -706,6 +720,7 @@ start_testbed_service_on_all_peers() | |||
706 | } | 720 | } |
707 | } | 721 | } |
708 | 722 | ||
723 | static unsigned int tries; | ||
709 | 724 | ||
710 | /** | 725 | /** |
711 | * Stats callback. Iterate over the hashmap and check if all th peers form | 726 | * Stats callback. Iterate over the hashmap and check if all th peers form |
@@ -743,7 +758,7 @@ successor_stats_cont (void *cls, | |||
743 | 758 | ||
744 | if (start_val == val) | 759 | if (start_val == val) |
745 | { | 760 | { |
746 | DEBUG("Circle completed\n"); | 761 | DEBUG("CIRCLE COMPLETED after %u tries", tries); |
747 | if (GNUNET_SCHEDULER_NO_TASK != successor_stats_task) | 762 | if (GNUNET_SCHEDULER_NO_TASK != successor_stats_task) |
748 | { | 763 | { |
749 | successor_stats_task = GNUNET_SCHEDULER_NO_TASK; | 764 | successor_stats_task = GNUNET_SCHEDULER_NO_TASK; |
@@ -760,9 +775,6 @@ successor_stats_cont (void *cls, | |||
760 | } | 775 | } |
761 | else | 776 | else |
762 | { | 777 | { |
763 | static unsigned int tries; | ||
764 | |||
765 | DEBUG("Circle not complete\n"); | ||
766 | if (max_searches == ++tries) | 778 | if (max_searches == ++tries) |
767 | { | 779 | { |
768 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 780 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -810,7 +822,6 @@ successor_stats_iterator (void *cls, | |||
810 | int is_persistent) | 822 | int is_persistent) |
811 | { | 823 | { |
812 | static const char *key_string = "XDHT"; | 824 | static const char *key_string = "XDHT"; |
813 | |||
814 | if (0 == strncmp (key_string, name, strlen (key_string))) | 825 | if (0 == strncmp (key_string, name, strlen (key_string))) |
815 | { | 826 | { |
816 | char *my_id_str; | 827 | char *my_id_str; |
@@ -825,10 +836,8 @@ successor_stats_iterator (void *cls, | |||
825 | 836 | ||
826 | strncpy(truncated_my_id_str, my_id_str, 12); | 837 | strncpy(truncated_my_id_str, my_id_str, 12); |
827 | truncated_my_id_str[12] = '\0'; | 838 | truncated_my_id_str[12] = '\0'; |
828 | |||
829 | my_id_key = GNUNET_new(struct GNUNET_HashCode); | 839 | my_id_key = GNUNET_new(struct GNUNET_HashCode); |
830 | GNUNET_CRYPTO_hash (truncated_my_id_str, sizeof(truncated_my_id_str),my_id_key); | 840 | GNUNET_CRYPTO_hash (truncated_my_id_str, sizeof(truncated_my_id_str),my_id_key); |
831 | |||
832 | GNUNET_STRINGS_data_to_string(&value, sizeof(uint64_t), successor_str, 13); | 841 | GNUNET_STRINGS_data_to_string(&value, sizeof(uint64_t), successor_str, 13); |
833 | strncpy(truncated_successor_str, successor_str, 12); | 842 | strncpy(truncated_successor_str, successor_str, 12); |
834 | truncated_successor_str[12] ='\0'; | 843 | truncated_successor_str[12] ='\0'; |
@@ -862,6 +871,9 @@ collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
862 | return; | 871 | return; |
863 | 872 | ||
864 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start collecting statistics...\n"); | 873 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start collecting statistics...\n"); |
874 | DEBUG("num_peers = %d", num_peers); | ||
875 | GNUNET_assert(NULL != testbed_handles); | ||
876 | |||
865 | 877 | ||
866 | /* Check for successor pointer, don't start put till the virtual ring topology | 878 | /* Check for successor pointer, don't start put till the virtual ring topology |
867 | is not created. */ | 879 | is not created. */ |
@@ -870,6 +882,8 @@ collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
870 | "dht", NULL, | 882 | "dht", NULL, |
871 | successor_stats_iterator, | 883 | successor_stats_iterator, |
872 | successor_stats_cont, cls); | 884 | successor_stats_cont, cls); |
885 | |||
886 | GNUNET_assert(successor_stats_op); | ||
873 | } | 887 | } |
874 | 888 | ||
875 | /** | 889 | /** |
@@ -901,9 +915,9 @@ service_started (void *cls, | |||
901 | 915 | ||
902 | peer_contexts[peers_started] = ctx; | 916 | peer_contexts[peers_started] = ctx; |
903 | peers_started++; | 917 | peers_started++; |
904 | DEBUG("Peers Started = %d \n", peers_started); | 918 | DEBUG("Peers Started = %d; num_peers = %d \n", peers_started, num_peers); |
905 | 919 | ||
906 | if (GNUNET_SCHEDULER_NO_TASK == successor_stats_task) | 920 | if (GNUNET_SCHEDULER_NO_TASK == successor_stats_task && peers_started == num_peers) |
907 | { | 921 | { |
908 | DEBUG("successor_stats_task \n"); | 922 | DEBUG("successor_stats_task \n"); |
909 | struct Collect_Stat_Context *collect_stat_cls = GNUNET_new(struct Collect_Stat_Context); | 923 | struct Collect_Stat_Context *collect_stat_cls = GNUNET_new(struct Collect_Stat_Context); |
@@ -958,6 +972,25 @@ test_run (void *cls, | |||
958 | return; | 972 | return; |
959 | } | 973 | } |
960 | 974 | ||
975 | #if ENABLE_MALICIOUS | ||
976 | |||
977 | if(PUT_PROBABILITY + MALICIOUS_PEERS > 100) | ||
978 | { | ||
979 | DEBUG ("Reduce either number of malicious peer or active peers. "); | ||
980 | GNUNET_SCHEDULER_shutdown (); | ||
981 | GNUNET_free (a_ctx); | ||
982 | return; | ||
983 | } | ||
984 | |||
985 | /* Select the peers which should act maliciously. */ | ||
986 | n_malicious = num_peers * MALICIOUS_PEERS / 100; | ||
987 | |||
988 | /* Select n_malicious peers and ensure that those are not active peers. | ||
989 | keep all malicious peer at one place, and call act malicious for all | ||
990 | those peers. */ | ||
991 | |||
992 | #endif | ||
993 | |||
961 | a_ac = GNUNET_malloc (n_active * sizeof (struct ActiveContext)); | 994 | a_ac = GNUNET_malloc (n_active * sizeof (struct ActiveContext)); |
962 | ac_cnt = 0; | 995 | ac_cnt = 0; |
963 | for (cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++) | 996 | for (cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++) |
@@ -1051,7 +1084,7 @@ main (int argc, char *const *argv) | |||
1051 | max_searches = 10; | 1084 | max_searches = 10; |
1052 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 1085 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
1053 | return 2; | 1086 | return 2; |
1054 | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2); /* default delay */ | 1087 | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20); /* default delay */ |
1055 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1); /* default timeout */ | 1088 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1); /* default timeout */ |
1056 | replication = 1; /* default replication */ | 1089 | replication = 1; /* default replication */ |
1057 | rc = 0; | 1090 | rc = 0; |