/** * Method called whenever a peer connects. * * @param cls closure * @param peer peer identity this notification is about * @param mq message queue for communicating with @a peer * @return our `struct Peer` for @a peer */ static void * connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_MQ_Handle *mq) { struct Peer *pos; uint64_t flags; const void *extra; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core told us that we are connecting to `%s'\n", GNUNET_i2s (peer)); if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) return NULL; extra = GNUNET_CORE_get_mq_options (GNUNET_YES, GNUNET_CORE_PRIO_BEST_EFFORT, &flags); GNUNET_MQ_set_options (mq, flags, extra); connection_count++; GNUNET_STATISTICS_set (stats, gettext_noop ("# peers connected"), connection_count, GNUNET_NO); pos = GNUNET_CONTAINER_multipeermap_get (peers, peer); if (NULL == pos) { pos = make_peer (peer, NULL, GNUNET_NO); } else { GNUNET_assert (NULL == pos->mq); } pos->mq = mq; if (pos->is_friend) { friend_count++; if ( (friend_count == minimum_friend_count) && (GNUNET_YES != friends_only) ) whitelist_peers (); GNUNET_STATISTICS_set (stats, gettext_noop ("# friends connected"), friend_count, GNUNET_NO); } reschedule_hellos (NULL, peer, pos); return pos; }
/** * Method called whenever a peer connects. * * @param cls closure * @param peer peer identity this notification is about * @param atsi performance data * @param atsi_count number of records in 'atsi' */ static void connect_notify (void *cls, const struct GNUNET_PeerIdentity *peer, const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count) { struct Peer *pos; GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Core told us that we are connecting to `%s'\n", GNUNET_i2s (peer)); if (0 == memcmp (&my_identity, peer, sizeof (struct GNUNET_PeerIdentity))) return; connection_count++; GNUNET_STATISTICS_set (stats, gettext_noop ("# peers connected"), connection_count, GNUNET_NO); pos = GNUNET_CONTAINER_multihashmap_get (peers, &peer->hashPubKey); if (NULL == pos) { pos = make_peer (peer, NULL, GNUNET_NO); GNUNET_break (GNUNET_OK == is_connection_allowed (pos)); } else { GNUNET_assert (GNUNET_NO == pos->is_connected); pos->greylisted_until.abs_value = 0; /* remove greylisting */ } pos->is_connected = GNUNET_YES; pos->connect_attempts = 0; /* re-set back-off factor */ if (pos->is_friend) { if ((friend_count == minimum_friend_count - 1) && (GNUNET_YES != friends_only)) whitelist_peers (); friend_count++; GNUNET_STATISTICS_set (stats, gettext_noop ("# friends connected"), friend_count, GNUNET_NO); } reschedule_hellos (NULL, &peer->hashPubKey, pos); }