-/**
- * Initializes the operation queue for parallel overlay connects
- *
- * @param h the host handle
- * @param npoc the number of parallel overlay connects - the queue size
- */
-void
-GNUNET_TESTBED_set_num_parallel_overlay_connects_ (struct
- GNUNET_TESTBED_Host *h,
- unsigned int npoc)
-{
- //fprintf (stderr, "%d", npoc);
- GNUNET_free_non_null (h->tslots);
- h->tslots_filled = 0;
- h->num_parallel_connects = npoc;
- h->tslots = GNUNET_malloc (npoc * sizeof (struct TimeSlot));
- GNUNET_TESTBED_operation_queue_reset_max_active_
- (h->opq_parallel_overlay_connect_operations, npoc);
-}
-
-
-/**
- * Returns a timing slot which will be exclusively locked
- *
- * @param h the host handle
- * @param key a pointer which is associated to the returned slot; should not be
- * NULL. It serves as a key to determine the correct owner of the slot
- * @return the time slot index in the array of time slots in the controller
- * handle
- */
-unsigned int
-GNUNET_TESTBED_get_tslot_ (struct GNUNET_TESTBED_Host *h, void *key)
-{
- unsigned int slot;
-
- GNUNET_assert (NULL != h->tslots);
- GNUNET_assert (NULL != key);
- for (slot = 0; slot < h->num_parallel_connects; slot++)
- if (NULL == h->tslots[slot].key)
- {
- h->tslots[slot].key = key;
- return slot;
- }
- GNUNET_assert (0); /* We should always find a free tslot */
-}
-
-
-/**
- * Decides whether any change in the number of parallel overlay connects is
- * necessary to adapt to the load on the system
- *
- * @param h the host handle
- */
-static void
-decide_npoc (struct GNUNET_TESTBED_Host *h)
-{
- struct GNUNET_TIME_Relative avg;
- int sd;
- unsigned int slot;
- unsigned int nvals;
-
- if (h->tslots_filled != h->num_parallel_connects)
- return;
- avg = GNUNET_TIME_UNIT_ZERO;
- nvals = 0;
- for (slot = 0; slot < h->num_parallel_connects; slot++)
- {
- avg = GNUNET_TIME_relative_add (avg, h->tslots[slot].time);
- nvals += h->tslots[slot].nvals;
- }
- GNUNET_assert (nvals >= h->num_parallel_connects);
- avg = GNUNET_TIME_relative_divide (avg, nvals);
- GNUNET_assert (GNUNET_TIME_UNIT_FOREVER_REL.rel_value != avg.rel_value);
- sd = GNUNET_TESTBED_SD_deviation_factor_ (h->poc_sd, (unsigned int) avg.rel_value);
- if ( (sd <= 5) ||
- (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
- h->num_parallel_connects)) )
- GNUNET_TESTBED_SD_add_data_ (h->poc_sd, (unsigned int) avg.rel_value);
- if (GNUNET_SYSERR == sd)
- {
- GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h,
- h->num_parallel_connects);
- return;
- }
- GNUNET_assert (0 <= sd);
- if (0 == sd)
- {
- GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h,
- h->num_parallel_connects
- * 2);
- return;
- }
- if (1 == sd)
- {
- GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h,
- h->num_parallel_connects
- + 1);
- return;
- }
- if (1 == h->num_parallel_connects)
- {
- GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h, 1);
- return;
- }
- if (2 == sd)
- {
- GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h,
- h->num_parallel_connects
- - 1);
- return;
- }
- GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h,
- h->num_parallel_connects /
- 2);
-}
-
-
-/**
- * Releases a time slot thus making it available for be used again
- *
- * @param h the host handle
- * @param index the index of the the time slot
- * @param key the key to prove ownership of the timeslot
- * @return GNUNET_YES if the time slot is successfully removed; GNUNET_NO if the
- * time slot cannot be removed - this could be because of the index
- * greater than existing number of time slots or `key' being different
- */
-int
-GNUNET_TESTBED_release_time_slot_ (struct GNUNET_TESTBED_Host *h,
- unsigned int index, void *key)
-{
- struct TimeSlot *slot;
-
- GNUNET_assert (NULL != key);
- if (index >= h->num_parallel_connects)
- return GNUNET_NO;
- slot = &h->tslots[index];
- if (key != slot->key)
- return GNUNET_NO;
- slot->key = NULL;
- return GNUNET_YES;
-}
-
-
-/**
- * Function to update a time slot
- *
- * @param h the host handle
- * @param index the index of the time slot to update
- * @param key the key to identify ownership of the slot
- * @param time the new time
- * @param failed should this reading be treated as coming from a fail event
- */
-void
-GNUNET_TESTBED_update_time_slot_ (struct GNUNET_TESTBED_Host *h,
- unsigned int index, void *key,
- struct GNUNET_TIME_Relative time, int failed)
-{
- struct TimeSlot *slot;
-
- if (GNUNET_YES == failed)
- {
- if (1 == h->num_parallel_connects)
- {
- GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h, 1);
- return;
- }
- GNUNET_TESTBED_set_num_parallel_overlay_connects_ (h,
- h->num_parallel_connects
- - 1);
- }
- if (GNUNET_NO == GNUNET_TESTBED_release_time_slot_ (h, index, key))
- return;
- slot = &h->tslots[index];
- slot->nvals++;
- if (GNUNET_TIME_UNIT_ZERO.rel_value == slot->time.rel_value)
- {
- slot->time = time;
- h->tslots_filled++;
- decide_npoc (h);
- return;
- }
- slot->time = GNUNET_TIME_relative_add (slot->time, time);
-}
-
-