diff options
Diffstat (limited to 'src/testing/testing_group.c')
-rw-r--r-- | src/testing/testing_group.c | 237 |
1 files changed, 145 insertions, 92 deletions
diff --git a/src/testing/testing_group.c b/src/testing/testing_group.c index f3eeb9069..78de644f4 100644 --- a/src/testing/testing_group.c +++ b/src/testing/testing_group.c | |||
@@ -304,6 +304,11 @@ struct InternalStartContext | |||
304 | const char *username; | 304 | const char *username; |
305 | 305 | ||
306 | /** | 306 | /** |
307 | * Pointer to starting memory location of a hostkey | ||
308 | */ | ||
309 | const char *hostkey; | ||
310 | |||
311 | /** | ||
307 | * Port to use for ssh. | 312 | * Port to use for ssh. |
308 | */ | 313 | */ |
309 | uint16_t sshport; | 314 | uint16_t sshport; |
@@ -629,6 +634,96 @@ struct UnblacklistContext | |||
629 | uint32_t first_uid; | 634 | uint32_t first_uid; |
630 | }; | 635 | }; |
631 | 636 | ||
637 | struct RandomContext | ||
638 | { | ||
639 | /** | ||
640 | * The peergroup | ||
641 | */ | ||
642 | struct GNUNET_TESTING_PeerGroup *pg; | ||
643 | |||
644 | /** | ||
645 | * uid of the first peer | ||
646 | */ | ||
647 | uint32_t first_uid; | ||
648 | |||
649 | /** | ||
650 | * Peer data for first peer. | ||
651 | */ | ||
652 | struct PeerData *first; | ||
653 | |||
654 | /** | ||
655 | * Random percentage to use | ||
656 | */ | ||
657 | double percentage; | ||
658 | }; | ||
659 | |||
660 | struct MinimumContext | ||
661 | { | ||
662 | /** | ||
663 | * The peergroup | ||
664 | */ | ||
665 | struct GNUNET_TESTING_PeerGroup *pg; | ||
666 | |||
667 | /** | ||
668 | * uid of the first peer | ||
669 | */ | ||
670 | uint32_t first_uid; | ||
671 | |||
672 | /** | ||
673 | * Peer data for first peer. | ||
674 | */ | ||
675 | struct PeerData *first; | ||
676 | |||
677 | /** | ||
678 | * Number of conns per peer | ||
679 | */ | ||
680 | unsigned int num_to_add; | ||
681 | |||
682 | /** | ||
683 | * Permuted array of all possible connections. Only add the Nth | ||
684 | * peer if it's in the Nth position. | ||
685 | */ | ||
686 | unsigned int *pg_array; | ||
687 | |||
688 | /** | ||
689 | * What number is the current element we are iterating over? | ||
690 | */ | ||
691 | unsigned int current; | ||
692 | }; | ||
693 | |||
694 | struct DFSContext | ||
695 | { | ||
696 | /** | ||
697 | * The peergroup | ||
698 | */ | ||
699 | struct GNUNET_TESTING_PeerGroup *pg; | ||
700 | |||
701 | /** | ||
702 | * uid of the first peer | ||
703 | */ | ||
704 | uint32_t first_uid; | ||
705 | |||
706 | /** | ||
707 | * uid of the second peer | ||
708 | */ | ||
709 | uint32_t second_uid; | ||
710 | |||
711 | /** | ||
712 | * Peer data for first peer. | ||
713 | */ | ||
714 | struct PeerData *first; | ||
715 | |||
716 | /** | ||
717 | * Which peer has been chosen as the one to add? | ||
718 | */ | ||
719 | unsigned int chosen; | ||
720 | |||
721 | /** | ||
722 | * What number is the current element we are iterating over? | ||
723 | */ | ||
724 | unsigned int current; | ||
725 | }; | ||
726 | |||
632 | /** | 727 | /** |
633 | * Convert unique ID to hash code. | 728 | * Convert unique ID to hash code. |
634 | * | 729 | * |
@@ -2100,6 +2195,7 @@ create_from_file (struct GNUNET_TESTING_PeerGroup *pg, | |||
2100 | return connect_attempts; | 2195 | return connect_attempts; |
2101 | } | 2196 | } |
2102 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Read %u total peers in topology\n", total_peers); | 2197 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Read %u total peers in topology\n", total_peers); |
2198 | GNUNET_assert(total_peers == pg->total); | ||
2103 | curr_state = PEER_INDEX; | 2199 | curr_state = PEER_INDEX; |
2104 | while((buf[count] != '\n') && (count < frstat.st_size - 1)) | 2200 | while((buf[count] != '\n') && (count < frstat.st_size - 1)) |
2105 | count++; | 2201 | count++; |
@@ -2131,18 +2227,19 @@ create_from_file (struct GNUNET_TESTING_PeerGroup *pg, | |||
2131 | return connect_attempts; | 2227 | return connect_attempts; |
2132 | } | 2228 | } |
2133 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Read second peer index %u\n", second_peer_index); | 2229 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Read second peer index %u\n", second_peer_index); |
2134 | while((buf[count] != '\n') && (buf[count] != ' ') && (count < frstat.st_size - 1)) | 2230 | /* Assume file is written with first peer 1, but array index is 0 */ |
2231 | connect_attempts += proc (pg, first_peer_index - 1, second_peer_index - 1); | ||
2232 | while((buf[count] != '\n') && (buf[count] != ',') && (count < frstat.st_size - 1)) | ||
2135 | count++; | 2233 | count++; |
2136 | if (buf[count] == '\n') | 2234 | if (buf[count] == '\n') |
2137 | { | 2235 | { |
2138 | curr_state = PEER_INDEX; | 2236 | curr_state = PEER_INDEX; |
2139 | } | 2237 | } |
2140 | else if (buf[count] != ' ') | 2238 | else if (buf[count] != ',') |
2141 | { | 2239 | { |
2142 | curr_state = OTHER_PEER_INDEX; | 2240 | curr_state = OTHER_PEER_INDEX; |
2143 | } | 2241 | } |
2144 | count++; | 2242 | count++; |
2145 | curr_state = OTHER_PEER_INDEX; | ||
2146 | break; | 2243 | break; |
2147 | default: | 2244 | default: |
2148 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Found bad data in topology file while in state %d!\n", curr_state); | 2245 | GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Found bad data in topology file while in state %d!\n", curr_state); |
@@ -3078,95 +3175,6 @@ GNUNET_TESTING_create_topology (struct GNUNET_TESTING_PeerGroup *pg, | |||
3078 | return num_connections; | 3175 | return num_connections; |
3079 | } | 3176 | } |
3080 | 3177 | ||
3081 | struct RandomContext | ||
3082 | { | ||
3083 | /** | ||
3084 | * The peergroup | ||
3085 | */ | ||
3086 | struct GNUNET_TESTING_PeerGroup *pg; | ||
3087 | |||
3088 | /** | ||
3089 | * uid of the first peer | ||
3090 | */ | ||
3091 | uint32_t first_uid; | ||
3092 | |||
3093 | /** | ||
3094 | * Peer data for first peer. | ||
3095 | */ | ||
3096 | struct PeerData *first; | ||
3097 | |||
3098 | /** | ||
3099 | * Random percentage to use | ||
3100 | */ | ||
3101 | double percentage; | ||
3102 | }; | ||
3103 | |||
3104 | struct MinimumContext | ||
3105 | { | ||
3106 | /** | ||
3107 | * The peergroup | ||
3108 | */ | ||
3109 | struct GNUNET_TESTING_PeerGroup *pg; | ||
3110 | |||
3111 | /** | ||
3112 | * uid of the first peer | ||
3113 | */ | ||
3114 | uint32_t first_uid; | ||
3115 | |||
3116 | /** | ||
3117 | * Peer data for first peer. | ||
3118 | */ | ||
3119 | struct PeerData *first; | ||
3120 | |||
3121 | /** | ||
3122 | * Number of conns per peer | ||
3123 | */ | ||
3124 | unsigned int num_to_add; | ||
3125 | |||
3126 | /** | ||
3127 | * Permuted array of all possible connections. Only add the Nth | ||
3128 | * peer if it's in the Nth position. | ||
3129 | */ | ||
3130 | unsigned int *pg_array; | ||
3131 | |||
3132 | /** | ||
3133 | * What number is the current element we are iterating over? | ||
3134 | */ | ||
3135 | unsigned int current; | ||
3136 | }; | ||
3137 | |||
3138 | struct DFSContext | ||
3139 | { | ||
3140 | /** | ||
3141 | * The peergroup | ||
3142 | */ | ||
3143 | struct GNUNET_TESTING_PeerGroup *pg; | ||
3144 | |||
3145 | /** | ||
3146 | * uid of the first peer | ||
3147 | */ | ||
3148 | uint32_t first_uid; | ||
3149 | |||
3150 | /** | ||
3151 | * uid of the second peer | ||
3152 | */ | ||
3153 | uint32_t second_uid; | ||
3154 | |||
3155 | /** | ||
3156 | * Peer data for first peer. | ||
3157 | */ | ||
3158 | struct PeerData *first; | ||
3159 | |||
3160 | /** | ||
3161 | * Which peer has been chosen as the one to add? | ||
3162 | */ | ||
3163 | unsigned int chosen; | ||
3164 | |||
3165 | /** | ||
3166 | * What number is the current element we are iterating over? | ||
3167 | */ | ||
3168 | unsigned int current; | ||
3169 | }; | ||
3170 | 3178 | ||
3171 | /** | 3179 | /** |
3172 | * Iterator for choosing random peers to connect. | 3180 | * Iterator for choosing random peers to connect. |
@@ -4324,6 +4332,7 @@ internal_start (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
4324 | internal_context->hostname, | 4332 | internal_context->hostname, |
4325 | internal_context->username, | 4333 | internal_context->username, |
4326 | internal_context->sshport, | 4334 | internal_context->sshport, |
4335 | internal_context->hostkey, | ||
4327 | &internal_hostkey_callback, | 4336 | &internal_hostkey_callback, |
4328 | internal_context, | 4337 | internal_context, |
4329 | &internal_startup_callback, | 4338 | &internal_startup_callback, |
@@ -4405,6 +4414,9 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
4405 | char *baseservicehome; | 4414 | char *baseservicehome; |
4406 | char *newservicehome; | 4415 | char *newservicehome; |
4407 | char *tmpdir; | 4416 | char *tmpdir; |
4417 | char *hostkeys_file; | ||
4418 | char *hostkey_data; | ||
4419 | struct GNUNET_DISK_FileHandle *fd; | ||
4408 | struct GNUNET_CONFIGURATION_Handle *pcfg; | 4420 | struct GNUNET_CONFIGURATION_Handle *pcfg; |
4409 | unsigned int off; | 4421 | unsigned int off; |
4410 | unsigned int hostcnt; | 4422 | unsigned int hostcnt; |
@@ -4412,12 +4424,15 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
4412 | uint16_t sshport; | 4424 | uint16_t sshport; |
4413 | uint32_t upnum; | 4425 | uint32_t upnum; |
4414 | uint32_t fdnum; | 4426 | uint32_t fdnum; |
4427 | uint64_t fs; | ||
4428 | uint64_t total_hostkeys; | ||
4415 | 4429 | ||
4416 | if (0 == total) | 4430 | if (0 == total) |
4417 | { | 4431 | { |
4418 | GNUNET_break (0); | 4432 | GNUNET_break (0); |
4419 | return NULL; | 4433 | return NULL; |
4420 | } | 4434 | } |
4435 | hostkey_data = NULL; | ||
4421 | upnum = 0; | 4436 | upnum = 0; |
4422 | fdnum = 0; | 4437 | fdnum = 0; |
4423 | pg = GNUNET_malloc (sizeof (struct GNUNET_TESTING_PeerGroup)); | 4438 | pg = GNUNET_malloc (sizeof (struct GNUNET_TESTING_PeerGroup)); |
@@ -4509,6 +4524,42 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
4509 | hostcnt = 0; | 4524 | hostcnt = 0; |
4510 | minport = LOW_PORT; | 4525 | minport = LOW_PORT; |
4511 | } | 4526 | } |
4527 | |||
4528 | if (GNUNET_YES == GNUNET_CONFIGURATION_get_value_string (cfg, "TESTING", "HOSTKEYSFILE", | ||
4529 | &hostkeys_file)) | ||
4530 | { | ||
4531 | if (GNUNET_YES != GNUNET_DISK_file_test (hostkeys_file)) | ||
4532 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Couldn't read hostkeys file!"); | ||
4533 | else | ||
4534 | { | ||
4535 | /* Check hostkey file size, read entire thing into memory */ | ||
4536 | fd = GNUNET_DISK_file_open (hostkeys_file, GNUNET_DISK_OPEN_READ, | ||
4537 | GNUNET_DISK_PERM_NONE); | ||
4538 | if (NULL == fd) | ||
4539 | { | ||
4540 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "open", hostkeys_file); | ||
4541 | return NULL; | ||
4542 | } | ||
4543 | |||
4544 | if (GNUNET_YES != GNUNET_DISK_file_size (hostkeys_file, &fs, GNUNET_YES)) | ||
4545 | fs = 0; | ||
4546 | |||
4547 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Found file size %llu for hostkeys, expect hostkeys to be size %d\n", fs, HOSTKEYFILESIZE); | ||
4548 | |||
4549 | if (fs % HOSTKEYFILESIZE != 0) | ||
4550 | { | ||
4551 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "File size %llu seems incorrect for hostkeys...\n", fs); | ||
4552 | } | ||
4553 | else | ||
4554 | { | ||
4555 | total_hostkeys = fs / HOSTKEYFILESIZE; | ||
4556 | GNUNET_log(GNUNET_ERROR_TYPE_WARNING, "Will read %llu hostkeys from file\n", total_hostkeys); | ||
4557 | hostkey_data = GNUNET_malloc_large (fs); | ||
4558 | GNUNET_assert (fs == GNUNET_DISK_file_read (fd, hostkey_data, fs)); | ||
4559 | } | ||
4560 | } | ||
4561 | } | ||
4562 | |||
4512 | for (off = 0; off < total; off++) | 4563 | for (off = 0; off < total; off++) |
4513 | { | 4564 | { |
4514 | if (hostcnt > 0) | 4565 | if (hostcnt > 0) |
@@ -4570,6 +4621,8 @@ GNUNET_TESTING_daemons_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
4570 | pg->peers[off].internal_context.hostname = hostname; | 4621 | pg->peers[off].internal_context.hostname = hostname; |
4571 | pg->peers[off].internal_context.username = username; | 4622 | pg->peers[off].internal_context.username = username; |
4572 | pg->peers[off].internal_context.sshport = sshport; | 4623 | pg->peers[off].internal_context.sshport = sshport; |
4624 | if (hostkey_data != NULL) | ||
4625 | pg->peers[off].internal_context.hostkey = &hostkey_data[off * HOSTKEYFILESIZE]; | ||
4573 | pg->peers[off].internal_context.hostkey_callback = hostkey_callback; | 4626 | pg->peers[off].internal_context.hostkey_callback = hostkey_callback; |
4574 | pg->peers[off].internal_context.hostkey_cls = hostkey_cls; | 4627 | pg->peers[off].internal_context.hostkey_cls = hostkey_cls; |
4575 | pg->peers[off].internal_context.start_cb = cb; | 4628 | pg->peers[off].internal_context.start_cb = cb; |