diff options
author | Supriti Singh <supritisingh08@gmail.com> | 2014-08-08 13:29:20 +0000 |
---|---|---|
committer | Supriti Singh <supritisingh08@gmail.com> | 2014-08-08 13:29:20 +0000 |
commit | f9a7eeb87ad4af2721816e3b77c3c0dd872ef622 (patch) | |
tree | 3a4436e855cfecd96676cb4ce93966456caefc26 /src | |
parent | 67c0c732835eccdadd5294e7a6c361ae3d782ffc (diff) | |
download | gnunet-f9a7eeb87ad4af2721816e3b77c3c0dd872ef622.tar.gz gnunet-f9a7eeb87ad4af2721816e3b77c3c0dd872ef622.zip |
Using statistics to collect current successor of a peer in profiler
Diffstat (limited to 'src')
-rw-r--r-- | src/dht/gnunet-service-xdht_neighbours.c | 46 | ||||
-rw-r--r-- | src/dht/gnunet_dht_profiler.c | 163 |
2 files changed, 178 insertions, 31 deletions
diff --git a/src/dht/gnunet-service-xdht_neighbours.c b/src/dht/gnunet-service-xdht_neighbours.c index 139d1971b..dfd210795 100644 --- a/src/dht/gnunet-service-xdht_neighbours.c +++ b/src/dht/gnunet-service-xdht_neighbours.c | |||
@@ -52,6 +52,8 @@ | |||
52 | * hashing. | 52 | * hashing. |
53 | */ | 53 | */ |
54 | 54 | ||
55 | #define DEBUG(...) \ | ||
56 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) | ||
55 | 57 | ||
56 | /** | 58 | /** |
57 | * Maximum possible fingers (including predecessor) of a peer | 59 | * Maximum possible fingers (including predecessor) of a peer |
@@ -2220,7 +2222,10 @@ GDS_NEIGHBOURS_send_get (const struct GNUNET_HashCode *key, | |||
2220 | 2222 | ||
2221 | msize = sizeof (struct PeerGetMessage) + | 2223 | msize = sizeof (struct PeerGetMessage) + |
2222 | (get_path_length * sizeof (struct GNUNET_PeerIdentity)); | 2224 | (get_path_length * sizeof (struct GNUNET_PeerIdentity)); |
2223 | 2225 | ||
2226 | //GNUNET_SERVER_MAX_MESSAGE_SIZE | ||
2227 | /* FIXME:TODO:URGENTHere you can try to optimize it a bit. In case the get path contains you | ||
2228 | or your friend then shorten the path. */ | ||
2224 | /* In this case we don't make get_path_length = 0, as we need get path to | 2229 | /* In this case we don't make get_path_length = 0, as we need get path to |
2225 | * return the message back to querying client. */ | 2230 | * return the message back to querying client. */ |
2226 | if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) | 2231 | if (msize >= GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE) |
@@ -3054,24 +3059,6 @@ scan_and_compress_trail (struct GNUNET_PeerIdentity finger_identity, | |||
3054 | return new_trail; | 3059 | return new_trail; |
3055 | } | 3060 | } |
3056 | 3061 | ||
3057 | #if 0 | ||
3058 | /* Store the successor for path tracking */ | ||
3059 | if (track_topology && (NULL != GDS_stats)) | ||
3060 | { | ||
3061 | char *my_id_str; | ||
3062 | char *succ_id_str; | ||
3063 | char *key; | ||
3064 | |||
3065 | my_id_str = GNUNET_strdup (GNUNET_i2s (&my_identity)); | ||
3066 | succ_id_str = GNUNET_strdup (GNUNET_i2s | ||
3067 | (&successor->finger_identity)); | ||
3068 | GNUNET_asprintf (&key, "XDHT:0:%.4s:%.4s", my_id_str, succ_id_str); | ||
3069 | GNUNET_free (my_id_str); | ||
3070 | GNUNET_free (succ_id_str); | ||
3071 | GNUNET_STATISTICS_update (GDS_stats, "key", 1, 0); | ||
3072 | GNUNET_free (key); | ||
3073 | } | ||
3074 | #endif | ||
3075 | 3062 | ||
3076 | /** | 3063 | /** |
3077 | * Periodic task to verify current successor. There can be multiple trails to reach | 3064 | * Periodic task to verify current successor. There can be multiple trails to reach |
@@ -3119,10 +3106,27 @@ send_verify_successor_message (void *cls, | |||
3119 | 3106 | ||
3120 | /* Trail stored at this index. */ | 3107 | /* Trail stored at this index. */ |
3121 | GNUNET_assert (GNUNET_YES == trail->is_present); | 3108 | GNUNET_assert (GNUNET_YES == trail->is_present); |
3122 | 3109 | ||
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 | |||
3123 | trail_id = trail->trail_id; | 3127 | trail_id = trail->trail_id; |
3124 | trail_length = trail->trail_length; | 3128 | trail_length = trail->trail_length; |
3125 | 3129 | ||
3126 | if (trail_length > 0) | 3130 | if (trail_length > 0) |
3127 | { | 3131 | { |
3128 | /* Copy the trail into peer list. */ | 3132 | /* Copy the trail into peer list. */ |
diff --git a/src/dht/gnunet_dht_profiler.c b/src/dht/gnunet_dht_profiler.c index 95528b3f9..fb56cc19c 100644 --- a/src/dht/gnunet_dht_profiler.c +++ b/src/dht/gnunet_dht_profiler.c | |||
@@ -208,7 +208,12 @@ static unsigned int replication; | |||
208 | /** | 208 | /** |
209 | * Testbed Operation (to get stats). | 209 | * Testbed Operation (to get stats). |
210 | */ | 210 | */ |
211 | static struct GNUNET_TESTBED_Operation *stats_op; | 211 | static struct GNUNET_TESTBED_Operation *bandwidth_stats_op; |
212 | |||
213 | /** | ||
214 | * To get successor stats. | ||
215 | */ | ||
216 | static struct GNUNET_TESTBED_Operation *successor_stats_op; | ||
212 | 217 | ||
213 | /** | 218 | /** |
214 | * Testbed peer handles. | 219 | * Testbed peer handles. |
@@ -235,9 +240,31 @@ static unsigned int average_put_path_length; | |||
235 | */ | 240 | */ |
236 | static unsigned int average_get_path_length; | 241 | static unsigned int average_get_path_length; |
237 | 242 | ||
243 | /** | ||
244 | * | ||
245 | */ | ||
238 | static unsigned int total_put_path_length; | 246 | static unsigned int total_put_path_length; |
239 | 247 | ||
248 | /** | ||
249 | * | ||
250 | */ | ||
240 | static unsigned int total_get_path_length; | 251 | static unsigned int total_get_path_length; |
252 | |||
253 | /** | ||
254 | * | ||
255 | */ | ||
256 | static struct GNUNET_CONTAINER_MultiHashMap *successor_peer_hashmap; | ||
257 | |||
258 | /** | ||
259 | * | ||
260 | */ | ||
261 | static struct GNUNET_HashCode *start_key; | ||
262 | |||
263 | /** | ||
264 | * | ||
265 | */ | ||
266 | static int flag = 0; | ||
267 | |||
241 | /** | 268 | /** |
242 | * Shutdown task. Cleanup all resources and operations. | 269 | * Shutdown task. Cleanup all resources and operations. |
243 | * | 270 | * |
@@ -273,9 +300,9 @@ do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
273 | GNUNET_free (a_ctx); | 300 | GNUNET_free (a_ctx); |
274 | a_ctx = NULL; | 301 | a_ctx = NULL; |
275 | } | 302 | } |
276 | if(NULL != stats_op) | 303 | if(NULL != bandwidth_stats_op) |
277 | GNUNET_TESTBED_operation_done (stats_op); | 304 | GNUNET_TESTBED_operation_done (bandwidth_stats_op); |
278 | stats_op = NULL; | 305 | bandwidth_stats_op = NULL; |
279 | GNUNET_free_non_null (a_ac); | 306 | GNUNET_free_non_null (a_ac); |
280 | } | 307 | } |
281 | 308 | ||
@@ -353,10 +380,10 @@ summarize () | |||
353 | return; | 380 | return; |
354 | } | 381 | } |
355 | /* Collect Stats*/ | 382 | /* Collect Stats*/ |
356 | stats_op = GNUNET_TESTBED_get_statistics (n_active, testbed_handles, | 383 | bandwidth_stats_op = GNUNET_TESTBED_get_statistics (n_active, testbed_handles, |
357 | "dht", NULL, | 384 | "dht", NULL, |
358 | bandwidth_stats_iterator, | 385 | bandwidth_stats_iterator, |
359 | bandwidth_stats_cont, NULL); | 386 | bandwidth_stats_cont, NULL); |
360 | } | 387 | } |
361 | 388 | ||
362 | 389 | ||
@@ -504,6 +531,107 @@ put_cont (void *cls, int success) | |||
504 | 531 | ||
505 | 532 | ||
506 | /** | 533 | /** |
534 | * Stats callback. Finish the stats testbed operation and when all stats have | ||
535 | * been iterated, shutdown the test. | ||
536 | * | ||
537 | * @param cls closure | ||
538 | * @param op the operation that has been finished | ||
539 | * @param emsg error message in case the operation has failed; will be NULL if | ||
540 | * operation has executed successfully. | ||
541 | */ | ||
542 | static void | ||
543 | successor_stats_cont (void *cls, | ||
544 | struct GNUNET_TESTBED_Operation *op, | ||
545 | const char *emsg) | ||
546 | { | ||
547 | /* Check if ring is formed. If yes then schedule put. */ | ||
548 | struct GNUNET_HashCode *val; | ||
549 | struct GNUNET_HashCode *start_val; | ||
550 | int count = 0; | ||
551 | struct GNUNET_HashCode *key; | ||
552 | |||
553 | start_val = GNUNET_CONTAINER_multihashmap_get(successor_peer_hashmap, | ||
554 | start_key); | ||
555 | |||
556 | val = GNUNET_new(struct GNUNET_HashCode); | ||
557 | val = start_val; | ||
558 | while (count < n_active) | ||
559 | { | ||
560 | key = val; | ||
561 | val = GNUNET_CONTAINER_multihashmap_get (successor_peer_hashmap, | ||
562 | key); | ||
563 | count++; | ||
564 | } | ||
565 | |||
566 | if (start_val == val) | ||
567 | { | ||
568 | DEBUG("Circle complete\n"); | ||
569 | } | ||
570 | else | ||
571 | { | ||
572 | DEBUG("Circle not complete\n"); | ||
573 | } | ||
574 | } | ||
575 | |||
576 | |||
577 | /** | ||
578 | * Process successor statistic values. | ||
579 | * | ||
580 | * @param cls closure | ||
581 | * @param peer the peer the statistic belong to | ||
582 | * @param subsystem name of subsystem that created the statistic | ||
583 | * @param name the name of the datum | ||
584 | * @param value the current value | ||
585 | * @param is_persistent GNUNET_YES if the value is persistent, GNUNET_NO if not | ||
586 | * @return GNUNET_OK to continue, GNUNET_SYSERR to abort iteration | ||
587 | */ | ||
588 | static int | ||
589 | successor_stats_iterator (void *cls, | ||
590 | const struct GNUNET_TESTBED_Peer *peer, | ||
591 | const char *subsystem, | ||
592 | const char *name, | ||
593 | uint64_t value, | ||
594 | int is_persistent) | ||
595 | { | ||
596 | static const char *key_string = "XDHT"; | ||
597 | |||
598 | DEBUG (" Inside successor stats,name = %s\n",name); | ||
599 | if (0 == strncmp (key_string, name, strlen (key_string))) | ||
600 | { | ||
601 | char *my_id_str; | ||
602 | char *successor_id_str; | ||
603 | struct GNUNET_HashCode *my_id; | ||
604 | struct GNUNET_HashCode *successor_id; | ||
605 | |||
606 | /* Parse the string to get the peer and its successor. */ | ||
607 | strtok((char *)name,":"); | ||
608 | my_id_str = strtok(NULL,":"); | ||
609 | successor_id_str = strtok(NULL,":"); | ||
610 | |||
611 | /* Get Hash of my_id_str and successor_id_str */ | ||
612 | my_id = GNUNET_new(struct GNUNET_HashCode); | ||
613 | successor_id = GNUNET_new(struct GNUNET_HashCode); | ||
614 | GNUNET_CRYPTO_hash (my_id_str, sizeof(my_id_str),my_id); | ||
615 | GNUNET_CRYPTO_hash (successor_id_str, sizeof(successor_id_str),successor_id); | ||
616 | |||
617 | if (0 == flag) | ||
618 | { | ||
619 | start_key = my_id; | ||
620 | flag = 1; | ||
621 | } | ||
622 | |||
623 | GNUNET_CONTAINER_multihashmap_put (successor_peer_hashmap, | ||
624 | my_id, (void *)successor_id, | ||
625 | GNUNET_CONTAINER_MULTIHASHMAPOPTION_REPLACE); | ||
626 | |||
627 | |||
628 | } | ||
629 | |||
630 | return GNUNET_OK; | ||
631 | } | ||
632 | |||
633 | |||
634 | /** | ||
507 | * Task to do DHT PUTS | 635 | * Task to do DHT PUTS |
508 | * | 636 | * |
509 | * @param cls the active context | 637 | * @param cls the active context |
@@ -513,7 +641,17 @@ static void | |||
513 | delayed_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 641 | delayed_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
514 | { | 642 | { |
515 | struct ActiveContext *ac = cls; | 643 | struct ActiveContext *ac = cls; |
516 | 644 | ||
645 | successor_peer_hashmap = GNUNET_CONTAINER_multihashmap_create (n_active, | ||
646 | GNUNET_NO); | ||
647 | /* Check for successor pointer, don't start put till the virtual ring topology | ||
648 | is not created. */ | ||
649 | successor_stats_op = | ||
650 | GNUNET_TESTBED_get_statistics (n_active, testbed_handles, | ||
651 | "dht", NULL, | ||
652 | successor_stats_iterator, | ||
653 | successor_stats_cont, NULL); | ||
654 | |||
517 | ac->delay_task = GNUNET_SCHEDULER_NO_TASK; | 655 | ac->delay_task = GNUNET_SCHEDULER_NO_TASK; |
518 | /* Generate and DHT PUT some random data */ | 656 | /* Generate and DHT PUT some random data */ |
519 | ac->put_data_size = 16; /* minimum */ | 657 | ac->put_data_size = 16; /* minimum */ |
@@ -537,6 +675,7 @@ delayed_put (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
537 | } | 675 | } |
538 | 676 | ||
539 | 677 | ||
678 | |||
540 | /** | 679 | /** |
541 | * Connection to DHT has been established. Call the delay task. | 680 | * Connection to DHT has been established. Call the delay task. |
542 | * | 681 | * |
@@ -566,6 +705,9 @@ dht_connected (void *cls, | |||
566 | ctx->op = NULL; | 705 | ctx->op = NULL; |
567 | return; | 706 | return; |
568 | } | 707 | } |
708 | |||
709 | DEBUG (" Call stats \n"); | ||
710 | |||
569 | ac->delay_task = GNUNET_SCHEDULER_add_delayed (delay, &delayed_put, ac); | 711 | ac->delay_task = GNUNET_SCHEDULER_add_delayed (delay, &delayed_put, ac); |
570 | } | 712 | } |
571 | 713 | ||
@@ -677,6 +819,7 @@ test_run (void *cls, | |||
677 | GNUNET_free (a_ctx); | 819 | GNUNET_free (a_ctx); |
678 | return; | 820 | return; |
679 | } | 821 | } |
822 | |||
680 | a_ac = GNUNET_malloc (n_active * sizeof (struct ActiveContext)); | 823 | a_ac = GNUNET_malloc (n_active * sizeof (struct ActiveContext)); |
681 | ac_cnt = 0; | 824 | ac_cnt = 0; |
682 | for (cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++) | 825 | for (cnt = 0; cnt < num_peers && ac_cnt < n_active; cnt++) |
@@ -766,7 +909,7 @@ main (int argc, char *const *argv) | |||
766 | 909 | ||
767 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) | 910 | if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv)) |
768 | return 2; | 911 | return 2; |
769 | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30); /* default delay */ | 912 | delay = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 1); /* default delay */ |
770 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1); /* default timeout */ | 913 | timeout = GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 1); /* default timeout */ |
771 | replication = 1; /* default replication */ | 914 | replication = 1; /* default replication */ |
772 | rc = 0; | 915 | rc = 0; |