- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Considering connecting to peer `%s'\n",
- GNUNET_i2s (peer));
-#endif
- pos = friends;
- while (pos != NULL)
- {
- if (0 == memcmp (&pos->id, peer, sizeof (struct GNUNET_PeerIdentity)))
- {
- if (GNUNET_YES == pos->is_connected)
- {
-#if DEBUG_TOPOLOGY
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Already connected to peer `%s'\n",
- GNUNET_i2s (peer));
-#endif
- return;
- }
- if (GNUNET_TIME_absolute_get_remaining (pos->blacklisted_until).value > 0)
- {
-#if DEBUG_TOPOLOGY
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Already tried peer `%s' recently\n",
- GNUNET_i2s (peer));
-#endif
- return; /* peer still blacklisted */
- }
- if (GNUNET_YES == pos->is_friend)
- {
- attempt_connect (peer, pos);
- return;
- }
- }
- pos = pos->next;
- }
- if ( (GNUNET_YES == friends_only) ||
- (friend_count < minimum_friend_count) )
- {
-#if DEBUG_TOPOLOGY
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Peer `%s' is not a friend, and we currently only connect to friends\n",
- GNUNET_i2s (peer));
-#endif
- return;
- }
- attempt_connect (peer, NULL);
-}
-
-
-/**
- * Try to add more friends to our connection set.
- */
-static void
-try_add_friends ()
-{
- struct PeerList *pos;
-
-#if DEBUG_TOPOLOGY
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Considering all of our friends for new connections\n");
-#endif
- pos = friends;
- while (pos != NULL)
- {
- if ( (GNUNET_TIME_absolute_get_remaining (pos->blacklisted_until).value == 0) &&
- (GNUNET_YES == pos->is_friend) &&
- (GNUNET_YES != pos->is_connected) )
- attempt_connect (&pos->id, pos);
- pos = pos->next;
- }
-}
-
-
-/**
- * Discard peer entries for blacklisted peers
- * where the blacklisting has expired.
- */
-static void
-discard_old_blacklist_entries ()
-{
- struct PeerList *pos;
- struct PeerList *next;
- struct PeerList *prev;
-
- next = friends;
- prev = NULL;
- while (NULL != (pos = next))
- {
- next = pos->next;
- if ( (GNUNET_NO == pos->is_friend) &&
- (GNUNET_NO == pos->is_connected) &&
- (0 == GNUNET_TIME_absolute_get_remaining (pos->blacklisted_until).value) )
- {
- /* delete 'pos' from list */
-#if DEBUG_TOPOLOGY
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Deleting peer `%s' from our list (not connected, not a friend and blacklist expired)\n",
- GNUNET_i2s (&pos->id));
-#endif
- if (prev == NULL)
- friends = next;
- else
- prev->next = next;
- GNUNET_free (pos);
- }
- else
- {
- prev = pos;
- }
- }
-}
-
-
-/**
- * Find more peers that we should connect to and ask the
- * core to establish connections.
- */
-static void
-find_more_peers (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
-{
- if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN))
- {