GNUnet  0.19.4
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
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);
97  msg->bandwidth_out = bandwidth_out;
98  msg->bandwidth_in = bandwidth_in;
99  if (NULL != prop)
100  GNUNET_ATS_properties_hton (&msg->properties,
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 {
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_Handle * mq
Definition: 003.c:5
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
automatic transport selection messages
StartFlag
Flag used to indicate which type of client is connecting to the ATS service.
Definition: ats.h:38
@ START_FLAG_PERFORMANCE_WITH_PIC
Performance monitoring client that wants to learn about changes in performance characteristics.
Definition: ats.h:48
struct GNUNET_STATISTICS_Handle * GSA_stats
Handle for statistics.
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.
ats service address management
void GAS_performance_add_client(struct GNUNET_SERVICE_Client *client, enum StartFlag flag)
Register a new performance client.
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()
void GAS_performance_init()
Initialize performance subsystem.
void GAS_performance_done()
Shutdown performance subsystem.
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.
static struct GNUNET_NotificationContext * nc_pic
Context for sending messages to performance clients with PIC.
static struct GNUNET_NotificationContext * nc_no_pic
Context for sending messages to performance clients without PIC.
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.
ats service, interaction with 'performance' API
static char * plugin_name
Name of our plugin.
static char buf[2048]
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
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.
GNUNET_HELLO_AddressInfo
Additional local information about an address.
#define GNUNET_log(kind,...)
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to 'struct's.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
@ GNUNET_YES
@ GNUNET_NO
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
@ GNUNET_ERROR_TYPE_DEBUG
void GNUNET_notification_context_destroy(struct GNUNET_NotificationContext *nc)
Destroy the context, force disconnect for all subscribers.
Definition: nc.c:138
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:304
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:190
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:533
struct GNUNET_NotificationContext * GNUNET_notification_context_create(unsigned int queue_length)
Create a new notification context.
Definition: nc.c:122
void GNUNET_notification_context_add(struct GNUNET_NotificationContext *nc, struct GNUNET_MQ_Handle *mq)
Add a subscriber to the notification context.
Definition: nc.c:161
@ GNUNET_NT_UNSPECIFIED
Category of last resort.
Definition: gnunet_nt_lib.h:43
#define GNUNET_MESSAGE_TYPE_ATS_PEER_INFORMATION
Type of the 'struct PeerInformationMessage' sent by ATS to clients to inform about QoS for a particul...
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
Definition: service.c:2443
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
ATS performance characteristics for an address.
enum GNUNET_NetworkType scope
Which network scope does the respective address belong to? This property does not change.
32-bit bandwidth used for network exchange by GNUnet, in bytes per second.
uint32_t value__
The actual value (bytes per second).
Handle to a message queue.
Definition: mq.c:87
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
The notification context is the key datastructure for a convenience API used for transmission of noti...
Definition: nc.c:77
The identity of the host (wraps the signing key of the peer).
Handle to a client that is connected to a service.
Definition: service.c:252
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in
Definition: ats.h:318
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out
Definition: ats.h:313
uint16_t plugin_name_length
Definition: ats.h:293
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.