GNUnet  0.11.x
gnunet-service-ats_performance.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2011-2015 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
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  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
29 #include "platform.h"
30 #include "gnunet-service-ats.h"
33 #include "ats.h"
34 
35 
40 
45 
46 
65 static void
67  const struct GNUNET_PeerIdentity *peer,
68  const char *plugin_name,
69  const void *plugin_addr,
70  size_t plugin_addr_len,
71  int active,
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)
76 {
78  size_t plugin_name_length = strlen (plugin_name) + 1;
79  size_t msize =
80  sizeof(struct PeerInformationMessage)
81  + plugin_addr_len
82  + plugin_name_length;
83  char buf[msize] GNUNET_ALIGN;
84  char *addrp;
85 
86  if (NULL != prop)
89  msg = (struct PeerInformationMessage *) buf;
90  msg->header.size = htons (msize);
92  msg->id = htonl (0);
93  msg->peer = *peer;
94  msg->address_length = htons (plugin_addr_len);
95  msg->address_active = ntohl ((uint32_t) active);
96  msg->plugin_name_length = htons (plugin_name_length);
99  if (NULL != prop)
101  prop);
102  else
103  memset (&msg->properties,
104  0,
105  sizeof(struct GNUNET_ATS_Properties));
106  msg->address_local_info = htonl (local_address_info);
107  addrp = (char *) &msg[1];
108  GNUNET_memcpy (addrp, plugin_addr, plugin_addr_len);
109  strcpy (&addrp[plugin_addr_len], plugin_name);
110  if (NULL == client)
111  {
113  &msg->header,
114  GNUNET_YES);
115  }
116  else
117  {
118  struct GNUNET_MQ_Envelope *env;
119 
120  env = GNUNET_MQ_msg_copy (&msg->header);
122  env);
123  }
124 }
125 
126 
144 void
146  const char *plugin_name,
147  const void *plugin_addr,
148  size_t plugin_addr_len,
149  int active,
150  const struct GNUNET_ATS_Properties *prop,
152  local_address_info,
154  bandwidth_out,
156  bandwidth_in)
157 {
158  GNUNET_break ((NULL == prop) ||
159  (GNUNET_NT_UNSPECIFIED != prop->scope));
160  notify_client (NULL,
161  peer,
162  plugin_name,
163  plugin_addr,
164  plugin_addr_len,
165  active,
166  prop,
167  local_address_info,
168  bandwidth_out,
169  bandwidth_in);
171  "# performance updates given to clients",
172  1,
173  GNUNET_NO);
174 }
175 
176 
191 static void
192 peerinfo_it (void *cls,
193  const struct GNUNET_PeerIdentity *id,
194  const char *plugin_name,
195  const void *plugin_addr,
196  size_t plugin_addr_len,
197  int active,
198  const struct GNUNET_ATS_Properties *prop,
199  enum GNUNET_HELLO_AddressInfo local_address_info,
200  struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
201  struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
202 {
203  struct GNUNET_SERVICE_Client *client = cls;
204 
205  if (NULL == id)
206  return;
208  "Callback for peer `%s' plugin `%s' BW out %u, BW in %u \n",
209  GNUNET_i2s (id),
210  plugin_name,
211  (unsigned int) ntohl (bandwidth_out.value__),
212  (unsigned int) ntohl (bandwidth_in.value__));
214  notify_client (client,
215  id,
216  plugin_name,
217  plugin_addr,
218  plugin_addr_len,
219  active,
220  prop,
221  local_address_info,
222  bandwidth_out,
223  bandwidth_in);
224 }
225 
226 
233 void
235  enum StartFlag flag)
236 {
237  struct GNUNET_MQ_Handle *mq;
238 
239  mq = GNUNET_SERVICE_client_get_mq (client);
241  {
243  mq);
245  &peerinfo_it,
246  client);
247  }
248  else
249  {
251  mq);
252  }
253 }
254 
255 
261 void
263 {
264  nc_no_pic = GNUNET_notification_context_create (32);
266 }
267 
268 
272 void
274 {
276  nc_no_pic = NULL;
278  nc_pic = NULL;
279 }
280 
281 
282 /* end of gnunet-service-ats_performance.c */
struct GNUNET_MQ_Envelope * GNUNET_MQ_msg_copy(const struct GNUNET_MessageHeader *hdr)
Create a new envelope by copying an existing message.
Definition: mq.c:653
The notification context is the key datastructure for a convenience API used for transmission of noti...
Definition: nc.c:75
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
uint16_t address_length
Definition: ats.h:288
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
Definition: service.c:2437
static struct GNUNET_NotificationContext * nc_no_pic
Context for sending messages to performance clients without PIC.
StartFlag
Flag used to indicate which type of client is connecting to the ATS service.
Definition: ats.h:37
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in
Definition: ats.h:318
void GNUNET_ATS_properties_hton(struct GNUNET_ATS_PropertiesNBO *nbo, const struct GNUNET_ATS_Properties *hbo)
Convert ATS properties from host to network byte order.
uint16_t plugin_name_length
Definition: ats.h:293
struct GNUNET_MessageHeader header
Type is GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION.
Definition: ats.h:283
uint32_t address_local_info
Local-only information of the address, see enum GNUNET_HELLO_AddressInfo.
Definition: ats.h:329
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_NO
Definition: gnunet_common.h:78
static void notify_client(struct GNUNET_SERVICE_Client *client, const struct GNUNET_PeerIdentity *peer, const char *plugin_name, const void *plugin_addr, size_t plugin_addr_len, int active, const struct GNUNET_ATS_Properties *prop, enum GNUNET_HELLO_AddressInfo local_address_info, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
Transmit the given performance information to all performance clients.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION
Type of the &#39;struct PeerInformationMessage&#39; sent by ATS to clients to inform about QoS for a particul...
struct GNUNET_STATISTICS_Handle * GSA_stats
Handle for statistics.
void GNUNET_notification_context_add(struct GNUNET_NotificationContext *nc, struct GNUNET_MQ_Handle *mq)
Add a subscriber to the notification context.
Definition: nc.c:160
ATS performance characteristics for an address.
struct GNUNET_ATS_PropertiesNBO properties
Performance properties of the address.
Definition: ats.h:323
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_PeerIdentity peer
Definition: ats.h:298
ats service, interaction with &#39;performance&#39; API
uint32_t value__
The actual value (bytes per second).
void GAS_performance_notify_all_clients(const struct GNUNET_PeerIdentity *peer, const char *plugin_name, const void *plugin_addr, size_t plugin_addr_len, int active, const struct GNUNET_ATS_Properties *prop, enum GNUNET_HELLO_AddressInfo local_address_info, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
Transmit the given performance information to all performance clients.
Handle to a client that is connected to a service.
Definition: service.c:250
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out
Definition: ats.h:313
static char buf[2048]
void GAS_performance_add_client(struct GNUNET_SERVICE_Client *client, enum StartFlag flag)
Register a new performance client.
void GAS_addresses_get_peer_info(const struct GNUNET_PeerIdentity *peer, GNUNET_ATS_PeerInfo_Iterator pi_it, void *pi_it_cls)
Return information all peers currently known to ATS.
void GAS_performance_init()
Initialize performance subsystem.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
static void peerinfo_it(void *cls, const struct GNUNET_PeerIdentity *id, const char *plugin_name, const void *plugin_addr, size_t plugin_addr_len, int active, const struct GNUNET_ATS_Properties *prop, enum GNUNET_HELLO_AddressInfo local_address_info, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
Iterator for called from GAS_addresses_get_peer_info()
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
32-bit bandwidth used for network exchange by GNUnet, in bytes per second.
ats service address management
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
struct GNUNET_NotificationContext * GNUNET_notification_context_create(unsigned int queue_length)
Create a new notification context.
Definition: nc.c:121
enum GNUNET_NetworkType scope
Which network scope does the respective address belong to? This property does not change...
Handle to a message queue.
Definition: mq.c:85
void GNUNET_notification_context_broadcast(struct GNUNET_NotificationContext *nc, const struct GNUNET_MessageHeader *msg, int can_drop)
Send a message to all subscribers of this context.
Definition: nc.c:189
The identity of the host (wraps the signing key of the peer).
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to &#39;struct&#39;s...
struct GNUNET_MQ_Handle * mq
Definition: 003.c:5
#define GNUNET_log(kind,...)
#define GNUNET_YES
Definition: gnunet_common.h:77
void GNUNET_notification_context_destroy(struct GNUNET_NotificationContext *nc)
Destroy the context, force disconnect for all subscribers.
Definition: nc.c:137
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:353
void GAS_performance_done()
Shutdown performance subsystem.
static struct GNUNET_NotificationContext * nc_pic
Context for sending messages to performance clients with PIC.
uint32_t address_active
Definition: ats.h:303
GNUNET_HELLO_AddressInfo
Additional local information about an address.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
static char * plugin_name
Name of our plugin.
automatic transport selection messages
Performance monitoring client that wants to learn about changes in performance characteristics.
Definition: ats.h:48
Category of last resort.
Definition: gnunet_nt_lib.h:40