From d33854b36c74e34a67e6b8de69fd462772bf9310 Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Thu, 21 Mar 2013 12:09:14 +0000 Subject: ats manipulation --- src/transport/gnunet-service-transport.c | 2 +- .../gnunet-service-transport_manipulation.c | 51 ++++++++-------------- .../gnunet-service-transport_manipulation.h | 2 +- 3 files changed, 21 insertions(+), 34 deletions(-) diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 8859e6ffc..da4bfbbf0 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c @@ -701,7 +701,7 @@ key_generation_cb (void *cls, &plugin_env_address_change_notification, &plugin_env_session_end, &plugin_env_address_to_type, - &GST_manipulation_update_metrics); + &GST_manipulation_metrics_recv); GST_neighbours_start (NULL, &neighbours_connect_notification, &neighbours_disconnect_notification, diff --git a/src/transport/gnunet-service-transport_manipulation.c b/src/transport/gnunet-service-transport_manipulation.c index e2bc69d0e..203a67771 100644 --- a/src/transport/gnunet-service-transport_manipulation.c +++ b/src/transport/gnunet-service-transport_manipulation.c @@ -356,7 +356,7 @@ GST_manipulation_send (const struct GNUNET_PeerIdentity *target, const void *msg * @return ATS Information containing the network type */ void -GST_manipulation_update_metrics (void *cls, +GST_manipulation_metrics_recv (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address, uint16_t address_len, @@ -364,24 +364,32 @@ GST_manipulation_update_metrics (void *cls, struct GNUNET_ATS_Information *ats, uint32_t ats_count) { -#if 0 + struct GNUNET_ATS_Information ats_new[ats_count]; struct TM_Peer *tmp; + uint32_t m_distance; + int d; - for (d = 0; d < ats_count; d++) + m_distance = 0; + if (NULL != (tmp = GNUNET_CONTAINER_multihashmap_get (man_handle.peers, &peer->hashPubKey))) { - ats_new[d] = ats[d]; - if ((ntohl(ats[d].type) == GNUNET_ATS_QUALITY_NET_DISTANCE) && - (man_handle.distance_recv > 0)) - ats_new[d].value = htonl(man_handle.distance_recv); /* Global inbound distance */ + if (UINT32_MAX != tmp->metrics[TM_RECEIVE][DISTANCE]) + m_distance = tmp->metrics[TM_RECEIVE][DISTANCE]; } - if (NULL != (tmp = GNUNET_CONTAINER_multihashmap_get (man_handle.peers, &peer->hashPubKey))) + for (d = 0; d < ats_count; d++) { - + ats_new[d] = ats[d]; + if (ntohl(ats[d].type) == GNUNET_ATS_QUALITY_NET_DISTANCE) + { + if (m_distance > 0) + ats_new[d].value = htonl(m_distance); + else if (man_handle.distance_recv > 0) + ats_new[d].value = htonl(man_handle.distance_recv); + } } -#endif - man_handle.metric_update_cb (cls, peer, address, address_len, session, ats, ats_count); + + man_handle.metric_update_cb (cls, peer, address, address_len, session, ats_new, ats_count); } struct GNUNET_TIME_Relative @@ -402,29 +410,8 @@ GST_manipulation_recv (void *cls, else m_delay = GNUNET_TIME_UNIT_ZERO; -#if 0 - for (d = 0; d < ats_count; d++) - { - ats_new[d] = ats[d]; - if ((ntohl(ats[d].type) == GNUNET_ATS_QUALITY_NET_DISTANCE) && - (man_handle.distance_recv > 0)) - ats_new[d].value = htonl(man_handle.distance_recv); /* Global inbound distance */ - } -#endif - if (NULL != (tmp = GNUNET_CONTAINER_multihashmap_get (man_handle.peers, &peer->hashPubKey))) { -#if 0 - /* Manipulate distance */ - for (d = 0; d < ats_count; d++) - { - ats_new[d] = ats[d]; - /* Set distance */ - if ((ntohl(ats[d].type) == GNUNET_ATS_QUALITY_NET_DISTANCE) && - (UINT32_MAX != tmp->metrics[TM_RECEIVE][DISTANCE])) - ats_new[d].value = htonl(tmp->metrics[TM_RECEIVE][DISTANCE]); - } -#endif /* Manipulate receive delay */ if (UINT32_MAX != tmp->metrics[TM_RECEIVE][DELAY]) m_delay.rel_value = tmp->metrics[TM_RECEIVE][DELAY]; /* Peer specific delay */ diff --git a/src/transport/gnunet-service-transport_manipulation.h b/src/transport/gnunet-service-transport_manipulation.h index 075580116..17a0a24f3 100644 --- a/src/transport/gnunet-service-transport_manipulation.h +++ b/src/transport/gnunet-service-transport_manipulation.h @@ -55,7 +55,7 @@ GST_manipulation_recv (void *cls, uint16_t sender_address_len); void -GST_manipulation_update_metrics (void *cls, +GST_manipulation_metrics_recv (void *cls, const struct GNUNET_PeerIdentity *peer, const char *address, uint16_t address_len, -- cgit v1.2.3