From 7610732f7dc73ec59c5768b707f75cde484e877f Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 17 Oct 2011 07:03:29 +0000 Subject: [PATCH] send performance info to clients --- src/ats/gnunet-service-ats_addresses.c | 4 ++ src/ats/gnunet-service-ats_performance.c | 55 ++++++++++++++++++++++++ src/ats/gnunet-service-ats_performance.h | 24 +++++++++++ 3 files changed, 83 insertions(+) diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 3d296dcf6..dcb107590 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c @@ -271,6 +271,10 @@ GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer) aa->session_client, aa->session_id, aa->ats, aa->ats_count, aa->bw_out, aa->bw_in); + GAS_performance_notify_clients (peer, aa->plugin, + aa->addr, aa->addr_len, + aa->ats, aa->ats_count, + aa->bw_out, aa->bw_in); } diff --git a/src/ats/gnunet-service-ats_performance.c b/src/ats/gnunet-service-ats_performance.c index 1089b6a6d..8a1ad611c 100644 --- a/src/ats/gnunet-service-ats_performance.c +++ b/src/ats/gnunet-service-ats_performance.c @@ -133,6 +133,61 @@ GAS_performance_remove_client (struct GNUNET_SERVER_Client *client) } +/** + * Transmit the given performance information to all performance + * clients. + * + * @param peer peer for which this is an address suggestion + * @param plugin_name 0-termintated string specifying the transport plugin + * @param plugin_addr binary address for the plugin to use + * @param plugin_addr_len number of bytes in plugin_addr + * @param atsi performance data for the address + * @param atsi_count number of performance records in 'ats' + * @param bandwidth_out assigned outbound bandwidth + * @param bandwidth_in assigned inbound bandwidth + */ +void +GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer, + const char *plugin_name, + const void *plugin_addr, size_t plugin_addr_len, + const struct GNUNET_TRANSPORT_ATS_Information *atsi, + uint32_t atsi_count, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) +{ + struct PerformanceClient *pc; + struct PeerInformationMessage *msg; + size_t plugin_name_length = strlen (plugin_name) + 1; + size_t msize = sizeof (struct PeerInformationMessage) + atsi_count * sizeof (struct GNUNET_TRANSPORT_ATS_Information) + + plugin_addr_len + plugin_name_length; + char buf[msize]; + struct GNUNET_TRANSPORT_ATS_Information *atsp; + char *addrp; + + GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); + GNUNET_assert (atsi_count < GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_TRANSPORT_ATS_Information)); + msg = (struct PeerInformationMessage*) buf; + msg->header.size = htons (msize); + msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION); + msg->ats_count = htonl (atsi_count); + msg->peer = *peer; + msg->address_length = htons (plugin_addr_len); + msg->plugin_name_length = htons (plugin_name_length); + msg->bandwidth_out = bandwidth_out; + msg->bandwidth_in = bandwidth_in; + atsp = (struct GNUNET_TRANSPORT_ATS_Information* ) &msg[1]; + memcpy (atsp, atsi, sizeof (struct GNUNET_TRANSPORT_ATS_Information) * atsi_count); + addrp = (char*) &atsp[atsi_count]; + memcpy (addrp, plugin_addr, plugin_addr_len); + strcpy (&addrp[plugin_addr_len], plugin_name); + for (pc = pc_head; pc != NULL; pc = pc->next) + GNUNET_SERVER_notification_context_unicast (nc, + pc->client, + &msg->header, + GNUNET_YES); +} + + /** * Handle 'reservation request' messages from clients. * diff --git a/src/ats/gnunet-service-ats_performance.h b/src/ats/gnunet-service-ats_performance.h index 79ffeb5b3..6dfd11202 100644 --- a/src/ats/gnunet-service-ats_performance.h +++ b/src/ats/gnunet-service-ats_performance.h @@ -28,6 +28,7 @@ #define GNUNET_SERVICE_ATS_PERFORMANCE_H #include "gnunet_util_lib.h" +#include "gnunet_transport_service.h" // FIXME #include "ats.h" /** @@ -51,6 +52,29 @@ void GAS_performance_remove_client (struct GNUNET_SERVER_Client *client); +/** + * Transmit the given performance information to all performance + * clients. + * + * @param peer peer for which this is an address suggestion + * @param plugin_name 0-termintated string specifying the transport plugin + * @param plugin_addr binary address for the plugin to use + * @param plugin_addr_len number of bytes in plugin_addr + * @param atsi performance data for the address + * @param atsi_count number of performance records in 'ats' + * @param bandwidth_out assigned outbound bandwidth + * @param bandwidth_in assigned inbound bandwidth + */ +void +GAS_performance_notify_clients (const struct GNUNET_PeerIdentity *peer, + const char *plugin_name, + const void *plugin_addr, size_t plugin_addr_len, + const struct GNUNET_TRANSPORT_ATS_Information *atsi, + uint32_t atsi_count, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in); + + /** * Handle 'reservation request' messages from clients. * -- 2.25.1