- 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);
-#if DEBUG_TOPOLOGY
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Asking to connect to `%s'\n",
- GNUNET_i2s (&pos->pid));
-#endif
- GNUNET_STATISTICS_update (stats,
- gettext_noop ("# connect requests issued to core"),
- 1,
- GNUNET_NO);
- pos->connect_req = GNUNET_CORE_peer_request_connect (handle,
- &pos->pid,
- &connect_completed_callback,
- 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)
- {
- attempt_connect (pos);
- }
- else
- {
- pos->greylist_clean_task
- = GNUNET_SCHEDULER_add_delayed (rem,
- &remove_from_greylist,
- pos);
- }
- if ( (GNUNET_NO == pos->is_friend) &&
- (GNUNET_NO == pos->is_connected) &&
- (NULL == pos->hello) )
- {
- free_peer (NULL, &pos->pid.hashPubKey, pos);
- return;
- }
+ strength = 0;
+ if ( (friend_count < minimum_friend_count) ||
+ (GNUNET_YES == friends_only) )
+ {
+ if (pos->is_friend)
+ strength += 10; /* urgently needed */
+ else
+ strength = 0; /* disallowed */
+ }
+ if (pos->is_friend)
+ strength *= 2; /* friends always count more */
+ if (NULL != pos->mq)
+ strength *= 2; /* existing connections preferred */
+ if (strength == pos->strength)
+ return; /* nothing to do */
+ if (NULL != pos->sh)
+ {
+ GNUNET_ATS_connectivity_suggest_cancel (pos->sh);
+ pos->sh = NULL;
+ }
+ pos->strength = strength;
+ if (0 != strength)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Asking to connect to `%s' with strength %u\n",
+ GNUNET_i2s (&pos->pid),
+ (unsigned int) strength);
+ GNUNET_STATISTICS_update (stats,
+ gettext_noop ("# connect requests issued to ATS"),
+ 1,
+ GNUNET_NO);
+ pos->sh = GNUNET_ATS_connectivity_suggest (ats,
+ &pos->pid,
+ strength);
+ }