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
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 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 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
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 GNUNET_PeerIdentity *peer,
86 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
87 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
89 struct GNUNET_MQ_Envelope *env;
90 struct AddressSuggestionMessage *msg;
92 if (NULL == my_client)
94 GNUNET_STATISTICS_update (GSA_stats,
95 "# address suggestions made",
98 env = GNUNET_MQ_msg (msg,
99 GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION);
101 msg->session_id = htonl (session_id);
102 msg->bandwidth_out = bandwidth_out;
103 msg->bandwidth_in = bandwidth_in;
104 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
105 "ATS sends quota for peer `%s': (in/out) %u/%u\n",
107 (unsigned int) ntohl (bandwidth_in.value__),
108 (unsigned int) ntohl (bandwidth_out.value__));
109 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (my_client),
115 * Handle 'address add' messages from clients.
117 * @param m the request message
120 GAS_handle_address_add (const struct AddressAddMessage *m)
123 const char *plugin_name;
124 uint16_t address_length;
125 uint16_t plugin_name_length;
126 struct GNUNET_ATS_Properties prop;
128 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
129 "Received `%s' message\n",
131 address_length = ntohs (m->address_length);
132 plugin_name_length = ntohs (m->plugin_name_length);
133 address = (const char *) &m[1];
134 if (plugin_name_length != 0)
135 plugin_name = &address[address_length];
138 GNUNET_STATISTICS_update (GSA_stats,
139 "# addresses created",
142 GNUNET_ATS_properties_ntoh (&prop,
144 GNUNET_break (GNUNET_ATS_NET_UNSPECIFIED != prop.scope);
145 GAS_addresses_add (&m->peer,
149 ntohl (m->address_local_info),
150 ntohl (m->session_id),
156 * Handle 'address update' messages from clients.
158 * @param m the request message
161 GAS_handle_address_update (const struct AddressUpdateMessage *m)
163 struct GNUNET_ATS_Properties prop;
165 GNUNET_STATISTICS_update (GSA_stats,
166 "# address updates received",
169 GNUNET_ATS_properties_ntoh (&prop,
171 GAS_addresses_update (&m->peer,
172 ntohl (m->session_id),
178 * Handle 'address destroyed' messages from clients.
180 * @param m the request message
183 GAS_handle_address_destroyed (const struct AddressDestroyedMessage *m)
185 struct GNUNET_MQ_Envelope *env;
186 struct GNUNET_ATS_SessionReleaseMessage *srm;
188 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
189 "Received `%s' message\n",
190 "ADDRESS_DESTROYED");
191 GNUNET_STATISTICS_update (GSA_stats,
192 "# addresses destroyed",
195 GAS_addresses_destroy (&m->peer,
196 ntohl (m->session_id));
197 env = GNUNET_MQ_msg (srm,
198 GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE);
199 srm->session_id = m->session_id;
201 GNUNET_MQ_send (GNUNET_SERVICE_client_get_mq (my_client),
206 /* end of gnunet-service-ats_scheduling.c */