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/>.
20 * @file ats/gnunet-service-ats_scheduling.c
21 * @brief ats service, interaction with 'scheduling' API
22 * @author Matthias Wachs
23 * @author Christian Grothoff
26 #include "gnunet-service-ats_addresses.h"
27 #include "gnunet-service-ats_scheduling.h"
31 * Actual handle to the client.
33 static struct GNUNET_SERVICE_Client *my_client;
37 * Register a new scheduling client.
39 * @param client handle of the new client
40 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
43 GAS_scheduling_add_client (struct GNUNET_SERVICE_Client *client)
45 if (NULL != my_client)
47 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
48 "This ATS already has a scheduling client, refusing new scheduling client for now.\n");
57 * Unregister a client (which may have been a scheduling client,
58 * but this is not assured).
60 * @param client handle of the (now dead) client
63 GAS_scheduling_remove_client (struct GNUNET_SERVICE_Client *client)
65 if (my_client != client)
67 GAS_addresses_destroy_all ();
73 * Transmit the given address suggestion and bandwidth update to all scheduling
76 * @param peer peer for which this is an address suggestion
77 * @param session_id session ID to use for the given client
78 * @param bandwidth_out assigned outbound bandwidth
79 * @param bandwidth_in assigned inbound bandwidth
82 GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *peer,
84 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
85 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
87 struct GNUNET_MQ_Envelope *env;
88 struct AddressSuggestionMessage *msg;
90 if (NULL == my_client)
92 GNUNET_STATISTICS_update (GSA_stats,
93 "# address suggestions made",
96 env = GNUNET_MQ_msg (msg,
97 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION);
99 msg->session_id = htonl (session_id);
100 msg->bandwidth_out = bandwidth_out;
101 msg->bandwidth_in = bandwidth_in;
102 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
103 "ATS sends quota for peer `%s': (in/out) %u/%u\n",
105 (unsigned int) ntohl (bandwidth_in.value__),
106 (unsigned int) ntohl (bandwidth_out.value__));
107 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (my_client),
113 * Handle 'address add' messages from clients.
115 * @param m the request message
118 GAS_handle_address_add (const struct AddressAddMessage *m)
121 const char *plugin_name;
122 uint16_t address_length;
123 uint16_t plugin_name_length;
124 struct GNUNET_ATS_Properties prop;
126 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
127 "Received `%s' message\n",
129 address_length = ntohs (m->address_length);
130 plugin_name_length = ntohs (m->plugin_name_length);
131 address = (const char *) &m[1];
132 if (plugin_name_length != 0)
133 plugin_name = &address[address_length];
136 GNUNET_STATISTICS_update (GSA_stats,
137 "# addresses created",
140 GNUNET_ATS_properties_ntoh (&prop,
142 GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop.scope);
143 GAS_addresses_add (&m->peer,
147 ntohl (m->address_local_info),
148 ntohl (m->session_id),
154 * Handle 'address update' messages from clients.
156 * @param m the request message
159 GAS_handle_address_update (const struct AddressUpdateMessage *m)
161 struct GNUNET_ATS_Properties prop;
163 GNUNET_STATISTICS_update (GSA_stats,
164 "# address updates received",
167 GNUNET_ATS_properties_ntoh (&prop,
169 GAS_addresses_update (&m->peer,
170 ntohl (m->session_id),
176 * Handle 'address destroyed' messages from clients.
178 * @param m the request message
181 GAS_handle_address_destroyed (const struct AddressDestroyedMessage *m)
183 struct GNUNET_MQ_Envelope *env;
184 struct GNUNET_ATS_SessionReleaseMessage *srm;
186 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
187 "Received `%s' message\n",
188 "ADDRESS_DESTROYED");
189 GNUNET_STATISTICS_update (GSA_stats,
190 "# addresses destroyed",
193 GAS_addresses_destroy (&m->peer,
194 ntohl (m->session_id));
195 env = GNUNET_MQ_msg (srm,
196 GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE);
197 srm->session_id = m->session_id;
199 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (my_client),
204 /* end of gnunet-service-ats_scheduling.c */