aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSupriti Singh <supritisingh08@gmail.com>2014-08-10 13:47:29 +0000
committerSupriti Singh <supritisingh08@gmail.com>2014-08-10 13:47:29 +0000
commit953138deb1873ae40f0a9b2f698342111c583afb (patch)
treea6d0af008673c3abda8d8383264f855f92f8baa4 /src
parent130bcc21ae7a0dfda053b4a636b551e64226a41d (diff)
downloadgnunet-953138deb1873ae40f0a9b2f698342111c583afb.tar.gz
gnunet-953138deb1873ae40f0a9b2f698342111c583afb.zip
Checking if circle is formed.
Diffstat (limited to 'src')
-rw-r--r--src/dht/gnunet-service-xdht_clients.c6
-rw-r--r--src/dht/gnunet-service-xdht_datacache.c4
-rw-r--r--src/dht/gnunet-service-xdht_neighbours.c55
-rw-r--r--src/dht/gnunet_dht_profiler.c416
4 files changed, 303 insertions, 178 deletions
diff --git a/src/dht/gnunet-service-xdht_clients.c b/src/dht/gnunet-service-xdht_clients.c
index 8d877654a..901b9c321 100644
--- a/src/dht/gnunet-service-xdht_clients.c
+++ b/src/dht/gnunet-service-xdht_clients.c
@@ -43,6 +43,9 @@
43 43
44#define LOG(kind,...) GNUNET_log_from (kind, "dht-clients",__VA_ARGS__) 44#define LOG(kind,...) GNUNET_log_from (kind, "dht-clients",__VA_ARGS__)
45 45
46#define DEBUG(...) \
47 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
48
46#if ENABLE_MALICIOUS 49#if ENABLE_MALICIOUS
47/** 50/**
48 * Should this peer act malicious? 51 * Should this peer act malicious?
@@ -645,6 +648,7 @@ GDS_CLIENTS_handle_reply (struct GNUNET_TIME_Absolute expiration,
645 _("Could not pass reply to client, message too big!\n")); 648 _("Could not pass reply to client, message too big!\n"));
646 return; 649 return;
647 } 650 }
651 DEBUG("reply FOR DATA_SIZE = %lu\n",msize);
648 pm = GNUNET_malloc (msize + sizeof (struct PendingMessage)); 652 pm = GNUNET_malloc (msize + sizeof (struct PendingMessage));
649 reply = (struct GNUNET_DHT_ClientResultMessage *) &pm[1]; 653 reply = (struct GNUNET_DHT_ClientResultMessage *) &pm[1];
650 pm->msg = &reply->header; 654 pm->msg = &reply->header;
@@ -949,7 +953,7 @@ handle_dht_local_put (void *cls, struct GNUNET_SERVER_Client *client,
949 "Handling local PUT of %u-bytes for query %s\n", 953 "Handling local PUT of %u-bytes for query %s\n",
950 size - sizeof (struct GNUNET_DHT_ClientPutMessage), 954 size - sizeof (struct GNUNET_DHT_ClientPutMessage),
951 GNUNET_h2s (&put_msg->key)); 955 GNUNET_h2s (&put_msg->key));
952 956 DEBUG("PUT doing put i = %s\n",GNUNET_h2s(&(put_msg->key)));
953 GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (put_msg->expiration), 957 GDS_CLIENTS_handle_reply (GNUNET_TIME_absolute_ntoh (put_msg->expiration),
954 &put_msg->key, 0, NULL, 0, NULL, 958 &put_msg->key, 0, NULL, 0, NULL,
955 ntohl (put_msg->type), 959 ntohl (put_msg->type),
diff --git a/src/dht/gnunet-service-xdht_datacache.c b/src/dht/gnunet-service-xdht_datacache.c
index a7952cc0c..5f054c730 100644
--- a/src/dht/gnunet-service-xdht_datacache.c
+++ b/src/dht/gnunet-service-xdht_datacache.c
@@ -34,6 +34,8 @@
34 34
35#define LOG(kind,...) GNUNET_log_from (kind, "dht-dtcache",__VA_ARGS__) 35#define LOG(kind,...) GNUNET_log_from (kind, "dht-dtcache",__VA_ARGS__)
36 36
37#define DEBUG(...) \
38 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__)
37 39
38/** 40/**
39 * Handle to the datacache service (for inserting/retrieving data) 41 * Handle to the datacache service (for inserting/retrieving data)
@@ -79,7 +81,7 @@ GDS_DATACACHE_handle_put (struct GNUNET_TIME_Absolute expiration,
79 GNUNET_STATISTICS_update (GDS_stats, 81 GNUNET_STATISTICS_update (GDS_stats,
80 gettext_noop ("# ITEMS stored in datacache"), 1, 82 gettext_noop ("# ITEMS stored in datacache"), 1,
81 GNUNET_NO); 83 GNUNET_NO);
82 84 DEBUG("PUT doing put key = %s\n",GNUNET_h2s((key)));
83 r = GNUNET_DATACACHE_put (datacache, key, data_size, data, type, expiration, 85 r = GNUNET_DATACACHE_put (datacache, key, data_size, data, type, expiration,
84 put_path_length, put_path); 86 put_path_length, put_path);
85 LOG (GNUNET_ERROR_TYPE_DEBUG, 87 LOG (GNUNET_ERROR_TYPE_DEBUG,
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c
index dfd210795..c5a89208f 100644
--- a/src/dht/gnunet-service-xdht_neighbours.c
+++ b/src/dht/gnunet-service-xdht_neighbours.c
@@ -2117,8 +2117,10 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key,
2117 msize = data_size + sizeof (struct PeerPutMessage); 2117 msize = data_size + sizeof (struct PeerPutMessage);
2118 } 2118 }
2119 2119
2120 /* Should it be GNUNET_SERVER_MAX_MESSAGE_SIZE? */
2120 if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) 2121 if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE)
2121 { 2122 {
2123 DEBUG("msize = %lu\n",msize);
2122 GNUNET_break (0); 2124 GNUNET_break (0);
2123 return; 2125 return;
2124 } 2126 }
@@ -2141,6 +2143,7 @@ GDS_NEIGHBOURS_send_put (const struct GNUNET_HashCode *key,
2141 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&best_known_dest, &my_identity)) 2143 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&best_known_dest, &my_identity))
2142 { 2144 {
2143 /* I am the destination. */ 2145 /* I am the destination. */
2146 DEBUG("PUT destination is me = %s,key =%s\n",GNUNET_i2s(&my_identity),GNUNET_h2s(key));
2144 GDS_DATACACHE_handle_put (expiration_time, key, 0, NULL, 2147 GDS_DATACACHE_handle_put (expiration_time, key, 0, NULL,
2145 block_type,data_size,data); 2148 block_type,data_size,data);
2146 return; 2149 return;
@@ -2233,7 +2236,9 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key,
2233 GNUNET_break (0); 2236 GNUNET_break (0);
2234 return; 2237 return;
2235 } 2238 }
2236 2239
2240 DEBUG("GET FOR DATA_SIZE = %lu\n",msize);
2241
2237 /* This is the first time we got request from our own client file. */ 2242 /* This is the first time we got request from our own client file. */
2238 if (NULL == target_peer) 2243 if (NULL == target_peer)
2239 { 2244 {
@@ -2251,6 +2256,7 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key,
2251 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, 2256 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity,
2252 &best_known_dest)) 2257 &best_known_dest))
2253 { 2258 {
2259 DEBUG("GET destination is me = %s,KEY = %s\n",GNUNET_i2s(&my_identity),GNUNET_h2s(key));
2254 GDS_DATACACHE_handle_get (key,block_type, NULL, 0, 2260 GDS_DATACACHE_handle_get (key,block_type, NULL, 0,
2255 NULL, 0, 1, &my_identity, NULL,&my_identity); 2261 NULL, 0, 1, &my_identity, NULL,&my_identity);
2256 2262
@@ -2346,7 +2352,7 @@ GDS_NEIGHBOURS_send_get_result (const struct GNUNET_HashCode *key,
2346 GNUNET_break(0); 2352 GNUNET_break(0);
2347 return; 2353 return;
2348 } 2354 }
2349 2355 DEBUG("GET RESULT FOR DATA_SIZE = %lu\n",msize);
2350 current_path_index = 0; 2356 current_path_index = 0;
2351 if(get_path_length > 0) 2357 if(get_path_length > 0)
2352 { 2358 {
@@ -3107,23 +3113,6 @@ send_verify_successor_message (void *cls,
3107 /* Trail stored at this index. */ 3113 /* Trail stored at this index. */
3108 GNUNET_assert (GNUNET_YES == trail->is_present); 3114 GNUNET_assert (GNUNET_YES == trail->is_present);
3109 3115
3110 /* Code for testing ONLY: Store the successor for path tracking */
3111 if (track_topology && (NULL != GDS_stats))
3112 {
3113 char *my_id_str;
3114 char *succ_id_str;
3115 char *key;
3116
3117 my_id_str = GNUNET_strdup (GNUNET_i2s (&my_identity));
3118 succ_id_str = GNUNET_strdup (GNUNET_i2s
3119 (&successor->finger_identity));
3120 GNUNET_asprintf (&key, "XDHT:%s:%s", my_id_str, succ_id_str);
3121 GNUNET_free (my_id_str);
3122 GNUNET_free (succ_id_str);
3123 GNUNET_STATISTICS_update (GDS_stats, key, 1, 0);
3124 GNUNET_free (key);
3125 }
3126
3127 trail_id = trail->trail_id; 3116 trail_id = trail->trail_id;
3128 trail_length = trail->trail_length; 3117 trail_length = trail->trail_length;
3129 3118
@@ -3524,7 +3513,7 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
3524 GNUNET_break_op (0); 3513 GNUNET_break_op (0);
3525 return GNUNET_OK; 3514 return GNUNET_OK;
3526 } 3515 }
3527 3516 DEBUG("GET FOR DATA_SIZE = %lu\n",msize);
3528 GNUNET_STATISTICS_update (GDS_stats, 3517 GNUNET_STATISTICS_update (GDS_stats,
3529 gettext_noop 3518 gettext_noop
3530 ("# Bytes received from other peers"), (int64_t) msize, 3519 ("# Bytes received from other peers"), (int64_t) msize,
@@ -3636,6 +3625,7 @@ handle_dht_p2p_put (void *cls, const struct GNUNET_PeerIdentity *peer,
3636 /* I am the final destination */ 3625 /* I am the final destination */
3637 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &best_known_dest)) 3626 if (0 == GNUNET_CRYPTO_cmp_peer_identity (&my_identity, &best_known_dest))
3638 { 3627 {
3628 DEBUG("PUT destination is me = %s,KEY = %s\n",GNUNET_i2s(&my_identity),GNUNET_h2s(&(put->key)));
3639 GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put->expiration_time), 3629 GDS_DATACACHE_handle_put (GNUNET_TIME_absolute_ntoh (put->expiration_time),
3640 &(put->key),putlen, pp, ntohl (put->block_type), 3630 &(put->key),putlen, pp, ntohl (put->block_type),
3641 payload_size, payload); 3631 payload_size, payload);
@@ -3698,7 +3688,7 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
3698 GNUNET_break_op (0); 3688 GNUNET_break_op (0);
3699 return GNUNET_YES; 3689 return GNUNET_YES;
3700 } 3690 }
3701 3691 DEBUG("PUT FOR DATA_SIZE = %lu\n",msize);
3702 GNUNET_STATISTICS_update (GDS_stats, 3692 GNUNET_STATISTICS_update (GDS_stats,
3703 gettext_noop 3693 gettext_noop
3704 ("# Bytes received from other peers"), msize, 3694 ("# Bytes received from other peers"), msize,
@@ -3745,6 +3735,7 @@ handle_dht_p2p_get (void *cls, const struct GNUNET_PeerIdentity *peer,
3745 /* I am the final destination. */ 3735 /* I am the final destination. */
3746 if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &best_known_dest)) 3736 if (0 == GNUNET_CRYPTO_cmp_peer_identity(&my_identity, &best_known_dest))
3747 { 3737 {
3738 DEBUG("GET destination is me = %s,KEY = %s\n",GNUNET_i2s(&my_identity),GNUNET_h2s(&(get->key)));
3748 struct GNUNET_PeerIdentity final_get_path[get_length+1]; 3739 struct GNUNET_PeerIdentity final_get_path[get_length+1];
3749 3740
3750 memcpy (final_get_path, gp, get_length * sizeof (struct GNUNET_PeerIdentity)); 3741 memcpy (final_get_path, gp, get_length * sizeof (struct GNUNET_PeerIdentity));
@@ -3811,7 +3802,7 @@ handle_dht_p2p_get_result (void *cls, const struct GNUNET_PeerIdentity *peer,
3811 GNUNET_break_op (0); 3802 GNUNET_break_op (0);
3812 return GNUNET_YES; 3803 return GNUNET_YES;
3813 } 3804 }
3814 3805 DEBUG("GET_RESULT FOR DATA_SIZE = %lu\n",msize);
3815 GNUNET_STATISTICS_update (GDS_stats, 3806 GNUNET_STATISTICS_update (GDS_stats,
3816 gettext_noop 3807 gettext_noop
3817 ("# Bytes received from other peers"), msize, 3808 ("# Bytes received from other peers"), msize,
@@ -4956,8 +4947,24 @@ compare_and_update_successor (struct GNUNET_PeerIdentity curr_succ,
4956 4947
4957 /* If the current_successor in the finger table is closest, then do nothing. */ 4948 /* If the current_successor in the finger table is closest, then do nothing. */
4958 if (closest_peer == &current_successor->finger_identity) 4949 if (closest_peer == &current_successor->finger_identity)
4950 {
4951 /* Code for testing ONLY: Store the successor for path tracking */
4952 track_topology = 1;
4953 if (track_topology && (NULL != GDS_stats))
4954 {
4955 char *my_id_str;
4956 uint64_t succ;
4957 char *key;
4958
4959 my_id_str = GNUNET_strdup (GNUNET_i2s_full (&my_identity));
4960 memcpy(&succ, &current_successor->finger_identity, sizeof(uint64_t));
4961 GNUNET_asprintf (&key, "XDHT:%s:", my_id_str);
4962 GNUNET_free (my_id_str);
4963 GNUNET_STATISTICS_set (GDS_stats, key, succ, 0);
4964 GNUNET_free (key);
4965 }
4959 return; 4966 return;
4960 4967 }
4961 /* Probable successor is the closest peer.*/ 4968 /* Probable successor is the closest peer.*/
4962 if(trail_length > 0) 4969 if(trail_length > 0)
4963 { 4970 {
@@ -5603,7 +5610,7 @@ remove_matching_trails (const struct GNUNET_PeerIdentity *disconnected_friend,
5603 matching_trails_count = 0; 5610 matching_trails_count = 0;
5604 5611
5605 /* Iterate over all the trails of finger. */ 5612 /* Iterate over all the trails of finger. */
5606 for (i = 0; i < remove_finger->trails_count; i++) 5613 for (i = 0; i < MAXIMUM_TRAILS_PER_FINGER; i++)
5607 { 5614 {
5608 struct Trail *trail; 5615 struct Trail *trail;
5609 trail = &remove_finger->trail_list[i]; 5616 trail = &remove_finger->trail_list[i];
diff --git a/src/dht/gnunet_dht_profiler.c b/src/dht/gnunet_dht_profiler.c
index fcec257f0..0fb7ab7df 100644
--- a/src/dht/gnunet_dht_profiler.c
+++ b/src/dht/gnunet_dht_profiler.c
@@ -38,7 +38,7 @@
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 100 41#define PUT_PROBABILITY 50
42 42
43/** 43/**
44 * Configuration 44 * Configuration
@@ -246,31 +246,71 @@ static unsigned int average_put_path_length;
246static unsigned int average_get_path_length; 246static unsigned int average_get_path_length;
247 247
248/** 248/**
249 * 249 * Total put path length across all peers.
250 */ 250 */
251static unsigned int total_put_path_length; 251static unsigned int total_put_path_length;
252 252
253/** 253/**
254 * 254 * Total get path length across all peers.
255 */ 255 */
256static unsigned int total_get_path_length; 256static unsigned int total_get_path_length;
257 257
258/** 258/**
259 * 259 * Hashmap to store pair of peer and its corresponding successor.
260 */ 260 */
261static struct GNUNET_CONTAINER_MultiHashMap *successor_peer_hashmap; 261static struct GNUNET_CONTAINER_MultiHashMap *successor_peer_hashmap;
262 262
263/** 263/**
264 * 264 * Key to start the lookup on successor_peer_hashmap.
265 */ 265 */
266static struct GNUNET_HashCode *start_key; 266static struct GNUNET_HashCode *start_key;
267 267
268/** 268/**
269 * 269 * Flag used to get the start_key.
270 */ 270 */
271static int flag = 0; 271static int flag = 0;
272 272
273/** 273/**
274 * Task to collect peer and its current successor statistics.
275 */
276static GNUNET_SCHEDULER_TaskIdentifier successor_stats_task;
277
278/**
279 * Closure for successor_stats_task.
280 */
281struct Collect_Stat_Context
282{
283 /**
284 * Current Peer Context.
285 */
286 struct Context *service_connect_ctx;
287
288 /**
289 * Testbed operation acting on this peer
290 */
291 struct GNUNET_TESTBED_Operation *op;
292};
293
294/**
295 * List of all the peers contexts.
296 */
297struct Context **peer_contexts = NULL;
298
299/**
300 * Counter to keep track of peers added to peer_context lists.
301 */
302static int peers_started = 0;
303
304/**
305 * Task that collects successor statistics from all the peers.
306 * @param cls
307 * @param tc
308 */
309static void
310collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
311
312
313/**
274 * Shutdown task. Cleanup all resources and operations. 314 * Shutdown task. Cleanup all resources and operations.
275 * 315 *
276 * @param cls NULL 316 * @param cls NULL
@@ -536,121 +576,6 @@ put_cont (void *cls, int success)
536 576
537 577
538/** 578/**
539 * Stats callback. Finish the stats testbed operation and when all stats have
540 * been iterated, shutdown the test.
541 *
542 * @param cls closure
543 * @param op the operation that has been finished
544 * @param emsg error message in case the operation has failed; will be NULL if
545 * operation has executed successfully.
546 */
547static void
548successor_stats_cont (void *cls,
549 struct GNUNET_TESTBED_Operation *op,
550 const char *emsg)
551{
552 /* Check if ring is formed. If yes then schedule put. */
553 struct GNUNET_HashCode *val;
554 struct GNUNET_HashCode *start_val;
555 int count = 0;
556 struct GNUNET_HashCode *key;
557
558 start_val = GNUNET_CONTAINER_multihashmap_get(successor_peer_hashmap,
559 start_key);
560
561 val = GNUNET_new(struct GNUNET_HashCode);
562 val = start_val;
563 while (count < n_active)
564 {
565 key = val;
566 val = GNUNET_CONTAINER_multihashmap_get (successor_peer_hashmap,
567 key);
568 count++;
569 }
570
571 if (start_val == val)
572 {
573 DEBUG("Circle complete\n");
574 /* FIXME: Schedule the delayed PUT task */
575 }
576 else
577 {
578 static unsigned int tries;
579
580 DEBUG("Circle not complete\n");
581 if (max_searches == ++tries)
582 {
583 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
584 "Maximum tries %u exceeded while checking successor"
585 " cirle formation. Exiting\n",
586 max_searches);
587 GNUNET_SCHEDULER_shutdown ();
588 return;
589 }
590 /* FIXME: Re-schedule the successor stats gathering task to run after some
591 delay */
592 }
593}
594
595
596/**
597 * Process successor statistic values.
598 *
599 * @param cls closure
600 * @param peer the peer the statistic belong to
601 * @param subsystem name of subsystem that created the statistic
602 * @param name the name of the datum
603 * @param value the current value
604 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
605 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
606 */
607static int
608successor_stats_iterator (void *cls,
609 const struct GNUNET_TESTBED_Peer *peer,
610 const char *subsystem,
611 const char *name,
612 uint64_t value,
613 int is_persistent)
614{
615 static const char *key_string = "XDHT";
616
617 DEBUG (" Inside successor stats,name = %s\n",name);
618 if (0 == strncmp (key_string, name, strlen (key_string)))
619 {
620 char *my_id_str;
621 char *successor_id_str;
622 struct GNUNET_HashCode *my_id;
623 struct GNUNET_HashCode *successor_id;
624
625 /* Parse the string to get the peer and its successor. */
626 strtok((char *)name,":");
627 my_id_str = strtok(NULL,":");
628 successor_id_str = strtok(NULL,":");
629
630 /* Get Hash of my_id_str and successor_id_str */
631 my_id = GNUNET_new(struct GNUNET_HashCode);
632 successor_id = GNUNET_new(struct GNUNET_HashCode);
633 GNUNET_CRYPTO_hash (my_id_str, sizeof(my_id_str),my_id);
634 GNUNET_CRYPTO_hash (successor_id_str, sizeof(successor_id_str),successor_id);
635
636 if (0 == flag)
637 {
638 start_key = my_id;
639 flag = 1;
640 }
641
642 GNUNET_CONTAINER_multihashmap_put (successor_peer_hashmap,
643 my_id, (void *)successor_id,
644 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
645
646
647 }
648
649 return GNUNET_OK;
650}
651
652
653/**
654 * Task to do DHT PUTS 579 * Task to do DHT PUTS
655 * 580 *
656 * @param cls the active context 581 * @param cls the active context
@@ -660,17 +585,7 @@ static void
660delayed_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 585delayed_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
661{ 586{
662 struct ActiveContext *ac = cls; 587 struct ActiveContext *ac = cls;
663 588 DEBUG("PUT SUPU \n");
664 successor_peer_hashmap = GNUNET_CONTAINER_multihashmap_create (n_active,
665 GNUNET_NO);
666 /* Check for successor pointer, don't start put till the virtual ring topology
667 is not created. */
668 successor_stats_op =
669 GNUNET_TESTBED_get_statistics (n_active, testbed_handles,
670 "dht", NULL,
671 successor_stats_iterator,
672 successor_stats_cont, NULL);
673
674 ac->delay_task = GNUNET_SCHEDULER_NO_TASK; 589 ac->delay_task = GNUNET_SCHEDULER_NO_TASK;
675 /* Generate and DHT PUT some random data */ 590 /* Generate and DHT PUT some random data */
676 ac->put_data_size = 16; /* minimum */ 591 ac->put_data_size = 16; /* minimum */
@@ -694,7 +609,6 @@ delayed_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
694} 609}
695 610
696 611
697
698/** 612/**
699 * Connection to DHT has been established. Call the delay task. 613 * Connection to DHT has been established. Call the delay task.
700 * 614 *
@@ -724,11 +638,7 @@ dht_connected (void *cls,
724 ctx->op = NULL; 638 ctx->op = NULL;
725 return; 639 return;
726 } 640 }
727 641
728 DEBUG (" Call stats \n");
729
730 /* FIXME: move this to happen after the successor circle formation is
731 complete */
732 ac->delay_task = GNUNET_SCHEDULER_add_delayed (delay, &delayed_put, ac); 642 ac->delay_task = GNUNET_SCHEDULER_add_delayed (delay, &delayed_put, ac);
733} 643}
734 644
@@ -772,6 +682,197 @@ dht_disconnect (void *cls, void *op_result)
772 682
773 683
774/** 684/**
685 * FIXME:Verify where is n_active used. Should this service be started only
686 * for n_active peers?
687 * Start testbed service for all the peers.
688 */
689static void
690start_testbed_service_on_all_peers()
691{
692 unsigned int i;
693 for(i = 0; i < peers_started; i++)
694 {
695 struct Context *ctx = peer_contexts[i];
696 DEBUG("GNUNET_TESTBED_service_connect \n");
697 ctx->op =
698 GNUNET_TESTBED_service_connect (ctx,
699 ctx->peer,
700 "dht",
701 &dht_connected, ctx->ac,
702 &dht_connect,
703 &dht_disconnect,
704 ctx->ac);
705
706 }
707}
708
709
710/**
711 * Stats callback. Iterate over the hashmap and check if all th peers form
712 * a virtual ring topology.
713 *
714 * @param cls closure
715 * @param op the operation that has been finished
716 * @param emsg error message in case the operation has failed; will be NULL if
717 * operation has executed successfully.
718 */
719static void
720successor_stats_cont (void *cls,
721 struct GNUNET_TESTBED_Operation *op,
722 const char *emsg)
723{
724 struct GNUNET_HashCode *val;
725 struct GNUNET_HashCode *start_val;
726 int count = 0;
727 struct GNUNET_HashCode *key;
728
729 start_val =(struct GNUNET_HashCode *) GNUNET_CONTAINER_multihashmap_get(successor_peer_hashmap,
730 start_key);
731
732 val = GNUNET_new(struct GNUNET_HashCode);
733 val = start_val;
734 while (count < num_peers)
735 {
736 key = GNUNET_new(struct GNUNET_HashCode);
737 key = val;
738 val = GNUNET_CONTAINER_multihashmap_get (successor_peer_hashmap,
739 key);
740 GNUNET_assert(NULL != val);
741 count++;
742 }
743
744 if (start_val == val)
745 {
746 DEBUG("Circle completed\n");
747 if (GNUNET_SCHEDULER_NO_TASK != successor_stats_task)
748 {
749 successor_stats_task = GNUNET_SCHEDULER_NO_TASK;
750 //FIXME: free hashmap.
751 }
752 successor_stats_op = NULL;
753
754 if(GNUNET_SCHEDULER_NO_TASK == successor_stats_task)
755 {
756 start_testbed_service_on_all_peers();
757 }
758
759 return;
760 }
761 else
762 {
763 static unsigned int tries;
764
765 DEBUG("Circle not complete\n");
766 if (max_searches == ++tries)
767 {
768 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
769 "Maximum tries %u exceeded while checking successor TOTAL TRIES %u"
770 " cirle formation. Exiting\n",
771 max_searches,tries);
772 if (GNUNET_SCHEDULER_NO_TASK != successor_stats_task)
773 {
774 successor_stats_task = GNUNET_SCHEDULER_NO_TASK;
775 //FIXME: free hashmap
776 }
777 successor_stats_op = NULL;
778
779 if(GNUNET_SCHEDULER_NO_TASK == successor_stats_task)
780 {
781 start_testbed_service_on_all_peers();
782 }
783
784 return;
785 }
786
787 //FIXME: change delay use exponential back off.
788 successor_stats_task = GNUNET_SCHEDULER_add_delayed (delay, &collect_stats, cls);
789 }
790}
791
792
793/**
794 * Process successor statistic values.
795 *
796 * @param cls closure
797 * @param peer the peer the statistic belong to
798 * @param subsystem name of subsystem that created the statistic
799 * @param name the name of the datum
800 * @param value the current value
801 * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not
802 * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration
803 */
804static int
805successor_stats_iterator (void *cls,
806 const struct GNUNET_TESTBED_Peer *peer,
807 const char *subsystem,
808 const char *name,
809 uint64_t value,
810 int is_persistent)
811{
812 static const char *key_string = "XDHT";
813
814 if (0 == strncmp (key_string, name, strlen (key_string)))
815 {
816 char *my_id_str;
817 char successor_str[13];
818 char truncated_my_id_str[13];
819 char truncated_successor_str[13];
820 struct GNUNET_HashCode *my_id_key;
821 struct GNUNET_HashCode *succ_key;
822
823 strtok((char *)name,":");
824 my_id_str = strtok(NULL,":");
825
826 strncpy(truncated_my_id_str, my_id_str, 12);
827 truncated_my_id_str[12] = '\0';
828
829 my_id_key = GNUNET_new(struct GNUNET_HashCode);
830 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);
833 strncpy(truncated_successor_str, successor_str, 12);
834 truncated_successor_str[12] ='\0';
835
836 succ_key = GNUNET_new(struct GNUNET_HashCode);
837 GNUNET_CRYPTO_hash (truncated_successor_str, sizeof(truncated_successor_str),succ_key);
838
839 if (0 == flag)
840 {
841 start_key = my_id_key;
842 flag = 1;
843 }
844 GNUNET_CONTAINER_multihashmap_put (successor_peer_hashmap,
845 my_id_key, (void *)succ_key,
846 GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE);
847 }
848 return GNUNET_OK;
849}
850
851
852/*
853 * Task that collects peer and its corresponding successors.
854 *
855 * @param cls Closure (NULL).
856 * @param tc Task Context.
857 */
858static void
859collect_stats (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
860{
861 if ((GNUNET_SCHEDULER_REASON_SHUTDOWN & tc->reason) != 0)
862 return;
863
864 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Start collecting statistics...\n");
865
866 /* Check for successor pointer, don't start put till the virtual ring topology
867 is not created. */
868 successor_stats_op =
869 GNUNET_TESTBED_get_statistics (num_peers, testbed_handles,
870 "dht", NULL,
871 successor_stats_iterator,
872 successor_stats_cont, cls);
873}
874
875/**
775 * Callback called when DHT service on the peer is started 876 * Callback called when DHT service on the peer is started
776 * 877 *
777 * @param cls the context 878 * @param cls the context
@@ -785,24 +886,35 @@ service_started (void *cls,
785 const char *emsg) 886 const char *emsg)
786{ 887{
787 struct Context *ctx = cls; 888 struct Context *ctx = cls;
788 static unsigned int nstarted; 889
789
790 GNUNET_assert (NULL != ctx); 890 GNUNET_assert (NULL != ctx);
791 GNUNET_assert (NULL != ctx->op); 891 GNUNET_assert (NULL != ctx->op);
792 GNUNET_TESTBED_operation_done (ctx->op); 892 GNUNET_TESTBED_operation_done (ctx->op);
793 ctx->op = NULL; 893 ctx->op = NULL;
794 if (NULL == ctx->ac) 894 if (NULL == ctx->ac)
795 return; 895 return;
796 ctx->op = GNUNET_TESTBED_service_connect (ctx, ctx->peer, 896
797 "dht", 897 if (NULL == peer_contexts)
798 &dht_connected, ctx->ac, 898 {
799 &dht_connect, 899 peer_contexts = GNUNET_malloc(num_peers * sizeof(struct Context *));
800 &dht_disconnect, 900 }
801 ctx->ac); 901
802 if (num_peers == ++nstarted) 902 peer_contexts[peers_started] = ctx;
903 peers_started++;
904 DEBUG("Peers Started = %d \n", peers_started);
905
906 if (GNUNET_SCHEDULER_NO_TASK == successor_stats_task)
803 { 907 {
804 /* FIXME: schedule a delayed task to scan the successors from statistics of 908 DEBUG("successor_stats_task \n");
805 all peers */ 909 struct Collect_Stat_Context *collect_stat_cls = GNUNET_new(struct Collect_Stat_Context);
910 collect_stat_cls->service_connect_ctx = cls;
911 collect_stat_cls->op = op;
912
913 successor_peer_hashmap = GNUNET_CONTAINER_multihashmap_create (num_peers,
914 GNUNET_NO);
915 successor_stats_task = GNUNET_SCHEDULER_add_delayed (delay,
916 &collect_stats,
917 collect_stat_cls);
806 } 918 }
807} 919}
808 920
@@ -936,11 +1048,11 @@ main (int argc, char *const *argv)
936 GNUNET_GETOPT_OPTION_END 1048 GNUNET_GETOPT_OPTION_END
937 }; 1049 };
938 1050
939 max_searches = 1; 1051 max_searches = 10;
940 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) 1052 if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
941 return 2; 1053 return 2;
942 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1); /* default delay */ 1054 delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 2); /* default delay */
943 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1); /* default timeout */ 1055 timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1); /* default timeout */
944 replication = 1; /* default replication */ 1056 replication = 1; /* default replication */
945 rc = 0; 1057 rc = 0;
946 if (GNUNET_OK != 1058 if (GNUNET_OK !=