-/**
- * Find a "good" address to use for a peer. If we already have an existing
- * address, we stick to it. Otherwise, we pick by lowest distance and then
- * by lowest latency.
- *
- * @param cls the 'struct ATS_Address**' where we store the result
- * @param key unused
- * @param value another 'struct ATS_Address*' to consider using
- * @return GNUNET_OK (continue to iterate)
- */
-static int
-find_address_it (void *cls, const struct GNUNET_HashCode * key, void *value)
-{
- struct ATS_Address **ap = cls;
- struct ATS_Address *aa = (struct ATS_Address *) value;
- struct ATS_Address *ab = *ap;
- struct GNUNET_TIME_Absolute now;
-
- now = GNUNET_TIME_absolute_get();
-
- if (aa->blocked_until.abs_value == GNUNET_TIME_absolute_max (now, aa->blocked_until).abs_value)
- {
- /* This address is blocked for suggestion */
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Address %p blocked for suggestion for %llu ms \n",
- aa,
- GNUNET_TIME_absolute_get_difference(now, aa->blocked_until).rel_value);
- return GNUNET_OK;
- }
-
- aa->block_interval = GNUNET_TIME_relative_add (aa->block_interval, ATS_BLOCKING_DELTA);
- aa->blocked_until = GNUNET_TIME_absolute_add (now, aa->block_interval);
-
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Address %p ready for suggestion, block interval now %llu \n", aa, aa->block_interval);
-
- /* FIXME this is a hack */
-
-
- if (NULL != ab)
- {
- if ((0 == strcmp (ab->plugin, "tcp")) &&
- (0 == strcmp (aa->plugin, "tcp")))
- {
- if ((0 != ab->addr_len) &&
- (0 == aa->addr_len))
- {
- /* saved address was an outbound address, but we have an inbound address */
- *ap = aa;
- return GNUNET_OK;
- }
- if (0 == ab->addr_len)
- {
- /* saved address was an inbound address, so do not overwrite */
- return GNUNET_OK;
- }
- }
- }
- /* FIXME end of hack */
-
- if (NULL == ab)
- {
- *ap = aa;
- return GNUNET_OK;
- }
- if ((ntohl (ab->assigned_bw_in.value__) == 0) &&
- (ntohl (aa->assigned_bw_in.value__) > 0))
- {
- /* stick to existing connection */
- *ap = aa;
- return GNUNET_OK;
- }
- if (ab->atsp_distance > aa->atsp_distance)
- {
- /* user shorter distance */
- *ap = aa;
- return GNUNET_OK;
- }
- if (ab->atsp_latency.rel_value > aa->atsp_latency.rel_value)
- {
- /* user lower latency */
- *ap = aa;
- return GNUNET_OK;
- }
- /* don't care */
- return GNUNET_OK;
-}
-
-