GNUnet  0.10.x
Go to the documentation of this file.
1 /*
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 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.
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
13  Affero General Public License for more details.
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <>.
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
29 #include "platform.h"
30 #include "gnunet-service-ats.h"
33 #include "ats.h"
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;
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,
115  }
116  else
117  {
118  struct GNUNET_MQ_Envelope *env;
120  env = GNUNET_MQ_msg_copy(&msg->header);
122  env);
123  }
124 }
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,
151  enum GNUNET_HELLO_AddressInfo local_address_info,
152  struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
153  struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
154 {
155  GNUNET_break((NULL == prop) ||
156  (GNUNET_NT_UNSPECIFIED != prop->scope));
157  notify_client(NULL,
158  peer,
159  plugin_name,
160  plugin_addr,
161  plugin_addr_len,
162  active,
163  prop,
164  local_address_info,
165  bandwidth_out,
166  bandwidth_in);
168  "# performance updates given to clients",
169  1,
170  GNUNET_NO);
171 }
188 static void
189 peerinfo_it(void *cls,
190  const struct GNUNET_PeerIdentity *id,
191  const char *plugin_name,
192  const void *plugin_addr,
193  size_t plugin_addr_len,
194  int active,
195  const struct GNUNET_ATS_Properties *prop,
196  enum GNUNET_HELLO_AddressInfo local_address_info,
197  struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
198  struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
199 {
200  struct GNUNET_SERVICE_Client *client = cls;
202  if (NULL == id)
203  return;
205  "Callback for peer `%s' plugin `%s' BW out %u, BW in %u \n",
206  GNUNET_i2s(id),
207  plugin_name,
208  (unsigned int)ntohl(bandwidth_out.value__),
209  (unsigned int)ntohl(bandwidth_in.value__));
211  notify_client(client,
212  id,
213  plugin_name,
214  plugin_addr,
215  plugin_addr_len,
216  active,
217  prop,
218  local_address_info,
219  bandwidth_out,
220  bandwidth_in);
221 }
230 void
232  enum StartFlag flag)
233 {
234  struct GNUNET_MQ_Handle *mq;
236  mq = GNUNET_SERVICE_client_get_mq(client);
238  {
240  mq);
242  &peerinfo_it,
243  client);
244  }
245  else
246  {
248  mq);
249  }
250 }
258 void
260 {
261  nc_no_pic = GNUNET_notification_context_create(32);
263 }
269 void
271 {
273  nc_no_pic = NULL;
275  nc_pic = NULL;
276 }
278 /* 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:651
The notification context is the key datastructure for a convenience API used for transmission of noti...
Definition: nc.c:74
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
uint16_t address_length
Definition: ats.h:280
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
Definition: service.c:2424
static struct GNUNET_NotificationContext * nc_no_pic
Context for sending messages to performance clients without PIC.
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:310
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:285
struct GNUNET_MessageHeader header
Definition: ats.h:275
uint32_t address_local_info
Local-only information of the address, see enum GNUNET_HELLO_AddressInfo.
Definition: ats.h:321
#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.
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:158
ATS performance characteristics for an address.
struct GNUNET_ATS_PropertiesNBO properties
Performance properties of the address.
Definition: ats.h:315
#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:290
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:246
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:305
static char buf[2048]
void GAS_performance_add_client(struct GNUNET_SERVICE_Client *client, enum StartFlag flag)
Register a new performance client.
static char * plugin_name
Solver plugin name as string.
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
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:119
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:84
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:187
The identity of the host (wraps the signing key of the peer).
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:135
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:351
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:295
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).
automatic transport selection messages
Performance monitoring client that wants to learn about changes in performance characteristics.
Definition: ats.h:47
Category of last resort.
Definition: gnunet_nt_lib.h:39