2 This file is part of GNUnet.
3 Copyright (C) 2011-2015 GNUnet e.V.
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., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, 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 * - simplify functions by passing a `struct GNUNET_HELLO_Address`
30 #include "gnunet-service-ats.h"
31 #include "gnunet-service-ats_addresses.h"
32 #include "gnunet-service-ats_performance.h"
37 * Context for sending messages to performance clients without PIC.
39 static struct GNUNET_SERVER_NotificationContext *nc_no_pic;
42 * Context for sending messages to performance clients with PIC.
44 static struct GNUNET_SERVER_NotificationContext *nc_pic;
48 * Transmit the given performance information to all performance
51 * @param pc client to send to, NULL for all
52 * @param peer peer for which this is an address suggestion
53 * @param plugin_name 0-termintated string specifying the transport plugin
54 * @param plugin_addr binary address for the plugin to use
55 * @param plugin_addr_len number of bytes in plugin_addr
56 * @param active #GNUNET_YES if this address is actively used
57 * to maintain a connection to a peer;
58 * #GNUNET_NO if the address is not actively used;
59 * #GNUNET_SYSERR if this address is no longer available for ATS
60 * @param prop performance data for the address
61 * @param local_address_info information about the local flags for the address
62 * @param bandwidth_out assigned outbound bandwidth
63 * @param bandwidth_in assigned inbound bandwidth
66 notify_client (struct GNUNET_SERVER_Client *client,
67 const struct GNUNET_PeerIdentity *peer,
68 const char *plugin_name,
69 const void *plugin_addr,
70 size_t plugin_addr_len,
72 const struct GNUNET_ATS_Properties *prop,
73 enum GNUNET_HELLO_AddressInfo local_address_info,
74 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
75 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
77 struct PeerInformationMessage *msg;
78 size_t plugin_name_length = strlen (plugin_name) + 1;
80 sizeof (struct PeerInformationMessage) +
83 char buf[msize] GNUNET_ALIGN;
84 struct GNUNET_SERVER_NotificationContext **uc;
85 struct GNUNET_SERVER_NotificationContext *nc;
89 GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope);
90 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
91 msg = (struct PeerInformationMessage *) buf;
92 msg->header.size = htons (msize);
93 msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION);
96 msg->address_length = htons (plugin_addr_len);
97 msg->address_active = ntohl ((uint32_t) active);
98 msg->plugin_name_length = htons (plugin_name_length);
99 msg->bandwidth_out = bandwidth_out;
100 msg->bandwidth_in = bandwidth_in;
102 GNUNET_ATS_properties_hton (&msg->properties,
105 memset (&msg->properties,
107 sizeof (struct GNUNET_ATS_Properties));
108 msg->address_local_info = htonl (local_address_info);
109 addrp = (char *) &msg[1];
110 memcpy (addrp, plugin_addr, plugin_addr_len);
111 strcpy (&addrp[plugin_addr_len], plugin_name);
114 GNUNET_SERVER_notification_context_broadcast (nc_pic,
120 uc = GNUNET_SERVER_client_get_user_context (client,
121 struct GNUNET_SERVER_NotificationContext *);
128 GNUNET_SERVER_notification_context_unicast (nc,
137 * Transmit the given performance information to all performance
140 * @param peer peer for which this is an address suggestion
141 * @param plugin_name 0-termintated string specifying the transport plugin
142 * @param plugin_addr binary address for the plugin to use
143 * @param plugin_addr_len number of bytes in @a plugin_addr
144 * @param active #GNUNET_YES if this address is actively used
145 * to maintain a connection to a peer;
146 * #GNUNET_NO if the address is not actively used;
147 * #GNUNET_SYSERR if this address is no longer available for ATS
148 * @param prop performance data for the address
149 * @param local_address_info information about the local flags for the address
150 * @param bandwidth_out assigned outbound bandwidth
151 * @param bandwidth_in assigned inbound bandwidth
154 GAS_performance_notify_all_clients (const struct GNUNET_PeerIdentity *peer,
155 const char *plugin_name,
156 const void *plugin_addr,
157 size_t plugin_addr_len,
159 const struct GNUNET_ATS_Properties *prop,
160 enum GNUNET_HELLO_AddressInfo local_address_info,
161 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
162 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
164 GNUNET_break ( (NULL == prop) ||
165 (GNUNET_ATS_NET_UNSPECIFIED != prop->scope) );
176 GNUNET_STATISTICS_update (GSA_stats,
177 "# performance updates given to clients",
184 * Iterator for called from #GAS_addresses_get_peer_info()
186 * @param cls closure with the `struct GNUNET_SERVER_Client *` to inform.
187 * @param id the peer id
188 * @param plugin_name plugin name
189 * @param plugin_addr address
190 * @param plugin_addr_len length of @a plugin_addr
191 * @param active is address actively used
192 * @param prop performance information
193 * @param local_address_info information about the local flags for the address
194 * @param bandwidth_out current outbound bandwidth assigned to address
195 * @param bandwidth_in current inbound bandwidth assigned to address
198 peerinfo_it (void *cls,
199 const struct GNUNET_PeerIdentity *id,
200 const char *plugin_name,
201 const void *plugin_addr,
202 size_t plugin_addr_len,
204 const struct GNUNET_ATS_Properties *prop,
205 enum GNUNET_HELLO_AddressInfo local_address_info,
206 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
207 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
209 struct GNUNET_SERVER_Client *client = cls;
213 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
214 "Callback for peer `%s' plugin `%s' BW out %u, BW in %u \n",
217 (unsigned int) ntohl (bandwidth_out.value__),
218 (unsigned int) ntohl (bandwidth_in.value__));
219 GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop->scope);
220 notify_client (client,
234 * Register a new performance client.
236 * @param client handle of the new client
237 * @param flag flag specifying the type of the client
240 GAS_performance_add_client (struct GNUNET_SERVER_Client *client,
243 if (START_FLAG_PERFORMANCE_WITH_PIC == flag)
245 GNUNET_SERVER_notification_context_add (nc_pic,
247 GNUNET_SERVER_client_set_user_context (client,
249 GAS_addresses_get_peer_info (NULL,
255 GNUNET_SERVER_notification_context_add (nc_no_pic,
257 GNUNET_SERVER_client_set_user_context (client,
264 * Initialize performance subsystem.
266 * @param server handle to our server
269 GAS_performance_init (struct GNUNET_SERVER_Handle *server)
271 nc_no_pic = GNUNET_SERVER_notification_context_create (server, 32);
272 nc_pic = GNUNET_SERVER_notification_context_create (server, 32);
277 * Shutdown performance subsystem.
280 GAS_performance_done ()
282 GNUNET_SERVER_notification_context_destroy (nc_no_pic);
284 GNUNET_SERVER_notification_context_destroy (nc_pic);
288 /* end of gnunet-service-ats_performance.c */