*
* @param cls closure
* @param peer the peer that connected
- * @param ats performance data
- * @param ats_count number of entries in ats (excluding 0-termination)
+ * @param atsi performance data
+ * @param atsi_count number of entries in ats (excluding 0-termination)
*/
static void
handle_transport_notify_connect (void *cls,
const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_ATS_Information
- *ats, uint32_t ats_count)
+ *atsi, uint32_t atsi_count)
{
struct Neighbour *n;
* @param cls closure
* @param peer (claimed) identity of the other peer
* @param message the message
- * @param ats performance data
- * @param ats_count number of entries in ats (excluding 0-termination)
+ * @param atsi performance data
+ * @param atsi_count number of entries in ats (excluding 0-termination)
*/
static void
handle_transport_receive (void *cls, const struct GNUNET_PeerIdentity *peer,
const struct GNUNET_MessageHeader *message,
- const struct GNUNET_ATS_Information *ats,
- uint32_t ats_count)
+ const struct GNUNET_ATS_Information *atsi,
+ uint32_t atsi_count)
{
struct Neighbour *n;
uint16_t type;
break;
case GNUNET_MESSAGE_TYPE_CORE_ENCRYPTED_MESSAGE:
GSC_KX_handle_encrypted_message (n->kxinfo,
- message, ats,
- ats_count);
+ message, atsi,
+ atsi_count);
break;
default:
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
*/
struct GNUNET_LOAD_Value *GSF_rt_entry_lifetime;
+/**
+ * Running average of the observed latency to other peers (round trip).
+ * Initialized to 5s as the initial default.
+ */
+struct GNUNET_TIME_Relative GSF_avg_latency = { 5000 };
+
/**
* 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 just now completed a datastore request. Update our
* datastore load calculations.
}
+/**
+ * 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
+ */
+static void
+update_latencies (const struct GNUNET_ATS_Information *atsi,
+ unsigned int atsi_count)
+{
+ unsigned int i;
+
+ for (i=0;i<atsi_count;i++)
+ {
+ if (ntohl(atsi[i].type) == GNUNET_ATS_QUALITY_NET_DELAY)
+ {
+ GSF_avg_latency.rel_value = (GSF_avg_latency.rel_value * 31 + 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;
+ }
+ }
+}
+
+
/**
* Handle P2P "PUT" message.
*
return GNUNET_OK;
}
GSF_cover_content_count++;
+ update_latencies (atsi, atsi_count);
return GSF_handle_p2p_content_ (cp, message);
}
if (NULL == pr)
return GNUNET_SYSERR;
GSF_local_lookup_ (pr, &consider_forwarding, NULL);
+ update_latencies (atsi, atsi_count);
return GNUNET_OK;
}
*/
extern struct GNUNET_LOAD_Value *GSF_rt_entry_lifetime;
+/**
+ * Running average of the observed latency to other peers (round trip).
+ */
+extern struct GNUNET_TIME_Relative GSF_avg_latency;
+
/**
* Typical priorities we're seeing from other peers right now. Since
* most priorities will be zero, this value is the weighted average of
{
struct GNUNET_TIME_Relative ret;
- /* FIXME: replace 5000 with something relating to current observed P2P message latency */
ret =
GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MILLISECONDS,
GNUNET_CRYPTO_random_u32
- (GNUNET_CRYPTO_QUALITY_WEAK, 5000));
+ (GNUNET_CRYPTO_QUALITY_WEAK,
+ 2 * GSF_avg_latency.rel_value + 1));
GNUNET_STATISTICS_update (GSF_stats,
gettext_noop
("# artificial delays introduced (ms)"),