GNUnet  0.11.x
gnunet-service-ats_scheduling.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2011-2016 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  */
20 
27 #include "platform.h"
30 #include "ats.h"
31 
36 
37 
44 int
46 {
47  if (NULL != my_client)
48  {
50  "This ATS already has a scheduling client, refusing new scheduling client for now.\n");
51  return GNUNET_SYSERR;
52  }
53  my_client = client;
54  return GNUNET_OK;
55 }
56 
57 
64 void
66 {
67  if (my_client != client)
68  return;
70  my_client = NULL;
71 }
72 
73 
83 void
86  uint32_t session_id,
88  bandwidth_out,
90  bandwidth_in)
91 {
92  struct GNUNET_MQ_Envelope *env;
94 
95  if (NULL == my_client)
96  return;
98  "# address suggestions made",
99  1,
100  GNUNET_NO);
101  env = GNUNET_MQ_msg (msg,
103  msg->peer = *peer;
104  msg->session_id = htonl (session_id);
106  msg->bandwidth_in = bandwidth_in;
108  "ATS sends quota for peer `%s': (in/out) %u/%u\n",
109  GNUNET_i2s (peer),
110  (unsigned int) ntohl (bandwidth_in.value__),
111  (unsigned int) ntohl (bandwidth_out.value__));
113  env);
114 }
115 
116 
122 void
124 {
125  const char *address;
126  const char *plugin_name;
127  uint16_t address_length;
128  uint16_t plugin_name_length;
129  struct GNUNET_ATS_Properties prop;
130 
132  "Received `%s' message\n",
133  "ADDRESS_ADD");
134  address_length = ntohs (m->address_length);
135  plugin_name_length = ntohs (m->plugin_name_length);
136  address = (const char *) &m[1];
137  if (plugin_name_length != 0)
138  plugin_name = &address[address_length];
139  else
140  plugin_name = "";
142  "# addresses created",
143  1,
144  GNUNET_NO);
146  &m->properties);
148  GAS_addresses_add (&m->peer,
149  plugin_name,
150  address,
151  address_length,
152  ntohl (m->address_local_info),
153  ntohl (m->session_id),
154  &prop);
155 }
156 
157 
163 void
165 {
166  struct GNUNET_ATS_Properties prop;
167 
169  "# address updates received",
170  1,
171  GNUNET_NO);
173  &m->properties);
175  ntohl (m->session_id),
176  &prop);
177 }
178 
179 
185 void
187 {
188  struct GNUNET_MQ_Envelope *env;
190 
192  "Received `%s' message\n",
193  "ADDRESS_DESTROYED");
195  "# addresses destroyed",
196  1,
197  GNUNET_NO);
199  ntohl (m->session_id));
200  env = GNUNET_MQ_msg (srm,
202  srm->session_id = m->session_id;
203  srm->peer = m->peer;
205  env);
206 }
207 
208 
209 /* end of gnunet-service-ats_scheduling.c */
uint16_t address_length
Number of bytes in the address that follows this struct.
Definition: ats.h:121
void GAS_handle_address_destroyed(const struct AddressDestroyedMessage *m)
Handle &#39;address destroyed&#39; messages from clients.
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_PeerIdentity peer
Which peer is this about? (Technically redundant, as the session_id should be sufficient, but enables ATS service to find the session faster).
Definition: ats.h:178
void GAS_handle_address_update(const struct AddressUpdateMessage *m)
Handle &#39;address update&#39; messages from clients.
struct GNUNET_PeerIdentity peer
Identity of the peer that this address is for.
Definition: ats.h:131
struct GNUNET_ATS_PropertiesNBO properties
Performance properties of the address.
Definition: ats.h:148
struct GNUNET_MQ_Handle * GNUNET_SERVICE_client_get_mq(struct GNUNET_SERVICE_Client *c)
Obtain the message queue of c.
Definition: service.c:2437
struct GNUNET_PeerIdentity peer
Which peer is this about? (Technically redundant, as the session_id should be sufficient, but enables ATS service to find the session faster).
Definition: ats.h:209
#define GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION
Type of the &#39;struct AddressSuggestionMessage&#39; sent by ATS to clients to suggest switching to a differ...
uint32_t session_id
Number the client used to identify the session.
Definition: ats.h:227
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
static struct GNUNET_HashCode session_id
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in
How much bandwidth we are allowed for receiving.
Definition: ats.h:271
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out
How much bandwidth we are allowed for sending.
Definition: ats.h:266
uint32_t session_id
Internal number this client uses to refer to this address.
Definition: ats.h:202
void GAS_addresses_add(const struct GNUNET_PeerIdentity *peer, const char *plugin_name, const void *plugin_addr, size_t plugin_addr_len, uint32_t local_address_info, uint32_t session_id, const struct GNUNET_ATS_Properties *prop)
Add a new address for a peer.
void GAS_addresses_destroy_all()
Remove all addresses.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
struct GNUNET_STATISTICS_Handle * GSA_stats
Handle for statistics.
ATS performance characteristics for an address.
uint32_t session_id
Internal number this client uses to refer to the address this suggestion is about.
Definition: ats.h:254
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Message used to notify ATS that the performance characteristics for an address have changed...
Definition: ats.h:161
uint32_t value__
The actual value (bytes per second).
Handle to a client that is connected to a service.
Definition: service.c:250
struct GNUNET_PeerIdentity peer
Which peer is this about? (Technically redundant, as the session_id should be sufficient, but may enable client to find the session faster).
Definition: ats.h:234
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
#define GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE
Type of the &#39;struct SessionReleaseMessage&#39; sent by ATS to client to confirm that a session ID was des...
void GAS_scheduling_transmit_address_suggestion(const struct GNUNET_PeerIdentity *peer, uint32_t session_id, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
Transmit the given address suggestion and bandwidth update to all scheduling clients.
int GAS_scheduling_add_client(struct GNUNET_SERVICE_Client *client)
Register a new scheduling client.
void GAS_scheduling_remove_client(struct GNUNET_SERVICE_Client *client)
Unregister a client (which may have been a scheduling client, but this is not assured).
uint16_t plugin_name_length
Number of bytes in the plugin name that follows this struct.
Definition: ats.h:126
static struct GNUNET_SERVICE_Client * my_client
Actual handle to the client.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
void GAS_addresses_destroy(const struct GNUNET_PeerIdentity *peer, uint32_t session_id)
Remove an address for a peer.
32-bit bandwidth used for network exchange by GNUnet, in bytes per second.
ats service address management
ATS Service suggests to the transport service to use the address identified by the given session_id f...
Definition: ats.h:243
enum GNUNET_NetworkType scope
Which network scope does the respective address belong to? This property does not change...
void GAS_handle_address_add(const struct AddressAddMessage *m)
Handle &#39;address add&#39; messages from clients.
The identity of the host (wraps the signing key of the peer).
uint32_t address_local_info
Local-only information of the address, see enum GNUNET_HELLO_AddressInfo.
Definition: ats.h:143
void GNUNET_ATS_properties_ntoh(struct GNUNET_ATS_Properties *hbo, const struct GNUNET_ATS_PropertiesNBO *nbo)
Convert ATS properties from network to host byte order.
#define GNUNET_log(kind,...)
struct GNUNET_ATS_PropertiesNBO properties
Performance properties of the address.
Definition: ats.h:183
struct GNUNET_PeerIdentity peer
Which peer is this about? (Technically redundant, as the session_id should be sufficient, but may enable client to find the session faster and/or check consistency).
Definition: ats.h:261
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
ats service, interaction with &#39;scheduling&#39; API
Message sent by ATS client to ATS service when an address was destroyed and must thus henceforth no l...
Definition: ats.h:192
uint32_t session_id
Internal number this client will henceforth use to refer to this address.
Definition: ats.h:137
Message sent by ATS service to client to confirm that it is done using the given session ID...
Definition: ats.h:217
void GAS_addresses_update(const struct GNUNET_PeerIdentity *peer, uint32_t session_id, const struct GNUNET_ATS_Properties *prop)
Update an address with new performance information for a peer.
static char * address
GNS address for this phone.
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.
uint32_t session_id
Internal number this client uses to refer to this address.
Definition: ats.h:171
automatic transport selection messages
Category of last resort.
Definition: gnunet_nt_lib.h:40
Scheduling client to ATS service: here is another address you can use.
Definition: ats.h:111