aboutsummaryrefslogtreecommitdiff
path: root/src/ats/gnunet-service-ats_scheduling.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats/gnunet-service-ats_scheduling.c')
-rw-r--r--src/ats/gnunet-service-ats_scheduling.c177
1 files changed, 79 insertions, 98 deletions
diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c
index bb95182c8..4af44e29b 100644
--- a/src/ats/gnunet-service-ats_scheduling.c
+++ b/src/ats/gnunet-service-ats_scheduling.c
@@ -46,7 +46,7 @@ static struct GNUNET_SERVER_Client *my_client;
46 * Register a new scheduling client. 46 * Register a new scheduling client.
47 * 47 *
48 * @param client handle of the new client 48 * @param client handle of the new client
49 * @return GNUNET_OK on success, GNUNET_SYSERR on error 49 * @return GNUNET_OK on success, GNUNET_SYSERR on error
50 */ 50 */
51int 51int
52GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client) 52GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client)
@@ -54,7 +54,7 @@ GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client)
54 if (my_client != NULL) 54 if (my_client != NULL)
55 { 55 {
56 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 56 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
57 "This ATS already has a scheduling client, refusing new scheduling client for now.\n"); 57 "This ATS already has a scheduling client, refusing new scheduling client for now.\n");
58 return GNUNET_SYSERR; 58 return GNUNET_SYSERR;
59 } 59 }
60 my_client = client; 60 my_client = client;
@@ -96,32 +96,37 @@ GAS_scheduling_remove_client (struct GNUNET_SERVER_Client *client)
96 * @param bandwidth_in assigned inbound bandwidth 96 * @param bandwidth_in assigned inbound bandwidth
97 */ 97 */
98void 98void
99GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *peer, 99GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity
100 const char *plugin_name, 100 *peer, const char *plugin_name,
101 const void *plugin_addr, size_t plugin_addr_len, 101 const void *plugin_addr,
102 uint32_t session_id, 102 size_t plugin_addr_len,
103 const struct GNUNET_ATS_Information *atsi, 103 uint32_t session_id,
104 uint32_t atsi_count, 104 const struct GNUNET_ATS_Information
105 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 105 *atsi, uint32_t atsi_count,
106 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 106 struct GNUNET_BANDWIDTH_Value32NBO
107 bandwidth_out,
108 struct GNUNET_BANDWIDTH_Value32NBO
109 bandwidth_in)
107{ 110{
108 struct AddressSuggestionMessage *msg; 111 struct AddressSuggestionMessage *msg;
109 size_t plugin_name_length = strlen (plugin_name) + 1; 112 size_t plugin_name_length = strlen (plugin_name) + 1;
110 size_t msize = sizeof (struct AddressSuggestionMessage) + atsi_count * sizeof (struct GNUNET_ATS_Information) 113 size_t msize =
111 + plugin_addr_len + plugin_name_length; 114 sizeof (struct AddressSuggestionMessage) +
115 atsi_count * sizeof (struct GNUNET_ATS_Information) + plugin_addr_len +
116 plugin_name_length;
112 char buf[msize]; 117 char buf[msize];
113 struct GNUNET_ATS_Information *atsp; 118 struct GNUNET_ATS_Information *atsp;
114 char *addrp; 119 char *addrp;
115 120
116 if (my_client == NULL) 121 if (my_client == NULL)
117 return; 122 return;
118 GNUNET_STATISTICS_update (GSA_stats, 123 GNUNET_STATISTICS_update (GSA_stats, "# address suggestions made", 1,
119 "# address suggestions made", 124 GNUNET_NO);
120 1,
121 GNUNET_NO);
122 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE); 125 GNUNET_assert (msize < GNUNET_SERVER_MAX_MESSAGE_SIZE);
123 GNUNET_assert (atsi_count < GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)); 126 GNUNET_assert (atsi_count <
124 msg = (struct AddressSuggestionMessage*) buf; 127 GNUNET_SERVER_MAX_MESSAGE_SIZE /
128 sizeof (struct GNUNET_ATS_Information));
129 msg = (struct AddressSuggestionMessage *) buf;
125 msg->header.size = htons (msize); 130 msg->header.size = htons (msize);
126 msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION); 131 msg->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION);
127 msg->ats_count = htonl (atsi_count); 132 msg->ats_count = htonl (atsi_count);
@@ -131,15 +136,13 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *pe
131 msg->session_id = htonl (session_id); 136 msg->session_id = htonl (session_id);
132 msg->bandwidth_out = bandwidth_out; 137 msg->bandwidth_out = bandwidth_out;
133 msg->bandwidth_in = bandwidth_in; 138 msg->bandwidth_in = bandwidth_in;
134 atsp = (struct GNUNET_ATS_Information* ) &msg[1]; 139 atsp = (struct GNUNET_ATS_Information *) &msg[1];
135 memcpy (atsp, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count); 140 memcpy (atsp, atsi, sizeof (struct GNUNET_ATS_Information) * atsi_count);
136 addrp = (char*) &atsp[atsi_count]; 141 addrp = (char *) &atsp[atsi_count];
137 memcpy (addrp, plugin_addr, plugin_addr_len); 142 memcpy (addrp, plugin_addr, plugin_addr_len);
138 strcpy (&addrp[plugin_addr_len], plugin_name); 143 strcpy (&addrp[plugin_addr_len], plugin_name);
139 GNUNET_SERVER_notification_context_unicast (nc, 144 GNUNET_SERVER_notification_context_unicast (nc, my_client, &msg->header,
140 my_client, 145 GNUNET_YES);
141 &msg->header,
142 GNUNET_YES);
143} 146}
144 147
145 148
@@ -152,16 +155,15 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *pe
152 */ 155 */
153void 156void
154GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client, 157GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client,
155 const struct GNUNET_MessageHeader *message) 158 const struct GNUNET_MessageHeader *message)
156
157{ 159{
158 const struct RequestAddressMessage * msg = (const struct RequestAddressMessage *) message; 160 const struct RequestAddressMessage *msg =
161 (const struct RequestAddressMessage *) message;
159 162
160 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", "REQUEST_ADDRESS"); 163 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
161 GNUNET_STATISTICS_update (GSA_stats, 164 "REQUEST_ADDRESS");
162 "# address requests received", 165 GNUNET_STATISTICS_update (GSA_stats, "# address requests received", 1,
163 1, 166 GNUNET_NO);
164 GNUNET_NO);
165 GNUNET_break (0 == ntohl (msg->reserved)); 167 GNUNET_break (0 == ntohl (msg->reserved));
166 GAS_addresses_request_address (&msg->peer); 168 GAS_addresses_request_address (&msg->peer);
167 GNUNET_SERVER_receive_done (client, GNUNET_OK); 169 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -177,9 +179,9 @@ GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client,
177 */ 179 */
178void 180void
179GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client, 181GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client,
180 const struct GNUNET_MessageHeader *message) 182 const struct GNUNET_MessageHeader *message)
181{ 183{
182 const struct AddressUpdateMessage * m; 184 const struct AddressUpdateMessage *m;
183 const struct GNUNET_ATS_Information *atsi; 185 const struct GNUNET_ATS_Information *atsi;
184 const char *address; 186 const char *address;
185 const char *plugin_name; 187 const char *plugin_name;
@@ -188,9 +190,8 @@ GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client,
188 uint32_t ats_count; 190 uint32_t ats_count;
189 uint16_t size; 191 uint16_t size;
190 192
191 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 193 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
192 "Received `%s' message\n", 194 "ADDRESS_UPDATE");
193 "ADDRESS_UPDATE");
194 size = ntohs (message->size); 195 size = ntohs (message->size);
195 if (size < sizeof (struct AddressUpdateMessage)) 196 if (size < sizeof (struct AddressUpdateMessage))
196 { 197 {
@@ -198,38 +199,31 @@ GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client,
198 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 199 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
199 return; 200 return;
200 } 201 }
201 m = (const struct AddressUpdateMessage*) message; 202 m = (const struct AddressUpdateMessage *) message;
202 ats_count = ntohl (m->ats_count); 203 ats_count = ntohl (m->ats_count);
203 address_length = ntohs (m->address_length); 204 address_length = ntohs (m->address_length);
204 plugin_name_length = ntohs (m->plugin_name_length); 205 plugin_name_length = ntohs (m->plugin_name_length);
205 atsi = (const struct GNUNET_ATS_Information*) &m[1]; 206 atsi = (const struct GNUNET_ATS_Information *) &m[1];
206 address = (const char*) &atsi[ats_count]; 207 address = (const char *) &atsi[ats_count];
207 if (plugin_name_length != 0) 208 if (plugin_name_length != 0)
208 plugin_name = &address[address_length]; 209 plugin_name = &address[address_length];
209 else 210 else
210 plugin_name = ""; 211 plugin_name = "";
211 if ( (address_length + 212 if ((address_length + plugin_name_length +
212 plugin_name_length + 213 ats_count * sizeof (struct GNUNET_ATS_Information) +
213 ats_count * sizeof (struct GNUNET_ATS_Information) + 214 sizeof (struct AddressUpdateMessage) != ntohs (message->size)) ||
214 sizeof (struct AddressUpdateMessage) != ntohs (message->size)) || 215 (ats_count >
215 (ats_count > GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information)) || 216 GNUNET_SERVER_MAX_MESSAGE_SIZE / sizeof (struct GNUNET_ATS_Information))
216 (plugin_name[plugin_name_length - 1] != '\0') ) 217 || (plugin_name[plugin_name_length - 1] != '\0'))
217 { 218 {
218 GNUNET_break (0); 219 GNUNET_break (0);
219 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 220 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
220 return; 221 return;
221 } 222 }
222 GNUNET_STATISTICS_update (GSA_stats, 223 GNUNET_STATISTICS_update (GSA_stats, "# address updates received", 1,
223 "# address updates received", 224 GNUNET_NO);
224 1, 225 GAS_addresses_update (&m->peer, plugin_name, address, address_length,
225 GNUNET_NO); 226 ntohl (m->session_id), atsi, ats_count);
226 GAS_addresses_update (&m->peer,
227 plugin_name,
228 address,
229 address_length,
230 ntohl (m->session_id),
231 atsi,
232 ats_count);
233 GNUNET_SERVER_receive_done (client, GNUNET_OK); 227 GNUNET_SERVER_receive_done (client, GNUNET_OK);
234} 228}
235 229
@@ -245,7 +239,7 @@ void
245GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client, 239GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client,
246 const struct GNUNET_MessageHeader *message) 240 const struct GNUNET_MessageHeader *message)
247{ 241{
248 const struct AddressUseMessage * m; 242 const struct AddressUseMessage *m;
249 const char *address; 243 const char *address;
250 const char *plugin_name; 244 const char *plugin_name;
251 uint16_t address_length; 245 uint16_t address_length;
@@ -253,8 +247,7 @@ GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client,
253 247
254 uint16_t size; 248 uint16_t size;
255 249
256 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 250 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
257 "Received `%s' message\n",
258 "ADDRESS_IN_USE"); 251 "ADDRESS_IN_USE");
259 size = ntohs (message->size); 252 size = ntohs (message->size);
260 if (size < sizeof (struct AddressUseMessage)) 253 if (size < sizeof (struct AddressUseMessage))
@@ -263,21 +256,20 @@ GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client,
263 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 256 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
264 return; 257 return;
265 } 258 }
266 m = (const struct AddressUseMessage*) message; 259 m = (const struct AddressUseMessage *) message;
267 260
268 address_length = ntohs (m->address_length); 261 address_length = ntohs (m->address_length);
269 plugin_name_length = ntohs (m->plugin_name_length); 262 plugin_name_length = ntohs (m->plugin_name_length);
270 263
271 address = (const char*) &m[1]; 264 address = (const char *) &m[1];
272 if (plugin_name_length != 0) 265 if (plugin_name_length != 0)
273 plugin_name = &address[address_length]; 266 plugin_name = &address[address_length];
274 else 267 else
275 plugin_name = ""; 268 plugin_name = "";
276 269
277 if ( (address_length + 270 if ((address_length + plugin_name_length +
278 plugin_name_length + 271 sizeof (struct AddressUseMessage) != ntohs (message->size)) ||
279 sizeof (struct AddressUseMessage) != ntohs (message->size)) || 272 (plugin_name[plugin_name_length - 1] != '\0'))
280 (plugin_name[plugin_name_length - 1] != '\0') )
281 { 273 {
282 GNUNET_break (0); 274 GNUNET_break (0);
283 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 275 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
@@ -306,10 +298,9 @@ GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client,
306 */ 298 */
307void 299void
308GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client, 300GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client,
309 const struct GNUNET_MessageHeader *message) 301 const struct GNUNET_MessageHeader *message)
310
311{ 302{
312 const struct AddressDestroyedMessage * m; 303 const struct AddressDestroyedMessage *m;
313 struct SessionReleaseMessage srm; 304 struct SessionReleaseMessage srm;
314 const char *address; 305 const char *address;
315 const char *plugin_name; 306 const char *plugin_name;
@@ -317,60 +308,50 @@ GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client,
317 uint16_t plugin_name_length; 308 uint16_t plugin_name_length;
318 uint16_t size; 309 uint16_t size;
319 310
320 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 311 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message of size %u %u\n",
321 "Received `%s' message of size %u %u\n", 312 "ADDRESS_DESTROYED", ntohs (message->size),
322 "ADDRESS_DESTROYED", ntohs (message->size), sizeof (struct AddressDestroyedMessage)); 313 sizeof (struct AddressDestroyedMessage));
323 size = ntohs (message->size); 314 size = ntohs (message->size);
324 if ( (size < sizeof (struct AddressDestroyedMessage)) || 315 if ((size < sizeof (struct AddressDestroyedMessage)) || (client != my_client))
325 (client != my_client) )
326 { 316 {
327 GNUNET_break (0); 317 GNUNET_break (0);
328 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 318 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
329 return; 319 return;
330 } 320 }
331 m = (const struct AddressDestroyedMessage*) message; 321 m = (const struct AddressDestroyedMessage *) message;
332 GNUNET_break (0 == ntohl (m->reserved)); 322 GNUNET_break (0 == ntohl (m->reserved));
333 address_length = ntohs (m->address_length); 323 address_length = ntohs (m->address_length);
334 plugin_name_length = ntohs (m->plugin_name_length); 324 plugin_name_length = ntohs (m->plugin_name_length);
335 address = (const char*) &m[1]; 325 address = (const char *) &m[1];
336 if (plugin_name_length != 0) 326 if (plugin_name_length != 0)
337 plugin_name = &address[address_length]; 327 plugin_name = &address[address_length];
338 else 328 else
339 plugin_name = ""; 329 plugin_name = "";
340 if ( (address_length + 330 if ((address_length + plugin_name_length +
341 plugin_name_length + 331 sizeof (struct AddressDestroyedMessage) != ntohs (message->size)))
342 sizeof (struct AddressDestroyedMessage) != ntohs (message->size)))
343 { 332 {
344 GNUNET_break (0); 333 GNUNET_break (0);
345 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 334 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
346 return; 335 return;
347 } 336 }
348 if ( (plugin_name_length != 0) && 337 if ((plugin_name_length != 0) &&
349 (plugin_name[plugin_name_length - 1] != '\0') ) 338 (plugin_name[plugin_name_length - 1] != '\0'))
350 { 339 {
351 GNUNET_break (0); 340 GNUNET_break (0);
352 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 341 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
353 return; 342 return;
354 } 343 }
355 GNUNET_STATISTICS_update (GSA_stats, 344 GNUNET_STATISTICS_update (GSA_stats, "# addresses destroyed", 1, GNUNET_NO);
356 "# addresses destroyed", 345 GAS_addresses_destroy (&m->peer, plugin_name, address, address_length,
357 1, 346 ntohl (m->session_id));
358 GNUNET_NO);
359 GAS_addresses_destroy (&m->peer,
360 plugin_name,
361 address,
362 address_length,
363 ntohl (m->session_id));
364 if (0 != ntohl (m->session_id)) 347 if (0 != ntohl (m->session_id))
365 { 348 {
366 srm.header.type = ntohs (GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE); 349 srm.header.type = ntohs (GNUNET_MESSAGE_TYPE_ATS_SESSION_RELEASE);
367 srm.header.size = ntohs (sizeof (struct SessionReleaseMessage)); 350 srm.header.size = ntohs (sizeof (struct SessionReleaseMessage));
368 srm.session_id = m->session_id; 351 srm.session_id = m->session_id;
369 srm.peer = m->peer; 352 srm.peer = m->peer;
370 GNUNET_SERVER_notification_context_unicast (nc, 353 GNUNET_SERVER_notification_context_unicast (nc, client, &srm.header,
371 client, 354 GNUNET_NO);
372 &srm.header,
373 GNUNET_NO);
374 } 355 }
375 GNUNET_SERVER_receive_done (client, GNUNET_OK); 356 GNUNET_SERVER_receive_done (client, GNUNET_OK);
376} 357}
@@ -382,7 +363,7 @@ GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client,
382 * @param server handle to our server 363 * @param server handle to our server
383 */ 364 */
384void 365void
385GAS_scheduling_init (struct GNUNET_SERVER_Handle *server) 366GAS_scheduling_init (struct GNUNET_SERVER_Handle *server)
386{ 367{
387 nc = GNUNET_SERVER_notification_context_create (server, 128); 368 nc = GNUNET_SERVER_notification_context_create (server, 128);
388} 369}