- rem = GREYLIST_AFTER_ATTEMPT;
- rem = GNUNET_TIME_relative_multiply (rem, connection_count);
- rem = GNUNET_TIME_relative_divide (rem, target_connection_count);
- if (pos->connect_attempts > 30)
- pos->connect_attempts = 30;
- rem = GNUNET_TIME_relative_multiply (rem, 1 << (++pos->connect_attempts));
- rem = GNUNET_TIME_relative_max (rem, GREYLIST_AFTER_ATTEMPT_MIN);
- rem = GNUNET_TIME_relative_min (rem, GREYLIST_AFTER_ATTEMPT_MAX);
- pos->greylisted_until = GNUNET_TIME_relative_to_absolute (rem);
- if (pos->greylist_clean_task != GNUNET_SCHEDULER_NO_TASK)
- GNUNET_SCHEDULER_cancel (pos->greylist_clean_task);
- pos->greylist_clean_task =
- GNUNET_SCHEDULER_add_delayed (rem, &remove_from_greylist, pos);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Asking to connect to `%s'\n",
- GNUNET_i2s (&pos->pid));
- GNUNET_STATISTICS_update (stats,
- gettext_noop
- ("# connect requests issued to transport"), 1,
- GNUNET_NO);
- GNUNET_TRANSPORT_try_connect (transport, &pos->pid);
-}
-
-
-/**
- * Try to connect to the specified peer.
- *
- * @param cls peer to connect to
- * @param tc scheduler context
- */
-static void
-do_attempt_connect (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- struct Peer *pos = cls;
- struct GNUNET_TIME_Relative delay;
-
- pos->attempt_connect_task = GNUNET_SCHEDULER_NO_TASK;
- if (GNUNET_YES == pos->is_connected)
- return;
- delay = GNUNET_TIME_absolute_get_remaining (next_connect_attempt);
- if (delay.rel_value > 0)
- {
- pos->attempt_connect_task = GNUNET_SCHEDULER_add_delayed (delay,
- &do_attempt_connect,
- pos);
- return;
- }
- next_connect_attempt = GNUNET_TIME_relative_to_absolute (MAX_CONNECT_FREQUENCY_DELAY);
- attempt_connect (pos);
-}
-
-
-/**
- * Schedule a task to try to connect to the specified peer.
- *
- * @param pos peer to connect to
- */
-static void
-schedule_attempt_connect (struct Peer *pos)
-{
- if (GNUNET_SCHEDULER_NO_TASK != pos->attempt_connect_task)
- return;
- pos->attempt_connect_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_absolute_get_remaining (next_connect_attempt),
- &do_attempt_connect,
- pos);
-}
-
-
-/**
- * Discard peer entries for greylisted peers
- * where the greylisting has expired.
- *
- * @param cls 'struct Peer' to greylist
- * @param tc scheduler context
- */
-static void
-remove_from_greylist (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- struct Peer *pos = cls;
- struct GNUNET_TIME_Relative rem;
-
- pos->greylist_clean_task = GNUNET_SCHEDULER_NO_TASK;
- rem = GNUNET_TIME_absolute_get_remaining (pos->greylisted_until);
- if (rem.rel_value == 0)