2 This file is part of GNUnet.
3 Copyright (C) 2011-2015 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file ats/gnunet-service-ats_performance.c
22 * @brief ats service, interaction with 'performance' API
23 * @author Matthias Wachs
24 * @author Christian Grothoff
27 #include "gnunet-service-ats.h"
28 #include "gnunet-service-ats_addresses.h"
29 #include "gnunet-service-ats_performance.h"
34 * Context for sending messages to performance clients without PIC.
36 static struct GNUNET_SERVER_NotificationContext *nc_no_pic;
39 * Context for sending messages to performance clients with PIC.
41 static struct GNUNET_SERVER_NotificationContext *nc_pic;
45 * Transmit the given performance information to all performance
48 * @param pc client to send to, NULL for all
49 * @param peer peer for which this is an address suggestion
50 * @param plugin_name 0-termintated string specifying the transport plugin
51 * @param plugin_addr binary address for the plugin to use
52 * @param plugin_addr_len number of bytes in plugin_addr
53 * @param active #GNUNET_YES if this address is actively used
54 * to maintain a connection to a peer;
55 * #GNUNET_NO if the address is not actively used;
56 * #GNUNET_SYSERR if this address is no longer available for ATS
57 * @param prop performance data for the address
58 * @param bandwidth_out assigned outbound bandwidth
59 * @param bandwidth_in assigned inbound bandwidth
62 notify_client (struct GNUNET_SERVER_Client *client,
63 const struct GNUNET_PeerIdentity *peer,
64 const char *plugin_name,
65 const void *plugin_addr,
66 size_t plugin_addr_len,
68 const struct GNUNET_ATS_Properties *prop,
69 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
70 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
72 struct PeerInformationMessage *msg;
73 size_t plugin_name_length = strlen (plugin_name) + 1;
75 sizeof (struct PeerInformationMessage) +
78 char buf[msize] GNUNET_ALIGN;
79 struct GNUNET_SERVER_NotificationContext *nc;
82 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
83 msg = (struct PeerInformationMessage *) buf;
84 msg->header.size = htons (msize);
85 msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION);
88 msg->address_length = htons (plugin_addr_len);
89 msg->address_active = ntohl ((uint32_t) active);
90 msg->plugin_name_length = htons (plugin_name_length);
91 msg->bandwidth_out = bandwidth_out;
92 msg->bandwidth_in = bandwidth_in;
93 GNUNET_ATS_properties_hton (&msg->properties,
95 addrp = (char *) &msg[1];
96 memcpy (addrp, plugin_addr, plugin_addr_len);
97 strcpy (&addrp[plugin_addr_len], plugin_name);
100 GNUNET_SERVER_notification_context_broadcast (nc_pic,
106 nc = *GNUNET_SERVER_client_get_user_context (client,
107 struct GNUNET_SERVER_NotificationContext *);
113 GNUNET_SERVER_notification_context_unicast (nc,
122 * Transmit the given performance information to all performance
125 * @param peer peer for which this is an address suggestion
126 * @param plugin_name 0-termintated string specifying the transport plugin
127 * @param plugin_addr binary address for the plugin to use
128 * @param plugin_addr_len number of bytes in @a plugin_addr
129 * @param active #GNUNET_YES if this address is actively used
130 * to maintain a connection to a peer;
131 * #GNUNET_NO if the address is not actively used;
132 * #GNUNET_SYSERR if this address is no longer available for ATS
133 * @param prop performance data for the address
134 * @param bandwidth_out assigned outbound bandwidth
135 * @param bandwidth_in assigned inbound bandwidth
138 GAS_performance_notify_all_clients (const struct GNUNET_PeerIdentity *peer,
139 const char *plugin_name,
140 const void *plugin_addr,
141 size_t plugin_addr_len,
143 const struct GNUNET_ATS_Properties *prop,
144 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
145 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
156 GNUNET_STATISTICS_update (GSA_stats,
157 "# performance updates given to clients",
164 * Iterator for called from #GAS_addresses_get_peer_info()
166 * @param cls closure with the `struct GNUNET_SERVER_Client *` to inform.
167 * @param id the peer id
168 * @param plugin_name plugin name
169 * @param plugin_addr address
170 * @param plugin_addr_len length of @a plugin_addr
171 * @param active is address actively used
172 * @param prop performance information
173 * @param bandwidth_out current outbound bandwidth assigned to address
174 * @param bandwidth_in current inbound bandwidth assigned to address
177 peerinfo_it (void *cls,
178 const struct GNUNET_PeerIdentity *id,
179 const char *plugin_name,
180 const void *plugin_addr,
181 size_t plugin_addr_len,
183 const struct GNUNET_ATS_Properties *prop,
184 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
185 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
187 struct GNUNET_SERVER_Client *client = cls;
191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
192 "Callback for peer `%s' plugin `%s' BW out %u, BW in %u \n",
195 (unsigned int) ntohl (bandwidth_out.value__),
196 (unsigned int) ntohl (bandwidth_in.value__));
197 notify_client (client,
210 * Register a new performance client.
212 * @param client handle of the new client
213 * @param flag flag specifying the type of the client
216 GAS_performance_add_client (struct GNUNET_SERVER_Client *client,
219 if (START_FLAG_PERFORMANCE_WITH_PIC == flag)
221 GNUNET_SERVER_notification_context_add (nc_pic,
223 GNUNET_SERVER_client_set_user_context (client,
225 GAS_addresses_get_peer_info (NULL,
231 GNUNET_SERVER_notification_context_add (nc_no_pic,
233 GNUNET_SERVER_client_set_user_context (client,
240 * Initialize performance subsystem.
242 * @param server handle to our server
245 GAS_performance_init (struct GNUNET_SERVER_Handle *server)
247 nc_no_pic = GNUNET_SERVER_notification_context_create (server, 32);
248 nc_pic = GNUNET_SERVER_notification_context_create (server, 32);
253 * Shutdown performance subsystem.
256 GAS_performance_done ()
258 GNUNET_SERVER_notification_context_destroy (nc_no_pic);
260 GNUNET_SERVER_notification_context_destroy (nc_pic);
264 /* end of gnunet-service-ats_performance.c */