aboutsummaryrefslogtreecommitdiff
path: root/src/ats/gnunet-service-ats_scheduling.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-06-16 08:38:55 +0000
committerChristian Grothoff <christian@grothoff.org>2014-06-16 08:38:55 +0000
commitc345e101fd271feb03c311d0ec1837fc6cf179f3 (patch)
treee02cb4ca82dd9809caba2644c4ceb512329587fb /src/ats/gnunet-service-ats_scheduling.c
parentacac80b2c2b5cf432e903350a0dc6bbaa5ee877c (diff)
downloadgnunet-c345e101fd271feb03c311d0ec1837fc6cf179f3.tar.gz
gnunet-c345e101fd271feb03c311d0ec1837fc6cf179f3.zip
-doxygen, indentation, nicer stats
Diffstat (limited to 'src/ats/gnunet-service-ats_scheduling.c')
-rw-r--r--src/ats/gnunet-service-ats_scheduling.c104
1 files changed, 65 insertions, 39 deletions
diff --git a/src/ats/gnunet-service-ats_scheduling.c b/src/ats/gnunet-service-ats_scheduling.c
index 4c0b6423f..85ca6c461 100644
--- a/src/ats/gnunet-service-ats_scheduling.c
+++ b/src/ats/gnunet-service-ats_scheduling.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors) 3 (C) 2011-2014 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 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 6 it under the terms of the GNU General Public License as published
@@ -41,17 +41,17 @@ static struct GNUNET_SERVER_NotificationContext *nc;
41 */ 41 */
42static struct GNUNET_SERVER_Client *my_client; 42static struct GNUNET_SERVER_Client *my_client;
43 43
44
45/** 44/**
46 * Handle to address subsystem 45 * Handle to address subsystem
47 */ 46 */
48static struct GAS_Addresses_Handle *address_handle; 47static struct GAS_Addresses_Handle *address_handle;
49 48
49
50/** 50/**
51 * Register a new scheduling client. 51 * Register a new scheduling client.
52 * 52 *
53 * @param client handle of the new client 53 * @param client handle of the new client
54 * @return GNUNET_OK on success, GNUNET_SYSERR on error 54 * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
55 */ 55 */
56int 56int
57GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client) 57GAS_scheduling_add_client (struct GNUNET_SERVER_Client *client)
@@ -91,26 +91,25 @@ GAS_scheduling_remove_client (struct GNUNET_SERVER_Client *client)
91 * @param peer peer for which this is an address suggestion 91 * @param peer peer for which this is an address suggestion
92 * @param plugin_name 0-termintated string specifying the transport plugin 92 * @param plugin_name 0-termintated string specifying the transport plugin
93 * @param plugin_addr binary address for the plugin to use 93 * @param plugin_addr binary address for the plugin to use
94 * @param plugin_addr_len number of bytes in plugin_addr 94 * @param plugin_addr_len number of bytes in @a plugin_addr
95 * @param local_address_info the local address for the address 95 * @param local_address_info the local address for the address
96 * @param session_id session ID to use for the given client (other clients will see 0) 96 * @param session_id session ID to use for the given client (other clients will see 0)
97 * @param atsi performance data for the address 97 * @param atsi performance data for the address
98 * @param atsi_count number of performance records in 'ats' 98 * @param atsi_count number of performance records in @a atsi
99 * @param bandwidth_out assigned outbound bandwidth 99 * @param bandwidth_out assigned outbound bandwidth
100 * @param bandwidth_in assigned inbound bandwidth 100 * @param bandwidth_in assigned inbound bandwidth
101 */ 101 */
102void 102void
103GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity 103GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity *peer,
104 *peer, 104 const char *plugin_name,
105 const char *plugin_name, 105 const void *plugin_addr,
106 const void *plugin_addr, 106 size_t plugin_addr_len,
107 size_t plugin_addr_len, 107 uint32_t local_address_info,
108 uint32_t local_address_info, 108 uint32_t session_id,
109 uint32_t session_id, 109 const struct GNUNET_ATS_Information *atsi,
110 const struct GNUNET_ATS_Information *atsi, 110 uint32_t atsi_count,
111 uint32_t atsi_count, 111 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
112 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 112 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
113 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
114{ 113{
115 struct AddressSuggestionMessage *msg; 114 struct AddressSuggestionMessage *msg;
116 size_t plugin_name_length = strlen (plugin_name) + 1; 115 size_t plugin_name_length = strlen (plugin_name) + 1;
@@ -166,7 +165,8 @@ GAS_scheduling_transmit_address_suggestion (const struct GNUNET_PeerIdentity
166 * @param message the request message 165 * @param message the request message
167 */ 166 */
168void 167void
169GAS_handle_request_address (void *cls, struct GNUNET_SERVER_Client *client, 168GAS_handle_request_address (void *cls,
169 struct GNUNET_SERVER_Client *client,
170 const struct GNUNET_MessageHeader *message) 170 const struct GNUNET_MessageHeader *message)
171{ 171{
172 const struct RequestAddressMessage *msg = 172 const struct RequestAddressMessage *msg =
@@ -204,6 +204,7 @@ GAS_handle_request_address_cancel (void *cls,
204 GNUNET_SERVER_receive_done (client, GNUNET_OK); 204 GNUNET_SERVER_receive_done (client, GNUNET_OK);
205} 205}
206 206
207
207/** 208/**
208 * Handle 'reset backoff' messages from clients. 209 * Handle 'reset backoff' messages from clients.
209 * 210 *
@@ -219,13 +220,15 @@ GAS_handle_reset_backoff (void *cls,
219 const struct ResetBackoffMessage *msg = 220 const struct ResetBackoffMessage *msg =
220 (const struct ResetBackoffMessage *) message; 221 (const struct ResetBackoffMessage *) message;
221 222
222 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", 223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
224 "Received `%s' message\n",
223 "RESET_BACKOFF"); 225 "RESET_BACKOFF");
224 GNUNET_break (0 == ntohl (msg->reserved)); 226 GNUNET_break (0 == ntohl (msg->reserved));
225 GAS_addresses_handle_backoff_reset (address_handle, &msg->peer); 227 GAS_addresses_handle_backoff_reset (address_handle, &msg->peer);
226 GNUNET_SERVER_receive_done (client, GNUNET_OK); 228 GNUNET_SERVER_receive_done (client, GNUNET_OK);
227} 229}
228 230
231
229/** 232/**
230 * Handle 'address add' messages from clients. 233 * Handle 'address add' messages from clients.
231 * 234 *
@@ -234,7 +237,8 @@ GAS_handle_reset_backoff (void *cls,
234 * @param message the request message 237 * @param message the request message
235 */ 238 */
236void 239void
237GAS_handle_address_add (void *cls, struct GNUNET_SERVER_Client *client, 240GAS_handle_address_add (void *cls,
241 struct GNUNET_SERVER_Client *client,
238 const struct GNUNET_MessageHeader *message) 242 const struct GNUNET_MessageHeader *message)
239{ 243{
240 const struct AddressUpdateMessage *m; 244 const struct AddressUpdateMessage *m;
@@ -246,7 +250,8 @@ GAS_handle_address_add (void *cls, struct GNUNET_SERVER_Client *client,
246 uint32_t ats_count; 250 uint32_t ats_count;
247 uint16_t size; 251 uint16_t size;
248 252
249 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", 253 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
254 "Received `%s' message\n",
250 "ADDRESS_ADD"); 255 "ADDRESS_ADD");
251 size = ntohs (message->size); 256 size = ntohs (message->size);
252 if (size < sizeof (struct AddressUpdateMessage)) 257 if (size < sizeof (struct AddressUpdateMessage))
@@ -277,10 +282,17 @@ GAS_handle_address_add (void *cls, struct GNUNET_SERVER_Client *client,
277 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 282 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
278 return; 283 return;
279 } 284 }
280 GNUNET_STATISTICS_update (GSA_stats, "# address updates received", 1, 285 GNUNET_STATISTICS_update (GSA_stats,
286 "# addresses created", 1,
281 GNUNET_NO); 287 GNUNET_NO);
282 GAS_addresses_add (address_handle, &m->peer, plugin_name, address, address_length, 288 GAS_addresses_add (address_handle,
283 ntohl(m->address_local_info), ntohl (m->session_id), atsi, ats_count); 289 &m->peer,
290 plugin_name,
291 address,
292 address_length,
293 ntohl(m->address_local_info),
294 ntohl (m->session_id),
295 atsi, ats_count);
284 GNUNET_SERVER_receive_done (client, GNUNET_OK); 296 GNUNET_SERVER_receive_done (client, GNUNET_OK);
285} 297}
286 298
@@ -293,7 +305,8 @@ GAS_handle_address_add (void *cls, struct GNUNET_SERVER_Client *client,
293 * @param message the request message 305 * @param message the request message
294 */ 306 */
295void 307void
296GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client, 308GAS_handle_address_update (void *cls,
309 struct GNUNET_SERVER_Client *client,
297 const struct GNUNET_MessageHeader *message) 310 const struct GNUNET_MessageHeader *message)
298{ 311{
299 const struct AddressUpdateMessage *m; 312 const struct AddressUpdateMessage *m;
@@ -305,7 +318,8 @@ GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client,
305 uint32_t ats_count; 318 uint32_t ats_count;
306 uint16_t size; 319 uint16_t size;
307 320
308 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n", 321 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
322 "Received `%s' message\n",
309 "ADDRESS_UPDATE"); 323 "ADDRESS_UPDATE");
310 size = ntohs (message->size); 324 size = ntohs (message->size);
311 if (size < sizeof (struct AddressUpdateMessage)) 325 if (size < sizeof (struct AddressUpdateMessage))
@@ -336,9 +350,15 @@ GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client,
336 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 350 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
337 return; 351 return;
338 } 352 }
339 GNUNET_STATISTICS_update (GSA_stats, "# address updates received", 1, 353 GNUNET_STATISTICS_update (GSA_stats,
354 "# address updates received",
355 1,
340 GNUNET_NO); 356 GNUNET_NO);
341 GAS_addresses_update (address_handle, &m->peer, plugin_name, address, address_length, 357 GAS_addresses_update (address_handle,
358 &m->peer,
359 plugin_name,
360 address,
361 address_length,
342 ntohl (m->address_local_info), 362 ntohl (m->address_local_info),
343 ntohl (m->session_id), atsi, ats_count); 363 ntohl (m->session_id), atsi, ats_count);
344 GNUNET_SERVER_receive_done (client, GNUNET_OK); 364 GNUNET_SERVER_receive_done (client, GNUNET_OK);
@@ -353,7 +373,8 @@ GAS_handle_address_update (void *cls, struct GNUNET_SERVER_Client *client,
353 * @param message the request message 373 * @param message the request message
354 */ 374 */
355void 375void
356GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client, 376GAS_handle_address_in_use (void *cls,
377 struct GNUNET_SERVER_Client *client,
357 const struct GNUNET_MessageHeader *message) 378 const struct GNUNET_MessageHeader *message)
358{ 379{
359 const struct AddressUseMessage *m; 380 const struct AddressUseMessage *m;
@@ -362,7 +383,6 @@ GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client,
362 int res; 383 int res;
363 uint16_t address_length; 384 uint16_t address_length;
364 uint16_t plugin_name_length; 385 uint16_t plugin_name_length;
365
366 uint16_t size; 386 uint16_t size;
367 uint16_t in_use; 387 uint16_t in_use;
368 388
@@ -404,16 +424,16 @@ GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client,
404 ntohl (m->session_id), 424 ntohl (m->session_id),
405 in_use); 425 in_use);
406 426
407 if (res == GNUNET_OK) 427 if (GNUNET_OK != res)
408 GNUNET_SERVER_receive_done (client, GNUNET_OK);
409 else
410 { 428 {
411 GNUNET_break (0); 429 GNUNET_break (0);
412 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 430 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
431 return;
413 } 432 }
414 433 GNUNET_SERVER_receive_done (client, GNUNET_OK);
415} 434}
416 435
436
417/** 437/**
418 * Handle 'address destroyed' messages from clients. 438 * Handle 'address destroyed' messages from clients.
419 * 439 *
@@ -422,7 +442,8 @@ GAS_handle_address_in_use (void *cls, struct GNUNET_SERVER_Client *client,
422 * @param message the request message 442 * @param message the request message
423 */ 443 */
424void 444void
425GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client, 445GAS_handle_address_destroyed (void *cls,
446 struct GNUNET_SERVER_Client *client,
426 const struct GNUNET_MessageHeader *message) 447 const struct GNUNET_MessageHeader *message)
427{ 448{
428 const struct AddressDestroyedMessage *m; 449 const struct AddressDestroyedMessage *m;
@@ -433,8 +454,10 @@ GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client,
433 uint16_t plugin_name_length; 454 uint16_t plugin_name_length;
434 uint16_t size; 455 uint16_t size;
435 456
436 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message of size %u %u\n", 457 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
437 "ADDRESS_DESTROYED", ntohs (message->size), 458 "Received `%s' message of size %u %u\n",
459 "ADDRESS_DESTROYED",
460 ntohs (message->size),
438 sizeof (struct AddressDestroyedMessage)); 461 sizeof (struct AddressDestroyedMessage));
439 size = ntohs (message->size); 462 size = ntohs (message->size);
440 if ((size < sizeof (struct AddressDestroyedMessage)) || (client != my_client)) 463 if ((size < sizeof (struct AddressDestroyedMessage)) || (client != my_client))
@@ -466,7 +489,10 @@ GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client,
466 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); 489 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
467 return; 490 return;
468 } 491 }
469 GNUNET_STATISTICS_update (GSA_stats, "# addresses destroyed", 1, GNUNET_NO); 492 GNUNET_STATISTICS_update (GSA_stats,
493 "# addresses destroyed",
494 1,
495 GNUNET_NO);
470 GAS_addresses_destroy (address_handle, &m->peer, plugin_name, 496 GAS_addresses_destroy (address_handle, &m->peer, plugin_name,
471 address, address_length, 497 address, address_length,
472 ntohl (m->address_local_info), 498 ntohl (m->address_local_info),
@@ -491,7 +517,8 @@ GAS_handle_address_destroyed (void *cls, struct GNUNET_SERVER_Client *client,
491 * @param ah the address handle to use 517 * @param ah the address handle to use
492 */ 518 */
493void 519void
494GAS_scheduling_init (struct GNUNET_SERVER_Handle *server, struct GAS_Addresses_Handle *ah) 520GAS_scheduling_init (struct GNUNET_SERVER_Handle *server,
521 struct GAS_Addresses_Handle *ah)
495{ 522{
496 GNUNET_assert (NULL != ah); 523 GNUNET_assert (NULL != ah);
497 address_handle = ah; 524 address_handle = ah;
@@ -511,7 +538,6 @@ GAS_scheduling_done ()
511 } 538 }
512 GNUNET_SERVER_notification_context_destroy (nc); 539 GNUNET_SERVER_notification_context_destroy (nc);
513 nc = NULL; 540 nc = NULL;
514
515} 541}
516 542
517 543