2 This file is part of GNUnet.
3 Copyright (C) 2011-2016 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
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
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 <http://www.gnu.org/licenses/>.
18 SPDX-License-Identifier: AGPL3.0-or-later
22 * @file ats/gnunet-service-ats_scheduling.c
23 * @brief ats service, interaction with 'scheduling' API
24 * @author Matthias Wachs
25 * @author Christian Grothoff
28 #include "gnunet-service-ats_addresses.h"
29 #include "gnunet-service-ats_scheduling.h"
33 * Actual handle to the client.
35 static struct GNUNET_SERVICE_Client *my_client;
39 * Register a new scheduling client.
41 * @param client handle of the new client
42 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
45 GAS_scheduling_add_client (struct GNUNET_SERVICE_Client *client)
47 if (NULL != my_client)
49 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
50 "This ATS already has a scheduling client, refusing new scheduling client for now.\n");
59 * Unregister a client (which may have been a scheduling client,
60 * but this is not assured).
62 * @param client handle of the (now dead) client
65 GAS_scheduling_remove_client (struct GNUNET_SERVICE_Client *client)
67 if (my_client != client)
69 GAS_addresses_destroy_all ();
75 * Transmit the given address suggestion and bandwidth update to all scheduling
78 * @param peer peer for which this is an address suggestion
79 * @param session_id session ID to use for the given client
80 * @param bandwidth_out assigned outbound bandwidth
81 * @param bandwidth_in assigned inbound bandwidth
84 GAS_scheduling_transmit_address_suggestion (const struct
85 GNUNET_PeerIdentity *peer,
87 struct GNUNET_BANDWIDTH_Value32NBO
89 struct GNUNET_BANDWIDTH_Value32NBO
92 struct GNUNET_MQ_Envelope *env;
93 struct AddressSuggestionMessage *msg;
95 if (NULL == my_client)
97 GNUNET_STATISTICS_update (GSA_stats,
98 "# address suggestions made",
101 env = GNUNET_MQ_msg (msg,
102 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION);
104 msg->session_id = htonl (session_id);
105 msg->bandwidth_out = bandwidth_out;
106 msg->bandwidth_in = bandwidth_in;
107 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
108 "ATS sends quota for peer `%s': (in/out) %u/%u\n",
110 (unsigned int) ntohl (bandwidth_in.value__),
111 (unsigned int) ntohl (bandwidth_out.value__));
112 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (my_client),
118 * Handle 'address add' messages from clients.
120 * @param m the request message
123 GAS_handle_address_add (const struct AddressAddMessage *m)
126 const char *plugin_name;
127 uint16_t address_length;
128 uint16_t plugin_name_length;
129 struct GNUNET_ATS_Properties prop;
131 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
132 "Received `%s' message\n",
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];
141 GNUNET_STATISTICS_update (GSA_stats,
142 "# addresses created",
145 GNUNET_ATS_properties_ntoh (&prop,
147 GNUNET_break (GNUNET_NT_UNSPECIFIED != prop.scope);
148 GAS_addresses_add (&m->peer,
152 ntohl (m->address_local_info),
153 ntohl (m->session_id),
159 * Handle 'address update' messages from clients.
161 * @param m the request message
164 GAS_handle_address_update (const struct AddressUpdateMessage *m)
166 struct GNUNET_ATS_Properties prop;
168 GNUNET_STATISTICS_update (GSA_stats,
169 "# address updates received",
172 GNUNET_ATS_properties_ntoh (&prop,
174 GAS_addresses_update (&m->peer,
175 ntohl (m->session_id),
181 * Handle 'address destroyed' messages from clients.
183 * @param m the request message
186 GAS_handle_address_destroyed (const struct AddressDestroyedMessage *m)
188 struct GNUNET_MQ_Envelope *env;
189 struct GNUNET_ATS_SessionReleaseMessage *srm;
191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
192 "Received `%s' message\n",
193 "ADDRESS_DESTROYED");
194 GNUNET_STATISTICS_update (GSA_stats,
195 "# addresses destroyed",
198 GAS_addresses_destroy (&m->peer,
199 ntohl (m->session_id));
200 env = GNUNET_MQ_msg (srm,
201 GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE);
202 srm->session_id = m->session_id;
204 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (my_client),
209 /* end of gnunet-service-ats_scheduling.c */