*/
struct GNUNET_TIME_Relative GSF_avg_latency = { 500 };
+/**
+ * Handle to ATS service.
+ */
+struct GNUNET_ATS_PerformanceHandle *GSF_ats;
+
+
/**
* Typical priorities we're seeing from other peers right now. Since
* most priorities will be zero, this value is the weighted average of
/**
* We've received peer performance information. Update
* our running average for the P2P latency.
- *
- * @param atsi performance information
- * @param atsi_count number of 'atsi' records
+*
+ * @param cls closure
+ * @param address the address
+ * @param bandwidth_out assigned outbound bandwidth for the connection
+ * @param bandwidth_in assigned inbound bandwidth for the connection
+ * @param ats performance data for the address (as far as known)
+ * @param ats_count number of performance records in 'ats'
*/
static void
-update_latencies (const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+update_latencies (void *cls,
+ const struct GNUNET_HELLO_Address *address,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
+ struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
+ const struct GNUNET_ATS_Information *ats,
+ uint32_t ats_count)
{
unsigned int i;
+ struct GNUNET_TIME_Relative latency;
- for (i = 0; i < atsi_count; i++)
+ // FIXME: if (GNUNET_YES != current_address) return;
+ for (i = 0; i < ats_count; i++)
{
- if (ntohl (atsi[i].type) == GNUNET_ATS_QUALITY_NET_DELAY)
- {
- GSF_avg_latency.rel_value =
- (GSF_avg_latency.rel_value * 31 +
- GNUNET_MIN (5000, ntohl (atsi[i].value))) / 32;
- GNUNET_STATISTICS_set (GSF_stats,
- gettext_noop
- ("# running average P2P latency (ms)"),
- GSF_avg_latency.rel_value, GNUNET_NO);
- break;
- }
+ if (GNUNET_ATS_QUALITY_NET_DELAY != ntohl (ats[i].type))
+ continue;
+ latency.rel_value = ntohl (ats[i].value);
+ GSF_update_peer_latency_ (&address->peer,
+ latency);
+ GSF_avg_latency.rel_value =
+ (GSF_avg_latency.rel_value * 31 +
+ GNUNET_MIN (5000, ntohl (ats[i].value))) / 32;
+ GNUNET_STATISTICS_set (GSF_stats,
+ gettext_noop
+ ("# running average P2P latency (ms)"),
+ GSF_avg_latency.rel_value, GNUNET_NO);
+ break;
}
}
return GNUNET_OK;
}
GSF_cover_content_count++;
- fprintf (stderr, "FIX ATS DATA: %s:%u!\n", __FILE__, __LINE__);
- update_latencies (NULL, 0);
return GSF_handle_p2p_content_ (cp, message);
}
return GNUNET_SYSERR;
GSF_pending_request_get_data_ (pr)->has_started = GNUNET_YES;
GSF_local_lookup_ (pr, &consider_forwarding, NULL);
- fprintf (stderr, "FIX ATS DATA: %s:%u!\n", __FILE__, __LINE__);
- update_latencies (NULL, 0);
return GNUNET_OK;
}
GNUNET_CORE_disconnect (GSF_core);
GSF_core = NULL;
}
+ if (NULL != GSF_ats)
+ {
+ GNUNET_ATS_performance_done (GSF_ats);
+ GSF_ats = NULL;
+ }
GSF_put_done_ ();
GSF_push_done_ ();
GSF_pending_request_done_ ();
if (0 == memcmp (&my_id, peer, sizeof (struct GNUNET_PeerIdentity)))
return;
- fprintf (stderr, "FIX ATS DATA: %s:%u!\n", __FILE__, __LINE__);
- cp = GSF_peer_connect_handler_ (peer, NULL, 0);
+ cp = GSF_peer_connect_handler_ (peer);
if (NULL == cp)
return;
GSF_iterate_pending_requests_ (&consider_peer_for_forwarding, cp);
GSF_plan_init ();
GSF_pending_request_init_ ();
GSF_connected_peer_init_ ();
+ GSF_ats = GNUNET_ATS_performance_init (GSF_cfg, &update_latencies, NULL);
GSF_push_init_ ();
GSF_put_init_ ();
if ((GNUNET_OK != GNUNET_FS_indexing_init (cfg, GSF_dsh)) ||
*/
#include "platform.h"
#include "gnunet_load_lib.h"
-#include "gnunet_ats_service.h"
#include "gnunet-service-fs.h"
#include "gnunet-service-fs_cp.h"
#include "gnunet-service-fs_pe.h"
*/
static char *respectDirectory;
-/**
- * Handle to ATS service.
- */
-static struct GNUNET_ATS_PerformanceHandle *ats;
-
/**
* Get the filename under which we would store respect
/**
- * Find latency information in 'atsi'.
+ * Update the latency information kept for the given peer.
*
- * @param atsi performance data
- * @param atsi_count number of records in 'atsi'
- * @return connection latency
+ * @param id peer record to update
+ * @param latency current latency value
*/
-static struct GNUNET_TIME_Relative
-get_latency (const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count)
-{
- unsigned int i;
-
- for (i = 0; i < atsi_count; i++)
- if (ntohl (atsi->type) == GNUNET_ATS_QUALITY_NET_DELAY)
- return GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
- ntohl (atsi->value));
- return GNUNET_TIME_UNIT_SECONDS;
-}
-
-
-/**
- * Update the performance information kept for the given peer.
- *
- * @param cp peer record to update
- * @param atsi transport performance data
- * @param atsi_count number of records in 'atsi'
- */
-static void
-update_atsi (struct GSF_ConnectedPeer *cp,
- const struct GNUNET_ATS_Information *atsi, unsigned int atsi_count)
+void
+GSF_update_peer_latency_ (const struct GNUNET_PeerIdentity *id,
+ struct GNUNET_TIME_Relative latency)
{
- struct GNUNET_TIME_Relative latency;
+ struct GSF_ConnectedPeer *cp;
- latency = get_latency (atsi, atsi_count);
+ cp = GSF_peer_get_ (id);
GNUNET_LOAD_value_set_decline (cp->ppd.transmission_delay, latency);
/* LATER: merge atsi into cp's performance data (if we ever care...) */
}
if (0 != cp->inc_preference)
{
- GNUNET_ATS_change_preference (ats, &target, GNUNET_ATS_PREFERENCE_BANDWIDTH,
+ GNUNET_ATS_change_preference (GSF_ats, &target, GNUNET_ATS_PREFERENCE_BANDWIDTH,
(double) cp->inc_preference,
GNUNET_ATS_PREFERENCE_END);
cp->inc_preference = 0;
/* reservation already done! */
pth->was_reserved = GNUNET_YES;
cp->rc =
- GNUNET_ATS_reserve_bandwidth (ats, &target, DBLOCK_SIZE,
+ GNUNET_ATS_reserve_bandwidth (GSF_ats, &target, DBLOCK_SIZE,
&ats_reserve_callback, cp);
return;
}
GNUNET_PEER_resolve (cp->ppd.pid, &target);
cp->rc_delay_task = GNUNET_SCHEDULER_NO_TASK;
cp->rc =
- GNUNET_ATS_reserve_bandwidth (ats, &target, DBLOCK_SIZE,
- &ats_reserve_callback, cp);
+ GNUNET_ATS_reserve_bandwidth (GSF_ats, &target, DBLOCK_SIZE,
+ &ats_reserve_callback, cp);
}
* records.
*
* @param peer identity of peer that connected
- * @param atsi performance data for the connection
- * @param atsi_count number of records in 'atsi'
* @return handle to connected peer entry
*/
struct GSF_ConnectedPeer *
-GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer,
- const struct GNUNET_ATS_Information *atsi,
- unsigned int atsi_count)
+GSF_peer_connect_handler_ (const struct GNUNET_PeerIdentity *peer)
{
struct GSF_ConnectedPeer *cp;
char *fn;
cp->ppd.pid = GNUNET_PEER_intern (peer);
cp->ppd.transmission_delay = GNUNET_LOAD_value_init (GNUNET_TIME_UNIT_ZERO);
cp->rc =
- GNUNET_ATS_reserve_bandwidth (ats, peer, DBLOCK_SIZE,
+ GNUNET_ATS_reserve_bandwidth (GSF_ats, peer, DBLOCK_SIZE,
&ats_reserve_callback, cp);
fn = get_respect_filename (peer);
if ((GNUNET_YES == GNUNET_DISK_file_test (fn)) &&
GNUNET_STATISTICS_set (GSF_stats, gettext_noop ("# peers connected"),
GNUNET_CONTAINER_multihashmap_size (cp_map),
GNUNET_NO);
- update_atsi (cp, atsi, atsi_count);
GSF_push_start_ (cp);
return cp;
}
cp->mig_revive_task =
GNUNET_SCHEDULER_add_delayed (bt, &revive_migration, cp);
}
- fprintf (stderr, "FIX ATS DATA: %s:%u!\n", __FILE__, __LINE__);
- update_atsi (cp, NULL, 0);
return GNUNET_OK;
}
GSF_connected_peer_init_ ()
{
cp_map = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_YES);
- ats = GNUNET_ATS_performance_init (GSF_cfg, NULL, NULL);
GNUNET_assert (GNUNET_OK ==
GNUNET_CONFIGURATION_get_value_filename (GSF_cfg, "fs",
"RESPECT",
cp_map = NULL;
GNUNET_free (respectDirectory);
respectDirectory = NULL;
- GNUNET_ATS_performance_done (ats);
- ats = NULL;
}