aboutsummaryrefslogtreecommitdiff
path: root/src/dht
diff options
context:
space:
mode:
authorSupriti Singh <supritisingh08@gmail.com>2014-09-22 15:12:15 +0000
committerSupriti Singh <supritisingh08@gmail.com>2014-09-22 15:12:15 +0000
commit3a85995c4a7a48f7afae1c554e9df3547ca7db3f (patch)
treebf4d46b158a973e4900e4792e80e860b324c2a0a /src/dht
parentb97fc3b79ac05184f0928af8071e76dcbd8f99ea (diff)
downloadgnunet-3a85995c4a7a48f7afae1c554e9df3547ca7db3f.tar.gz
gnunet-3a85995c4a7a48f7afae1c554e9df3547ca7db3f.zip
- Act malicious API complete
- Using multiple trails in PUT/GET
Diffstat (limited to 'src/dht')
-rw-r--r--src/dht/dht.h15
-rw-r--r--src/dht/dht_api.c95
-rw-r--r--src/dht/gnunet-service-xdht_clients.c30
-rw-r--r--src/dht/gnunet-service-xdht_neighbours.c227
-rw-r--r--src/dht/gnunet-service-xdht_neighbours.h2
-rw-r--r--src/dht/gnunet_dht_profiler.c327
6 files changed, 501 insertions, 195 deletions
diff --git a/src/dht/dht.h b/src/dht/dht.h
index f630e5a33..524cb4bda 100644
--- a/src/dht/dht.h
+++ b/src/dht/dht.h
@@ -442,6 +442,19 @@ struct GNUNET_DHT_MonitorGetRespMessage
442}; 442};
443 443
444#if ENABLE_MALICIOUS 444#if ENABLE_MALICIOUS
445
446/**
447 * Message to confirming receipt of ACT MALICIOUS, sent from DHT service to clients.
448 */
449struct GNUNET_DHT_ClientActMaliciousConfirmationMessage
450{
451 /**
452 * Type: #GNUNET_MESSAGE_TYPE_DHT_CLIENT_PUT_OK
453 */
454 struct GNUNET_MessageHeader header;
455};
456
457
445/** 458/**
446 * Message to turn the service malicious 459 * Message to turn the service malicious
447 */ 460 */
@@ -453,7 +466,7 @@ struct GNUNET_DHT_ActMaliciousMessage
453 struct GNUNET_MessageHeader header; 466 struct GNUNET_MessageHeader header;
454 467
455 /** 468 /**
456 * Type of malicious behaviour expected; 0 turning peer benign 469 * If set to 1, act maliciously
457 */ 470 */
458 uint32_t action; 471 uint32_t action;
459}; 472};
diff --git a/src/dht/dht_api.c b/src/dht/dht_api.c
index 8aa7320f5..be699e65e 100644
--- a/src/dht/dht_api.c
+++ b/src/dht/dht_api.c
@@ -93,6 +93,28 @@ struct PendingMessage
93 93
94}; 94};
95 95
96#if ENABLE_MALICIOUS
97/**
98 * Handle to act malicious message
99 */
100struct GNUNET_DHT_ActMaliciousHandle
101{
102 /**
103 * Continuation to call when done.
104 */
105 GNUNET_DHT_ActMaliciousContinuation cont;
106
107 /**
108 * Main handle to this DHT api
109 */
110 struct GNUNET_DHT_Handle *dht_handle;
111
112 /**
113 * Closure for 'cont'.
114 */
115 void *cont_cls;
116};
117#endif
96 118
97/** 119/**
98 * Handle to a PUT request. 120 * Handle to a PUT request.
@@ -142,8 +164,6 @@ struct GNUNET_DHT_PutHandle
142 164
143}; 165};
144 166
145
146
147/** 167/**
148 * Handle to a GET request 168 * Handle to a GET request
149 */ 169 */
@@ -342,6 +362,13 @@ struct GNUNET_DHT_Handle
342 * Did we start our receive loop yet? 362 * Did we start our receive loop yet?
343 */ 363 */
344 int in_receive; 364 int in_receive;
365
366#if ENABLE_MALICIOUS
367 /**
368 * Handle of act malicious request.
369 */
370 struct GNUNET_DHT_ActMaliciousHandle *mh;
371#endif
345}; 372};
346 373
347 374
@@ -857,6 +884,35 @@ process_monitor_put_message (struct GNUNET_DHT_Handle *handle,
857} 884}
858 885
859 886
887#if ENABLE_MALICIOUS
888/**
889 * Process a act malicious confirmation from service.
890 * @param handle The DHT handle.
891 * @param msg confirmation message from the service.
892 * @return #GNUNET_OK if everything went fine,
893 * #GNUNET_SYSERR if the message is malformed.
894 */
895static int
896process_act_malicious_confirmation_message (struct GNUNET_DHT_Handle *handle,
897 const struct GNUNET_DHT_ClientActMaliciousConfirmationMessage *msg)
898{
899 struct GNUNET_DHT_ActMaliciousHandle *mh;
900 GNUNET_DHT_PutContinuation cont;
901 void *cont_cls;
902
903 mh = handle->mh;
904 if (NULL == mh)
905 return GNUNET_OK;
906 cont = mh->cont;
907 cont_cls = mh->cont_cls;
908 if (NULL != cont)
909 cont (cont_cls, GNUNET_OK);
910
911 return GNUNET_OK;
912}
913#endif
914
915
860/** 916/**
861 * Process a put confirmation message from the service. 917 * Process a put confirmation message from the service.
862 * 918 *
@@ -972,6 +1028,17 @@ service_message_handler (void *cls, const struct GNUNET_MessageHeader *msg)
972 ret = process_put_confirmation_message (handle, 1028 ret = process_put_confirmation_message (handle,
973 (const struct GNUNET_DHT_ClientPutConfirmationMessage*) msg); 1029 (const struct GNUNET_DHT_ClientPutConfirmationMessage*) msg);
974 break; 1030 break;
1031#if ENABLE_MALICIOUS
1032 case GNUNET_MESSAGE_TYPE_DHT_CLIENT_ACT_MALICIOUS_OK:
1033 if(msize != sizeof (struct GNUNET_DHT_ClientActMaliciousConfirmationMessage))
1034 {
1035 GNUNET_break (0);
1036 break;
1037 }
1038 ret = process_act_malicious_confirmation_message (handle,
1039 (const struct GNUNET_DHT_ClientActMaliciousConfirmationMessage*) msg);
1040 break;
1041#endif
975 default: 1042 default:
976 GNUNET_break(0); 1043 GNUNET_break(0);
977 LOG (GNUNET_ERROR_TYPE_WARNING, 1044 LOG (GNUNET_ERROR_TYPE_WARNING,
@@ -1151,7 +1218,6 @@ GNUNET_DHT_put (struct GNUNET_DHT_Handle *handle,
1151 struct PendingMessage *pending; 1218 struct PendingMessage *pending;
1152 struct GNUNET_DHT_PutHandle *ph; 1219 struct GNUNET_DHT_PutHandle *ph;
1153 1220
1154
1155 msize = sizeof (struct GNUNET_DHT_ClientPutMessage) + size; 1221 msize = sizeof (struct GNUNET_DHT_ClientPutMessage) + size;
1156 if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) || 1222 if ((msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) ||
1157 (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE)) 1223 (size >= GNUNET_SERVER_MAX_MESSAGE_SIZE))
@@ -1499,16 +1565,21 @@ GNUNET_DHT_monitor_stop (struct GNUNET_DHT_MonitorHandle *handle)
1499 1565
1500#if ENABLE_MALICIOUS 1566#if ENABLE_MALICIOUS
1501/** 1567/**
1502 * Turn the DHT service to act malicious depending on @a flag 1568 * Turn the DHT service to act malicious.
1503 * 1569 *
1504 * @param handle the DHT handle 1570 * @param handle the DHT handle
1505 * @param action 1 to make the service malicious; 0 to make it benign 1571 * @param action 1 to make the service malicious; 0 to make it benign
1506 FIXME: perhaps make this an enum of known malicious behaviors? 1572 * @param cont continuation to call when done (transmitting request to service)
1573 * @param cont_cls closure for @a cont
1507 */ 1574 */
1508void 1575struct GNUNET_DHT_ActMaliciousHandle *
1509GNUNET_DHT_malicious (struct GNUNET_DHT_Handle *handle, unsigned int action) 1576GNUNET_DHT_act_malicious (struct GNUNET_DHT_Handle *handle,
1577 unsigned int action,
1578 GNUNET_DHT_PutContinuation cont,
1579 void *cont_cls)
1510{ 1580{
1511 struct GNUNET_DHT_ActMaliciousMessage *amm; 1581 struct GNUNET_DHT_ActMaliciousMessage *amm;
1582 struct GNUNET_DHT_ActMaliciousHandle *mh;
1512 struct PendingMessage *pending; 1583 struct PendingMessage *pending;
1513 size_t msize; 1584 size_t msize;
1514 1585
@@ -1516,9 +1587,12 @@ GNUNET_DHT_malicious (struct GNUNET_DHT_Handle *handle, unsigned int action)
1516 if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE) 1587 if (msize >= GNUNET_SERVER_MAX_MESSAGE_SIZE)
1517 { 1588 {
1518 GNUNET_break(0); 1589 GNUNET_break(0);
1519 return; 1590 return NULL;
1520 } 1591 }
1521 1592 mh = GNUNET_new (struct GNUNET_DHT_ActMaliciousHandle);
1593 mh->dht_handle = handle;
1594 mh->cont = cont;
1595 mh->cont_cls = cont_cls;
1522 pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize); 1596 pending = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
1523 amm = (struct GNUNET_DHT_ActMaliciousMessage *)&pending[1]; 1597 amm = (struct GNUNET_DHT_ActMaliciousMessage *)&pending[1];
1524 pending->msg = &amm->header; 1598 pending->msg = &amm->header;
@@ -1527,11 +1601,12 @@ GNUNET_DHT_malicious (struct GNUNET_DHT_Handle *handle, unsigned int action)
1527 amm->header.size = htons (msize); 1601 amm->header.size = htons (msize);
1528 amm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_ACT_MALICIOUS); 1602 amm->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_ACT_MALICIOUS);
1529 amm->action = action; 1603 amm->action = action;
1530 1604 handle->mh = mh;
1531 GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail, 1605 GNUNET_CONTAINER_DLL_insert (handle->pending_head, handle->pending_tail,
1532 pending); 1606 pending);
1533 pending->in_pending_queue = GNUNET_YES; 1607 pending->in_pending_queue = GNUNET_YES;
1534 process_pending_messages (handle); 1608 process_pending_messages (handle);
1609 return mh;
1535} 1610}
1536#endif 1611#endif
1537 1612
diff --git a/src/dht/gnunet-service-xdht_clients.c b/src/dht/gnunet-service-xdht_clients.c
index e5513f6a9..3ddb62be1 100644
--- a/src/dht/gnunet-service-xdht_clients.c
+++ b/src/dht/gnunet-service-xdht_clients.c
@@ -46,13 +46,6 @@
46#define DEBUG(...) \ 46#define DEBUG(...) \
47 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) 47 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
48 48
49#if ENABLE_MALICIOUS
50/**
51 * Should this peer act malicious?
52 */
53extern unsigned int malicious;
54#endif
55
56/** 49/**
57 * Linked list of messages to send to clients. 50 * Linked list of messages to send to clients.
58 */ 51 */
@@ -1298,7 +1291,7 @@ handle_dht_local_monitor_stop (void *cls, struct GNUNET_SERVER_Client *client,
1298 1291
1299#if ENABLE_MALICIOUS 1292#if ENABLE_MALICIOUS
1300/** 1293/**
1301 * Handler for act malicous message. 1294 * Handler for act malicious message.
1302 * 1295 *
1303 * @param cls closure for the service 1296 * @param cls closure for the service
1304 * @param client the client we received this message from 1297 * @param client the client we received this message from
@@ -1310,11 +1303,24 @@ handle_dht_act_malicious (void *cls, struct GNUNET_SERVER_Client *client,
1310 const struct GNUNET_MessageHeader *message) 1303 const struct GNUNET_MessageHeader *message)
1311{ 1304{
1312 const struct GNUNET_DHT_ActMaliciousMessage *msg; 1305 const struct GNUNET_DHT_ActMaliciousMessage *msg;
1313 unsigned int malicious; 1306 struct PendingMessage *pm;
1314 1307 struct GNUNET_DHT_ClientActMaliciousConfirmationMessage *conf;
1308 unsigned int malicious_action;
1309
1315 msg = (const struct GNUNET_DHT_ActMaliciousMessage *)message; 1310 msg = (const struct GNUNET_DHT_ActMaliciousMessage *)message;
1316 malicious = msg->action; 1311 malicious_action = msg->action;
1317 GDS_NEIGHBOURS_act_malicious(malicious); 1312
1313 if(GNUNET_OK == GDS_NEIGHBOURS_act_malicious (malicious_action))
1314 {
1315 pm = GNUNET_malloc (sizeof (struct PendingMessage) +
1316 sizeof (struct GNUNET_DHT_ClientActMaliciousConfirmationMessage));
1317 conf = (struct GNUNET_DHT_ClientActMaliciousConfirmationMessage *) &pm[1];
1318 conf->header.size = htons (sizeof (struct GNUNET_DHT_ClientActMaliciousConfirmationMessage));
1319 conf->header.type = htons (GNUNET_MESSAGE_TYPE_DHT_CLIENT_ACT_MALICIOUS_OK);
1320 pm->msg = &conf->header;
1321 add_pending_message (find_active_client (client), pm);
1322 GNUNET_SERVER_receive_done (client, GNUNET_OK);
1323 }
1318} 1324}
1319#endif 1325#endif
1320 1326
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c
index 912d31fc4..b36f7c657 100644
--- a/src/dht/gnunet-service-xdht_neighbours.c
+++ b/src/dht/gnunet-service-xdht_neighbours.c
@@ -111,7 +111,7 @@
111/** 111/**
112 * Maximum number of trails stored per finger. 112 * Maximum number of trails stored per finger.
113 */ 113 */
114#define MAXIMUM_TRAILS_PER_FINGER 2 114#define MAXIMUM_TRAILS_PER_FINGER 4
115 115
116/** 116/**
117 * Finger map index for predecessor entry in finger table. 117 * Finger map index for predecessor entry in finger table.
@@ -1066,10 +1066,11 @@ process_friend_queue (struct FriendInfo *peer)
1066 * Set the ENABLE_MALICIOUS value to malicious. 1066 * Set the ENABLE_MALICIOUS value to malicious.
1067 * @param malicious 1067 * @param malicious
1068 */ 1068 */
1069void 1069int
1070GDS_NEIGHBOURS_act_malicious (unsigned int malicious) 1070GDS_NEIGHBOURS_act_malicious (unsigned int malicious)
1071{ 1071{
1072 act_malicious = malicious; 1072 act_malicious = malicious;
1073 return GNUNET_OK;
1073} 1074}
1074#endif 1075#endif
1075 1076
@@ -2149,9 +2150,8 @@ find_local_best_known_next_hop (uint64_t destination_finger_value,
2149 return current_closest_peer; 2150 return current_closest_peer;
2150} 2151}
2151 2152
2153
2152/** 2154/**
2153 * FIXME; Send put message across all the trail to reach to next hop to handle
2154 * malicious peers.
2155 * Construct a Put message and send it to target_peer. 2155 * Construct a Put message and send it to target_peer.
2156 * @param key Key for the content 2156 * @param key Key for the content
2157 * @param block_type Type of the block 2157 * @param block_type Type of the block
@@ -2267,7 +2267,6 @@ GDS_NEIGHBOURS_handle_put (const struct GNUNET_HashCode *key,
2267 next_hop = successor.next_hop; 2267 next_hop = successor.next_hop;
2268 intermediate_trail_id = successor.trail_id; 2268 intermediate_trail_id = successor.trail_id;
2269 2269
2270 DEBUG("PUT_REQUEST_RECEVIED KEY = %s \n",GNUNET_h2s(key));
2271 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&best_known_dest, &my_identity)) 2270 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&best_known_dest, &my_identity))
2272 { 2271 {
2273 /* I am the destination. */ 2272 /* I am the destination. */
@@ -2279,10 +2278,10 @@ GDS_NEIGHBOURS_handle_put (const struct GNUNET_HashCode *key,
2279 key, data, data_size); 2278 key, data, data_size);
2280 return; 2279 return;
2281 } 2280 }
2282 2281 DEBUG("\n PUT_REQUEST_RECEVIED for key = %s, act_malicious = %d",GNUNET_h2s(key),act_malicious);
2283 /* In case we are sending the request to a finger, then send across all of its 2282 /* In case we are sending the request to a finger, then send across all of its
2284 trail.*/ 2283 trail.*/
2285#if 0 2284#if ENABLE_MALICIOUS
2286 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&successor.best_known_destination, 2285 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&successor.best_known_destination,
2287 &successor.next_hop)) 2286 &successor.next_hop))
2288 { 2287 {
@@ -2294,26 +2293,40 @@ GDS_NEIGHBOURS_handle_put (const struct GNUNET_HashCode *key,
2294 { 2293 {
2295 if (GNUNET_YES == next_hop_finger->trail_list[i].is_present) 2294 if (GNUNET_YES == next_hop_finger->trail_list[i].is_present)
2296 { 2295 {
2296 if(0 == next_hop_finger->trail_list[i].trail_length)
2297 {
2298 DEBUG("\n PUT_REQUEST = %s TRAIL LENGTH = 0 NOT SENDING ACROSS MULTIPLE TRAILS,next_hop = %s", GNUNET_h2s(key),
2299 GNUNET_i2s(&next_hop));
2300 GDS_NEIGHBOURS_send_put (key, block_type, options, desired_replication_level,
2301 best_known_dest, intermediate_trail_id, &next_hop,
2302 0, 1, &my_identity, expiration_time,
2303 data, data_size);
2304 return;
2305 }
2306 next_hop = next_hop_finger->trail_list[i].trail_head->peer;
2307 DEBUG("\n PUT_REQUEST = %s SENDING ACROSS TRAIL_ID = %s, next_hop = %s",
2308 GNUNET_h2s(key),GNUNET_h2s(&next_hop_finger->trail_list[i].trail_id),
2309 GNUNET_i2s(&next_hop));
2297 GDS_NEIGHBOURS_send_put (key, block_type, options, desired_replication_level, 2310 GDS_NEIGHBOURS_send_put (key, block_type, options, desired_replication_level,
2298 best_known_dest, 2311 best_known_dest,
2299 next_hop_finger->trail_list[i].trail_id, 2312 next_hop_finger->trail_list[i].trail_id,
2300 &next_hop, hop_count, put_path_length, put_path, 2313 &next_hop, 0, 1, &my_identity,
2301 expiration_time, 2314 expiration_time,
2302 data, data_size); 2315 data, data_size);
2303 } 2316 }
2304 } 2317 }
2318 return;
2305 } 2319 }
2306 else
2307#endif 2320#endif
2308 GDS_NEIGHBOURS_send_put (key, block_type, options, desired_replication_level, 2321 DEBUG("\n PUT_REQUEST = %s NOT SENDING ACROSS MULTIPLE TRAILS next_hop = %s",
2309 best_known_dest, intermediate_trail_id, &next_hop, 2322 GNUNET_h2s(key), GNUNET_i2s(&next_hop));
2310 0, 1, &my_identity, expiration_time, 2323 GDS_NEIGHBOURS_send_put (key, block_type, options, desired_replication_level,
2311 data, data_size); 2324 best_known_dest, intermediate_trail_id, &next_hop,
2325 0, 1, &my_identity, expiration_time,
2326 data, data_size);
2312} 2327}
2313 2328
2314/** 2329/**
2315 * FIXME; Send get message across all the trail to reach to next hop to handle
2316 * malicious peers.
2317 * Construct a Get message and send it to target_peer. 2330 * Construct a Get message and send it to target_peer.
2318 * @param key Key for the content 2331 * @param key Key for the content
2319 * @param block_type Type of the block 2332 * @param block_type Type of the block
@@ -2400,6 +2413,7 @@ GDS_NEIGHBOURS_handle_get(const struct GNUNET_HashCode *key,
2400 struct Closest_Peer successor; 2413 struct Closest_Peer successor;
2401 struct GNUNET_PeerIdentity best_known_dest; 2414 struct GNUNET_PeerIdentity best_known_dest;
2402 struct GNUNET_HashCode intermediate_trail_id; 2415 struct GNUNET_HashCode intermediate_trail_id;
2416 struct GNUNET_PeerIdentity next_hop;
2403 uint64_t key_value; 2417 uint64_t key_value;
2404 2418
2405 memcpy (&key_value, key, sizeof (uint64_t)); 2419 memcpy (&key_value, key, sizeof (uint64_t));
@@ -2410,8 +2424,7 @@ GDS_NEIGHBOURS_handle_get(const struct GNUNET_HashCode *key,
2410 2424
2411 best_known_dest = successor.best_known_destination; 2425 best_known_dest = successor.best_known_destination;
2412 intermediate_trail_id = successor.trail_id; 2426 intermediate_trail_id = successor.trail_id;
2413 2427
2414 DEBUG("GET_REQUEST_RECEVIED KEY = %s \n",GNUNET_h2s(key));
2415 /* I am the destination. I have the data. */ 2428 /* I am the destination. I have the data. */
2416 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, 2429 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity,
2417 &best_known_dest)) 2430 &best_known_dest))
@@ -2421,9 +2434,37 @@ GDS_NEIGHBOURS_handle_get(const struct GNUNET_HashCode *key,
2421 return; 2434 return;
2422 } 2435 }
2423 2436
2424 /* fixme; for multiple trails, we need to send back finger index and send trail 2437#if ENABLE_MALICIOUS
2425 across all the fingers. but in current implementation we don't have this case. 2438 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&successor.best_known_destination,
2426 compare finger and current_successor returns, */ 2439 &successor.next_hop))
2440 {
2441 struct FingerInfo *next_hop_finger;
2442 unsigned int i;
2443
2444 next_hop_finger = &finger_table[successor.finger_table_index];
2445 for (i = 0; i < next_hop_finger->trails_count; i++)
2446 {
2447 if (GNUNET_YES == next_hop_finger->trail_list[i].is_present)
2448 {
2449 if(0 == next_hop_finger->trail_list[i].trail_length)
2450 {
2451 GDS_NEIGHBOURS_send_get (key, block_type, options,
2452 desired_replication_level,
2453 best_known_dest,intermediate_trail_id,
2454 &successor.next_hop,
2455 0, 1, &my_identity);
2456 return;
2457 }
2458 next_hop = next_hop_finger->trail_list[i].trail_head->peer;
2459 GDS_NEIGHBOURS_send_get (key, block_type, options, desired_replication_level,
2460 best_known_dest,
2461 next_hop_finger->trail_list[i].trail_id,
2462 &next_hop, 0, 1, &my_identity);
2463 }
2464 }
2465 return;
2466 }
2467#endif
2427 GDS_NEIGHBOURS_send_get (key, block_type, options, desired_replication_level, 2468 GDS_NEIGHBOURS_send_get (key, block_type, options, desired_replication_level,
2428 best_known_dest,intermediate_trail_id, &successor.next_hop, 2469 best_known_dest,intermediate_trail_id, &successor.next_hop,
2429 0, 1, &my_identity); 2470 0, 1, &my_identity);
@@ -3479,9 +3520,7 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3479 struct GNUNET_PeerIdentity closest_peer; 3520 struct GNUNET_PeerIdentity closest_peer;
3480 struct FingerInfo *successor; 3521 struct FingerInfo *successor;
3481 unsigned int finger_table_index; 3522 unsigned int finger_table_index;
3482 struct GNUNET_PeerIdentity *updated_trail; 3523
3483 int updated_finger_trail_length;
3484
3485 /* Get the finger_table_index corresponding to finger_value we got from network.*/ 3524 /* Get the finger_table_index corresponding to finger_value we got from network.*/
3486 finger_table_index = get_finger_table_index (finger_value, is_predecessor); 3525 finger_table_index = get_finger_table_index (finger_value, is_predecessor);
3487 3526
@@ -3592,8 +3631,8 @@ finger_table_add (struct GNUNET_PeerIdentity finger_identity,
3592 add_new_trail (existing_finger, finger_trail, 3631 add_new_trail (existing_finger, finger_trail,
3593 finger_trail_length, finger_trail_id); 3632 finger_trail_length, finger_trail_id);
3594 else 3633 else
3595 select_and_replace_trail (existing_finger, updated_trail, 3634 select_and_replace_trail (existing_finger, finger_trail,
3596 updated_finger_trail_length, finger_trail_id); 3635 finger_trail_length, finger_trail_id);
3597 } 3636 }
3598 update_current_search_finger_index (finger_table_index); 3637 update_current_search_finger_index (finger_table_index);
3599 return; 3638 return;
@@ -3631,14 +3670,6 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
3631 size_t payload_size; 3670 size_t payload_size;
3632 uint64_t key_value; 3671 uint64_t key_value;
3633 3672
3634#if ENABLE_MALICIOUS
3635 if(1 == act_malicious)
3636 {
3637 DEBUG("I am malicious,dropping put request. \n");
3638 return GNUNET_OK;
3639 }
3640#endif
3641
3642 msize = ntohs (message->size); 3673 msize = ntohs (message->size);
3643 if (msize < sizeof (struct PeerPutMessage)) 3674 if (msize < sizeof (struct PeerPutMessage))
3644 { 3675 {
@@ -3657,7 +3688,14 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
3657 GNUNET_break_op (0); 3688 GNUNET_break_op (0);
3658 return GNUNET_OK; 3689 return GNUNET_OK;
3659 } 3690 }
3660 3691 DEBUG("\n PUT_REQUEST_RECEVIED for key = %s, my_id = %s",GNUNET_h2s(&put->key),GNUNET_i2s(&my_identity));
3692#if ENABLE_MALICIOUS
3693 if(1 == act_malicious)
3694 {
3695 DEBUG("\n I AM MALICIOUS PUT_REQUEST_RECEVIED for key = %s, my_id = %s",GNUNET_h2s(&put->key),GNUNET_i2s(&my_identity));
3696 return GNUNET_OK;
3697 }
3698#endif
3661 GNUNET_STATISTICS_update (GDS_stats, 3699 GNUNET_STATISTICS_update (GDS_stats,
3662 gettext_noop 3700 gettext_noop
3663 ("# Bytes received from other peers"), (int64_t) msize, 3701 ("# Bytes received from other peers"), (int64_t) msize,
@@ -3784,13 +3822,56 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
3784 } 3822 }
3785 else 3823 else
3786 { 3824 {
3787 GDS_NEIGHBOURS_send_put (&put->key, 3825#if ENABLE_MALICIOUS
3788 ntohl (put->block_type),ntohl (put->options), 3826 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&successor.best_known_destination,
3789 ntohl (put->desired_replication_level), 3827 &successor.next_hop))
3790 best_known_dest, intermediate_trail_id, next_hop, 3828 {
3791 hop_count, putlen, pp, 3829 struct FingerInfo *next_hop_finger;
3792 GNUNET_TIME_absolute_ntoh (put->expiration_time), 3830 unsigned int i;
3793 payload, payload_size); 3831
3832 next_hop_finger = &finger_table[successor.finger_table_index];
3833 for (i = 0; i < next_hop_finger->trails_count; i++)
3834 {
3835 if (GNUNET_YES == next_hop_finger->trail_list[i].is_present)
3836 {
3837 if(0 == next_hop_finger->trail_list[i].trail_length)
3838 {
3839 DEBUG("\n PUT_REQUEST_RECEVIED for key = %s, next_hop = %s,TRAIL LENGTH IS 0",GNUNET_h2s(&put->key),GNUNET_i2s(next_hop));
3840 GDS_NEIGHBOURS_send_put (&put->key,
3841 ntohl (put->block_type),ntohl (put->options),
3842 ntohl (put->desired_replication_level),
3843 best_known_dest, intermediate_trail_id, next_hop,
3844 hop_count, putlen, pp,
3845 GNUNET_TIME_absolute_ntoh (put->expiration_time),
3846 payload, payload_size);
3847 return GNUNET_OK;
3848 }
3849 next_hop = &next_hop_finger->trail_list[i].trail_head->peer;
3850 DEBUG("\n PUT_REQUEST = %s SENDING ACROSS TRAIL_ID = %s, next_hop = %s",
3851 GNUNET_h2s(&put->key),GNUNET_h2s(&next_hop_finger->trail_list[i].trail_id),
3852 GNUNET_i2s(next_hop));
3853 GDS_NEIGHBOURS_send_put (&put->key,
3854 ntohl (put->block_type),ntohl (put->options),
3855 ntohl (put->desired_replication_level),
3856 best_known_dest,
3857 next_hop_finger->trail_list[i].trail_id,
3858 next_hop, hop_count, putlen, pp,
3859 GNUNET_TIME_absolute_ntoh (put->expiration_time),
3860 payload, payload_size);
3861 }
3862 }
3863 return GNUNET_OK;
3864 }
3865#endif
3866 DEBUG("\n PUT_REQUEST = %s NOT SENDING ACROSS MULTIPLE TRAILS next_hop = %s",
3867 GNUNET_h2s(&put->key), GNUNET_i2s(next_hop));
3868 GDS_NEIGHBOURS_send_put (&put->key,
3869 ntohl (put->block_type),ntohl (put->options),
3870 ntohl (put->desired_replication_level),
3871 best_known_dest, intermediate_trail_id, next_hop,
3872 hop_count, putlen, pp,
3873 GNUNET_TIME_absolute_ntoh (put->expiration_time),
3874 payload, payload_size);
3794 } 3875 }
3795 return GNUNET_OK; 3876 return GNUNET_OK;
3796} 3877}
@@ -3824,14 +3905,6 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
3824 uint64_t key_value; 3905 uint64_t key_value;
3825 uint32_t hop_count; 3906 uint32_t hop_count;
3826 size_t msize; 3907 size_t msize;
3827
3828#if ENABLE_MALICIOUS
3829 if(1 == act_malicious)
3830 {
3831 DEBUG("I am malicious,dropping get request. \n");
3832 return GNUNET_OK;
3833 }
3834#endif
3835 3908
3836 msize = ntohs (message->size); 3909 msize = ntohs (message->size);
3837 if (msize < sizeof (struct PeerGetMessage)) 3910 if (msize < sizeof (struct PeerGetMessage))
@@ -3842,12 +3915,6 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
3842 3915
3843 get = (const struct PeerGetMessage *)message; 3916 get = (const struct PeerGetMessage *)message;
3844 get_length = ntohl (get->get_path_length); 3917 get_length = ntohl (get->get_path_length);
3845 current_best_known_dest = get->best_known_destination;
3846 received_intermediate_trail_id = get->intermediate_trail_id;
3847 get_path = (const struct GNUNET_PeerIdentity *)&get[1];
3848 hop_count = get->hop_count;
3849 hop_count++;
3850
3851 if ((msize < 3918 if ((msize <
3852 sizeof (struct PeerGetMessage) + 3919 sizeof (struct PeerGetMessage) +
3853 get_length * sizeof (struct GNUNET_PeerIdentity)) || 3920 get_length * sizeof (struct GNUNET_PeerIdentity)) ||
@@ -3858,6 +3925,20 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
3858 return GNUNET_YES; 3925 return GNUNET_YES;
3859 } 3926 }
3860 3927
3928#if ENABLE_MALICIOUS
3929 if(1 == act_malicious)
3930 {
3931 DEBUG("I am malicious,dropping get request. \n");
3932 return GNUNET_OK;
3933 }
3934#endif
3935 current_best_known_dest = get->best_known_destination;
3936 received_intermediate_trail_id = get->intermediate_trail_id;
3937 get_path = (const struct GNUNET_PeerIdentity *)&get[1];
3938 hop_count = get->hop_count;
3939 hop_count++;
3940
3941
3861 GNUNET_STATISTICS_update (GDS_stats, 3942 GNUNET_STATISTICS_update (GDS_stats,
3862 gettext_noop 3943 gettext_noop
3863 ("# Bytes received from other peers"), msize, 3944 ("# Bytes received from other peers"), msize,
@@ -3906,7 +3987,6 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
3906 } 3987 }
3907 } 3988 }
3908 3989
3909
3910 /* I am the final destination. */ 3990 /* I am the final destination. */
3911 if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &best_known_dest)) 3991 if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &best_known_dest))
3912 { 3992 {
@@ -3924,6 +4004,38 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
3924 } 4004 }
3925 else 4005 else
3926 { 4006 {
4007
4008#if ENABLE_MALICIOUS
4009 if (0 != GNUNET_CRYPTO_cmp_peer_identity (&successor.best_known_destination,
4010 &successor.next_hop))
4011 {
4012 struct FingerInfo *next_hop_finger;
4013 unsigned int i;
4014
4015 next_hop_finger = &finger_table[successor.finger_table_index];
4016 for (i = 0; i < next_hop_finger->trails_count; i++)
4017 {
4018 if(0 == next_hop_finger->trail_list[i].trail_length)
4019 {
4020 GDS_NEIGHBOURS_send_get (&(get->key), get->block_type, get->options,
4021 get->desired_replication_level, best_known_dest,
4022 intermediate_trail_id, next_hop, hop_count,
4023 get_length, gp);
4024 return GNUNET_OK;
4025 }
4026 if (GNUNET_YES == next_hop_finger->trail_list[i].is_present)
4027 {
4028 next_hop = &next_hop_finger->trail_list[i].trail_head->peer;
4029 GDS_NEIGHBOURS_send_get (&(get->key), get->block_type, get->options,
4030 get->desired_replication_level, best_known_dest,
4031 next_hop_finger->trail_list[i].trail_id,
4032 next_hop, hop_count,
4033 get_length, gp);
4034 }
4035 }
4036 return GNUNET_OK;
4037 }
4038#endif
3927 GDS_NEIGHBOURS_send_get (&(get->key), get->block_type, get->options, 4039 GDS_NEIGHBOURS_send_get (&(get->key), get->block_type, get->options,
3928 get->desired_replication_level, best_known_dest, 4040 get->desired_replication_level, best_known_dest,
3929 intermediate_trail_id, next_hop, hop_count, 4041 intermediate_trail_id, next_hop, hop_count,
@@ -4926,7 +5038,6 @@ check_trail_me_to_probable_succ (struct GNUNET_PeerIdentity probable_successor,
4926 struct GNUNET_PeerIdentity *trail_to_new_successor; 5038 struct GNUNET_PeerIdentity *trail_to_new_successor;
4927 5039
4928 /* Probable successor is a friend */ 5040 /* Probable successor is a friend */
4929 /* SUPUS: Here should I worry about friend,*/
4930 if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap, 5041 if (NULL != GNUNET_CONTAINER_multipeermap_get (friend_peermap,
4931 &probable_successor)) 5042 &probable_successor))
4932 { 5043 {
@@ -5053,7 +5164,7 @@ compare_and_update_successor (struct GNUNET_PeerIdentity curr_succ,
5053 char *my_id_str; 5164 char *my_id_str;
5054 uint64_t succ; 5165 uint64_t succ;
5055 char *key; 5166 char *key;
5056 5167
5057 my_id_str = GNUNET_strdup (GNUNET_i2s_full (&my_identity)); 5168 my_id_str = GNUNET_strdup (GNUNET_i2s_full (&my_identity));
5058 memcpy(&succ, &current_successor->finger_identity, sizeof(uint64_t)); 5169 memcpy(&succ, &current_successor->finger_identity, sizeof(uint64_t));
5059 GNUNET_asprintf (&key, "XDHT:%s:", my_id_str); 5170 GNUNET_asprintf (&key, "XDHT:%s:", my_id_str);
diff --git a/src/dht/gnunet-service-xdht_neighbours.h b/src/dht/gnunet-service-xdht_neighbours.h
index 57ed68434..66295702d 100644
--- a/src/dht/gnunet-service-xdht_neighbours.h
+++ b/src/dht/gnunet-service-xdht_neighbours.h
@@ -37,7 +37,7 @@
37 * Set the ENABLE_MALICIOUS value to malicious. 37 * Set the ENABLE_MALICIOUS value to malicious.
38 * @param malicious 38 * @param malicious
39 */ 39 */
40void 40int
41GDS_NEIGHBOURS_act_malicious (unsigned int malicious); 41GDS_NEIGHBOURS_act_malicious (unsigned int malicious);
42#endif 42#endif
43 43
diff --git a/src/dht/gnunet_dht_profiler.c b/src/dht/gnunet_dht_profiler.c
index 5fa4a105d..592e31bfe 100644
--- a/src/dht/gnunet_dht_profiler.c
+++ b/src/dht/gnunet_dht_profiler.c
@@ -38,21 +38,20 @@
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 20 41#define PUT_PROBABILITY 50
42 42
43#if ENABLE_MALICIOUS 43#if ENABLE_MALICIOUS
44/** 44/**
45 * Number of peers which should act as malicious peers 45 * Number of peers which should act as malicious peers
46 */ 46 */
47#define MALICIOUS_PROBABILITY 50 47#define MALICIOUS_PROBABILITY 20
48 48
49#endif
50/** 49/**
51 * Percentage of peers that should act maliciously. 50 * Context for a peer which should act maliciously.
52 * These peers will never start PUT/GET request.
53 * n_active and n_malicious should not intersect.
54 */ 51 */
55#define MALICIOUS_PEERS 0 52struct MaliciousContext;
53#endif
54
56 55
57/** 56/**
58 * Configuration 57 * Configuration
@@ -70,16 +69,10 @@ static char *hosts_file;
70struct ActiveContext; 69struct ActiveContext;
71 70
72/** 71/**
73 * Context for a peer which should act maliciously.
74 */
75struct MaliciousContext;
76
77/**
78 * Context to hold data of peer 72 * Context to hold data of peer
79 */ 73 */
80struct Context 74struct Context
81{ 75{
82
83 /** 76 /**
84 * The testbed peer this context belongs to 77 * The testbed peer this context belongs to
85 */ 78 */
@@ -119,6 +112,11 @@ struct MaliciousContext
119 * Handler to the DHT service 112 * Handler to the DHT service
120 */ 113 */
121 struct GNUNET_DHT_Handle *dht; 114 struct GNUNET_DHT_Handle *dht;
115
116 /**
117 * Handler to malicious api
118 */
119 struct GNUNET_DHT_ActMaliciousHandle *dht_malicious;
122}; 120};
123 121
124/** 122/**
@@ -126,6 +124,32 @@ struct MaliciousContext
126 */ 124 */
127struct Context **malicious_peer_contexts = NULL; 125struct Context **malicious_peer_contexts = NULL;
128 126
127/**
128 * Context for a peer which should act maliciously.
129 */
130struct Malicious_Context
131{
132 /**
133 * The linked peer context
134 */
135 struct Context *ctx;
136
137 /**
138 * Handler to the DHT service
139 */
140 struct GNUNET_DHT_Handle *dht;
141};
142
143/**
144 * Array of malicious peers.
145 */
146static struct MaliciousContext *a_mc;
147
148/**
149 * Number or malicious peers.
150 */
151static unsigned int n_malicious;
152
129#endif 153#endif
130 154
131/** 155/**
@@ -182,27 +206,8 @@ struct ActiveContext
182 * The number of peers currently doing GET on our data 206 * The number of peers currently doing GET on our data
183 */ 207 */
184 uint16_t nrefs; 208 uint16_t nrefs;
185
186 /**
187 * If set this peer will act maliciously.
188 */
189 unsigned int malicious;
190}; 209};
191 210
192#if ENABLE_MALICIOUS
193struct Malicious_Context
194{
195 /**
196 * The linked peer context
197 */
198 struct Context *ctx;
199
200 /**
201 * Handler to the DHT service
202 */
203 struct GNUNET_DHT_Handle *dht;
204};
205#endif
206 211
207/** 212/**
208 * An array of contexts. The size of this array should be equal to @a num_peers 213 * An array of contexts. The size of this array should be equal to @a num_peers
@@ -214,13 +219,6 @@ static struct Context *a_ctx;
214 */ 219 */
215static struct ActiveContext *a_ac; 220static struct ActiveContext *a_ac;
216 221
217#if ENABLE_MALICIOUS
218/**
219 * Array of malicious peers.
220 */
221static struct MaliciousContext *a_mc;
222#endif
223
224/** 222/**
225 * The delay between rounds for collecting statistics 223 * The delay between rounds for collecting statistics
226 */ 224 */
@@ -246,13 +244,6 @@ static struct GNUNET_TIME_Relative timeout;
246 */ 244 */
247static unsigned int num_peers; 245static unsigned int num_peers;
248 246
249#if ENABLE_MALICIOUS
250/**
251 * Number or malicious peers.
252 */
253static unsigned int n_malicious;
254#endif
255
256/** 247/**
257 * Number of active peers 248 * Number of active peers
258 */ 249 */
@@ -411,6 +402,11 @@ static enum
411static int in_shutdown = 0; 402static int in_shutdown = 0;
412 403
413/** 404/**
405 * Total number of times to check if circle is formed or not.
406 */
407static unsigned int tries;
408
409/**
414 * Task that collects successor statistics from all the peers. 410 * Task that collects successor statistics from all the peers.
415 * @param cls 411 * @param cls
416 * @param tc 412 * @param tc
@@ -419,6 +415,12 @@ static void
419collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); 415collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
420 416
421/** 417/**
418 * Connect to DHT services of active peers
419 */
420static void
421start_profiling();
422
423/**
422 * Shutdown task. Cleanup all resources and operations. 424 * Shutdown task. Cleanup all resources and operations.
423 * 425 *
424 * @param cls NULL 426 * @param cls NULL
@@ -823,18 +825,12 @@ static void *
823dht_connect (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg) 825dht_connect (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
824{ 826{
825 n_dht++; 827 n_dht++;
828 DEBUG("\n Inside dht_connect , n_dht = %u",n_dht);
826 return GNUNET_DHT_connect (cfg, 10); 829 return GNUNET_DHT_connect (cfg, 10);
827} 830}
828 831
829 832
830/** 833/**
831 * Connect to DHT services of active peers
832 */
833static void
834start_profiling();
835
836
837/**
838 * Adapter function called to destroy a connection to 834 * Adapter function called to destroy a connection to
839 * a service. 835 * a service.
840 * 836 *
@@ -872,7 +868,6 @@ dht_disconnect (void *cls, void *op_result)
872 } 868 }
873} 869}
874 870
875
876/** 871/**
877 * Connect to DHT services of active peers 872 * Connect to DHT services of active peers
878 */ 873 */
@@ -881,7 +876,7 @@ start_profiling()
881{ 876{
882 struct Context *ctx; 877 struct Context *ctx;
883 unsigned int i; 878 unsigned int i;
884 879
885 DEBUG("GNUNET_TESTBED_service_connect \n"); 880 DEBUG("GNUNET_TESTBED_service_connect \n");
886 GNUNET_break (GNUNET_YES != in_shutdown); 881 GNUNET_break (GNUNET_YES != in_shutdown);
887 for(i = 0; i < n_active; i++) 882 for(i = 0; i < n_active; i++)
@@ -900,18 +895,157 @@ start_profiling()
900 } 895 }
901} 896}
902 897
898#if ENABLE_MALICIOUS
899/**
900 * Count of total number of malicious peers.
901 */
902static unsigned int count_malicious;
903
904/**
905 * Continuation of GNUNET_DHT_act_malicious
906 * @param cls Malicious context
907 * @param success #GNUNET_OK if the ACT_MALICIOUS was transmitted,
908 * #GNUNET_NO on timeout,
909 * #GNUNET_SYSERR on disconnect from service
910 * after the ACT_MALICIOUS message was transmitted
911 * (so we don't know if it was received or not)
912 */
913static void
914act_malicious_cont (void *cls, int success)
915{
916 struct MaliciousContext *mc = cls;
917 struct Context *ctx = mc->ctx;
918
919 GNUNET_TESTBED_operation_done (ctx->op);
920 ctx->op = NULL;
921 return;
922}
923
924
925/**
926 * Call malicious API for all the malicious peers.
927 * @param cls the malicious context.
928 * @param op the operation that has been finished
929 * @param ca_result the service handle returned from GNUNET_TESTBED_ConnectAdapter()
930 * @param emsg error message in case the operation has failed; will be NULL if
931 * operation has executed successfully.
932 */
933void
934dht_set_malicious(void *cls,
935 struct GNUNET_TESTBED_Operation *op,
936 void *ca_result,
937 const char *emsg)
938{
939 struct MaliciousContext *mc = cls;
940 struct Context *ctx = mc->ctx;
941
942 GNUNET_assert (NULL != ctx);
943 GNUNET_assert (NULL != ctx->op);
944 GNUNET_assert (ctx->op == op);
945 mc->dht = (struct GNUNET_DHT_Handle *) ca_result;
946 if (NULL != emsg)
947 {
948 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Connection to DHT service failed: %s\n", emsg);
949 GNUNET_TESTBED_operation_done (ctx->op); /* Calls dht_disconnect_malicious() */
950 ctx->op = NULL;
951 return;
952 }
953 mc->dht_malicious = GNUNET_DHT_act_malicious(mc->dht, 1, act_malicious_cont, mc);
954}
955
956
957/**
958 * Adapter function called to destroy a connection to
959 * a service.
960 *
961 * @param cls the active context
962 * @param op_result service handle returned from the connect adapter
963 */
964static void
965dht_disconnect_malicious (void *cls, void *op_result)
966{
967 struct MaliciousContext *mc = cls;
968 count_malicious++;
969 GNUNET_assert (NULL != mc->dht);
970 GNUNET_assert (mc->dht == op_result);
971 GNUNET_DHT_disconnect (mc->dht);
972 mc->dht = NULL;
973 mc->ctx->op = NULL;
974 n_dht--;
975
976 if (0 != n_dht)
977 return;
978
979 if(n_malicious == count_malicious)
980 {
981 DEBUG("\n Call start_profiling()");
982 start_profiling();
983 }
984}
985
986
987/**
988 * Set the malicious variable in peer malicious context.
989 */
990static void
991set_malicious()
992{
993 unsigned int i;
994 DEBUG ("Setting %u peers malicious",n_malicious);
995
996 for(i = 0; i < n_malicious; i++)
997 {
998 DEBUG("\n Inside loop , i = %u",i);
999 struct MaliciousContext *mc = &a_mc[i];
1000 mc->ctx->op =
1001 GNUNET_TESTBED_service_connect (mc->ctx,
1002 mc->ctx->peer,
1003 "dht",
1004 &dht_set_malicious, mc,
1005 &dht_connect,
1006 &dht_disconnect_malicious,
1007 mc);
1008 }
1009}
1010
1011#endif
1012
1013
1014/**
1015 * Start collecting relevant statistics. If ENABLE_MALICIOUS set, first
1016 * set the malicious peers. If not, then start with PUT operation on active
1017 * peers.
1018 */
1019static void
1020start_func()
1021{
1022#if ENABLE_MALICIOUS
1023 set_malicious();
1024 return;
1025#endif
1026 start_profiling();
1027}
1028
1029
1030/**
1031 * Remove entry from successor peer hashmap.
1032 * @param cls closure
1033 * @param key current public key
1034 * @param value value in the hash map
1035 * @return #GNUNET_YES if we should continue to iterate,
1036 * #GNUNET_NO if not.
1037 */
903static int 1038static int
904hashmap_iterate_remove(void *cls, 1039hashmap_iterate_remove(void *cls,
905 const struct GNUNET_HashCode *key, 1040 const struct GNUNET_HashCode *key,
906 void *value) 1041 void *value)
907{ 1042{
908 GNUNET_assert(GNUNET_YES == GNUNET_CONTAINER_multihashmap_remove(successor_peer_hashmap, key, value)); 1043 GNUNET_assert (GNUNET_YES ==
1044 GNUNET_CONTAINER_multihashmap_remove(successor_peer_hashmap, key, value));
909 return GNUNET_YES; 1045 return GNUNET_YES;
910} 1046}
911 1047
912 1048
913static unsigned int tries;
914
915/** 1049/**
916 * Stats callback. Iterate over the hashmap and check if all th peers form 1050 * Stats callback. Iterate over the hashmap and check if all th peers form
917 * a virtual ring topology. 1051 * a virtual ring topology.
@@ -931,20 +1065,21 @@ successor_stats_cont (void *cls,
931 struct GNUNET_HashCode *key; 1065 struct GNUNET_HashCode *key;
932 int count; 1066 int count;
933 1067
934
935 /* Don't schedule the task till we are looking for circle here. */ 1068 /* Don't schedule the task till we are looking for circle here. */
936 successor_stats_task = GNUNET_SCHEDULER_NO_TASK; 1069 successor_stats_task = GNUNET_SCHEDULER_NO_TASK;
937 GNUNET_TESTBED_operation_done (successor_stats_op); 1070 GNUNET_TESTBED_operation_done (successor_stats_op);
938 successor_stats_op = NULL; 1071 successor_stats_op = NULL;
939 if (0 == max_searches) 1072 if (0 == max_searches)
940 { 1073 {
941 start_profiling(); 1074 start_func();
942 return; 1075 return;
943 } 1076 }
1077
1078 GNUNET_assert (NULL != start_key);
944 start_val = 1079 start_val =
945 (struct GNUNET_HashCode *) GNUNET_CONTAINER_multihashmap_get(successor_peer_hashmap, 1080 (struct GNUNET_HashCode *) GNUNET_CONTAINER_multihashmap_get(successor_peer_hashmap,
946 start_key); 1081 start_key);
947 1082
948 val = start_val; 1083 val = start_val;
949 for (count = 0; count < num_peers; count++) 1084 for (count = 0; count < num_peers; count++)
950 { 1085 {
@@ -977,16 +1112,13 @@ successor_stats_cont (void *cls,
977 1112
978 successor_peer_hashmap = GNUNET_CONTAINER_multihashmap_create (num_peers, 1113 successor_peer_hashmap = GNUNET_CONTAINER_multihashmap_create (num_peers,
979 GNUNET_NO); 1114 GNUNET_NO);
980 //TODO:Check if comparison is correct.
981 if ((start_val == val) && (count == num_peers)) 1115 if ((start_val == val) && (count == num_peers))
982 { 1116 {
983 DEBUG("CIRCLE COMPLETED after %u tries", tries); 1117 DEBUG("CIRCLE COMPLETED after %u tries", tries);
984 //FIXME: FREE HASHMAP.
985 //FIXME: If circle is done, then check that finger table of all the peers
986 //are fill atleast O(log N) and then start with the experiments.
987 if(GNUNET_SCHEDULER_NO_TASK == successor_stats_task) 1118 if(GNUNET_SCHEDULER_NO_TASK == successor_stats_task)
988 start_profiling(); 1119 {
989 1120 start_func();
1121 }
990 return; 1122 return;
991 } 1123 }
992 else 1124 else
@@ -995,7 +1127,7 @@ successor_stats_cont (void *cls,
995 { 1127 {
996 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
997 "Maximum tries %u exceeded while checking successor TOTAL TRIES %u" 1129 "Maximum tries %u exceeded while checking successor TOTAL TRIES %u"
998 " cirle formation. Exiting\n", 1130 " circle formation. Exiting\n",
999 max_searches,tries); 1131 max_searches,tries);
1000 if (GNUNET_SCHEDULER_NO_TASK != successor_stats_task) 1132 if (GNUNET_SCHEDULER_NO_TASK != successor_stats_task)
1001 { 1133 {
@@ -1003,7 +1135,7 @@ successor_stats_cont (void *cls,
1003 } 1135 }
1004 if(GNUNET_SCHEDULER_NO_TASK == successor_stats_task) 1136 if(GNUNET_SCHEDULER_NO_TASK == successor_stats_task)
1005 { 1137 {
1006 start_profiling(); 1138 start_func();
1007 } 1139 }
1008 1140
1009 return; 1141 return;
@@ -1039,7 +1171,7 @@ successor_stats_iterator (void *cls,
1039 static const char *key_string = "XDHT"; 1171 static const char *key_string = "XDHT";
1040 if (0 == max_searches) 1172 if (0 == max_searches)
1041 return GNUNET_OK; 1173 return GNUNET_OK;
1042 1174
1043 if (0 == strncmp (key_string, name, strlen (key_string))) 1175 if (0 == strncmp (key_string, name, strlen (key_string)))
1044 { 1176 {
1045 char *my_id_str; 1177 char *my_id_str;
@@ -1062,18 +1194,19 @@ successor_stats_iterator (void *cls,
1062 1194
1063 succ_key = GNUNET_new(struct GNUNET_HashCode); 1195 succ_key = GNUNET_new(struct GNUNET_HashCode);
1064 GNUNET_CRYPTO_hash (truncated_successor_str, sizeof(truncated_successor_str),succ_key); 1196 GNUNET_CRYPTO_hash (truncated_successor_str, sizeof(truncated_successor_str),succ_key);
1065 1197
1066 if (0 == flag) 1198 if (0 == flag)
1067 { 1199 {
1200 GNUNET_assert(NULL != my_id_key);
1068 start_key = my_id_key; 1201 start_key = my_id_key;
1202 GNUNET_assert(NULL != start_key);
1069 flag = 1; 1203 flag = 1;
1070 } 1204 }
1071 /* FIXME: GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE do not free the value
1072 which is replaced, need to free it. */
1073 GNUNET_CONTAINER_multihashmap_put (successor_peer_hashmap, 1205 GNUNET_CONTAINER_multihashmap_put (successor_peer_hashmap,
1074 my_id_key, (void *)succ_key, 1206 my_id_key, (void *)succ_key,
1075 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); 1207 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
1076 } 1208 }
1209
1077 return GNUNET_OK; 1210 return GNUNET_OK;
1078} 1211}
1079 1212
@@ -1106,33 +1239,6 @@ collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
1106} 1239}
1107 1240
1108 1241
1109#if ENABLE_MALICIOUS
1110#if 0
1111/**
1112 * Set the malicious variable in peer malicious context.
1113 */
1114static void
1115set_malicious()
1116{
1117 unsigned int i;
1118 DEBUG ("Setting %u peers malicious");
1119 for(i = 0; i < n_malicious; i++)
1120 {
1121 struct MaliciousContext *mc = &a_mc[i];
1122 mc->ctx->op =
1123 GNUNET_TESTBED_service_connect (ac->ctx,
1124 ac->ctx->peer,
1125 "dht",
1126 &dht_set_malicious, mc,
1127 &dht_connect,
1128 &dht_finish,
1129 mc);
1130 }
1131}
1132#endif
1133#endif
1134
1135
1136/** 1242/**
1137 * Callback called when DHT service on the peer is started 1243 * Callback called when DHT service on the peer is started
1138 * 1244 *
@@ -1156,14 +1262,11 @@ service_started (void *cls,
1156 DEBUG("Peers Started = %d; num_peers = %d \n", peers_started, num_peers); 1262 DEBUG("Peers Started = %d; num_peers = %d \n", peers_started, num_peers);
1157 if (GNUNET_SCHEDULER_NO_TASK == successor_stats_task && peers_started == num_peers) 1263 if (GNUNET_SCHEDULER_NO_TASK == successor_stats_task && peers_started == num_peers)
1158 { 1264 {
1159#if ENABLE_MALICIOUS
1160 //set_malicious();
1161#endif
1162
1163 DEBUG("successor_stats_task \n"); 1265 DEBUG("successor_stats_task \n");
1164 struct Collect_Stat_Context *collect_stat_cls = GNUNET_new(struct Collect_Stat_Context); 1266 struct Collect_Stat_Context *collect_stat_cls = GNUNET_new(struct Collect_Stat_Context);
1165 collect_stat_cls->service_connect_ctx = cls; 1267 collect_stat_cls->service_connect_ctx = cls;
1166 collect_stat_cls->op = op; 1268 collect_stat_cls->op = op;
1269
1167 successor_stats_task = GNUNET_SCHEDULER_add_delayed (delay_stats, 1270 successor_stats_task = GNUNET_SCHEDULER_add_delayed (delay_stats,
1168 &collect_stats, 1271 &collect_stats,
1169 collect_stat_cls); 1272 collect_stat_cls);
@@ -1215,7 +1318,7 @@ test_run (void *cls,
1215 1318
1216#if ENABLE_MALICIOUS 1319#if ENABLE_MALICIOUS
1217 1320
1218 if(PUT_PROBABILITY + MALICIOUS_PEERS > 100) 1321 if(PUT_PROBABILITY + MALICIOUS_PROBABILITY > 100)
1219 { 1322 {
1220 DEBUG ("Reduce either number of malicious peer or active peers. "); 1323 DEBUG ("Reduce either number of malicious peer or active peers. ");
1221 GNUNET_SCHEDULER_shutdown (); 1324 GNUNET_SCHEDULER_shutdown ();
@@ -1224,23 +1327,21 @@ test_run (void *cls,
1224 } 1327 }
1225 1328
1226 /* Select the peers which should act maliciously. */ 1329 /* Select the peers which should act maliciously. */
1227 n_malicious = num_peers * MALICIOUS_PEERS / 100; 1330 n_malicious = num_peers * MALICIOUS_PROBABILITY / 100;
1228 1331
1229 /* Select n_malicious peers and ensure that those are not active peers.
1230 keep all malicious peer at one place, and call act malicious for all
1231 those peers. */
1232 a_mc = GNUNET_malloc (n_malicious * sizeof (struct MaliciousContext)); 1332 a_mc = GNUNET_malloc (n_malicious * sizeof (struct MaliciousContext));
1233 malicious_peers = 0; 1333 malicious_peers = 0;
1234 1334
1235 for (cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++) 1335 for (cnt = 0; cnt < num_peers && malicious_peers < n_malicious; cnt++)
1236 { 1336 {
1237 if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100) >= 1337 if (GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100) >=
1238 MALICIOUS_PROBABILITY) 1338 MALICIOUS_PROBABILITY)
1239 continue; 1339 continue;
1240 a_ac[ac_cnt].malicious = 1; 1340 a_ctx[cnt].mc = &a_mc[malicious_peers];
1241 a_mc[ac_cnt].ctx = &a_ctx[cnt]; 1341 a_mc[malicious_peers].ctx = &a_ctx[cnt];
1242 malicious_peers++; 1342 malicious_peers++;
1243 } 1343 }
1344 n_malicious = malicious_peers;
1244 INFO ("Malicious Peers: %u\n",malicious_peers); 1345 INFO ("Malicious Peers: %u\n",malicious_peers);
1245 1346
1246#endif 1347#endif
@@ -1250,7 +1351,7 @@ test_run (void *cls,
1250 for (cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++) 1351 for (cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++)
1251 { 1352 {
1252 if ((GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100) >= 1353 if ((GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 100) >=
1253 PUT_PROBABILITY) || (a_ac[ac_cnt].malicious == 1)) 1354 PUT_PROBABILITY) || (a_ctx[ac_cnt].mc != NULL))
1254 continue; 1355 continue;
1255 1356
1256 a_ctx[cnt].ac = &a_ac[ac_cnt]; 1357 a_ctx[cnt].ac = &a_ac[ac_cnt];